Python docutils.nodes.image() Examples
The following are 30
code examples of docutils.nodes.image().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: _html_base.py From aws-extender with MIT License | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #2
Source File: examples_and_gallery.py From plotnine with GNU General Public License v2.0 | 6 votes |
def make_thumbnail(self, imgfilename_inrst): """ Make thumbnail and return (html) path to image Parameters ---------- imgfilename_rst : rst Image filename (relative path), as it appears in the ReST file (coverted). """ builddir = self.env.app.outdir imgfilename_src = os.path.join(DOC_PATH, imgfilename_inrst) thumbfilename = self.thumbfilename(imgfilename_inrst) thumbfilename_inhtml = os.path.join('_images', thumbfilename) thumbfilename_dest = os.path.join(builddir, '_images', thumbfilename) im = Image.open(imgfilename_src) im.thumbnail(thumbnail_size) im.save(thumbfilename_dest) return thumbfilename_inhtml
Example #3
Source File: _html_base.py From deepWordBug with Apache License 2.0 | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #4
Source File: _html_base.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #5
Source File: _html_base.py From blackmamba with MIT License | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #6
Source File: custom_directives.py From pyimgui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_image_node(self, source): file_name = self.name_source_snippet(source) file_path = os.path.join(VISUAL_EXAMPLES_DIR, file_name) env = self.state.document.settings.env if all([ render_snippet, env.config['render_examples'], not os.environ.get('SPHINX_DISABLE_RENDER', False), ]): try: render_snippet( source, file_path, output_dir=SOURCE_DIR, **self.options ) except: print("problematic code:\n%s" % source) raise img = nodes.image() img['uri'] = "/" + file_path return img
Example #7
Source File: _html_base.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #8
Source File: layout.py From sphinxcontrib-needs with MIT License | 6 votes |
def link(self, url, text=None, image_url=None, image_height=None, image_width=None): """ Shows a link. Link can be a text, an image or both :param url: :param text: :param image_url: :param image_height: :param image_width: :return: """ if text is None: # May be needed if only image shall be shown text = '' link_node = nodes.reference(text, text, refuri=url) if image_url is not None: image_node = self.image(image_url, image_height, image_width) link_node.append(image_node) return link_node
Example #9
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
def test_caption_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :caption: hello world\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.figure, type(doctree[0])) self.assertEqual(2, len(doctree[0])) self.assertEqual(nodes.image, type(doctree[0][0])) self.assertEqual(nodes.caption, type(doctree[0][1])) self.assertEqual(1, len(doctree[0][1])) self.assertEqual(nodes.Text, type(doctree[0][1][0])) self.assertEqual('hello world', doctree[0][1][0])
Example #10
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 6 votes |
def test_caption_option_and_align_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :align: left\n" " :caption: hello world\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.figure, type(doctree[0])) self.assertEqual('left', doctree[0]['align']) self.assertEqual(2, len(doctree[0])) self.assertEqual(nodes.image, type(doctree[0][0])) self.assertNotIn('align', doctree[0][0]) self.assertEqual(nodes.caption, type(doctree[0][1])) self.assertEqual(1, len(doctree[0][1])) self.assertEqual(nodes.Text, type(doctree[0][1][0])) self.assertEqual('hello world', doctree[0][1][0])
Example #11
Source File: _html_base.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #12
Source File: _html_base.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #13
Source File: _html_base.py From bash-lambda-layer with MIT License | 6 votes |
def visit_reference(self, node): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] if ( self.settings.cloak_email_addresses and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' else: assert 'refid' in node, \ 'References must have "refuri" or "refid" attribute.' atts['href'] = '#' + node['refid'] atts['class'] += ' internal' if not isinstance(node.parent, nodes.TextElement): assert len(node) == 1 and isinstance(node[0], nodes.image) atts['class'] += ' image-reference' self.body.append(self.starttag(node, 'a', '', **atts))
Example #14
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_setup_nodoctype_is_true(self): directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=True) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[-1])) svg = open(doctree[0]['uri']).read() self.assertNotEqual("<?xml version='1.0' encoding='UTF-8'?>\n" "<!DOCTYPE ", svg[:49])
Example #15
Source File: ipython_directive.py From ImageFusion with MIT License | 5 votes |
def process_block(self, block): """ process block from the block_parser and return a list of processed lines """ ret = [] output = None input_lines = None lineno = self.IP.execution_count input_prompt = self.promptin%lineno output_prompt = self.promptout%lineno image_file = None image_directive = None for token, data in block: if token==COMMENT: out_data = self.process_comment(data) elif token==INPUT: (out_data, input_lines, output, is_doctest, image_file, image_directive) = \ self.process_input(data, input_prompt, lineno) elif token==OUTPUT: out_data = \ self.process_output(data, output_prompt, input_lines, output, is_doctest, image_file) if out_data: ret.extend(out_data) # save the image files if image_file is not None: self.save_image(image_file) return ret, image_directive
Example #16
Source File: ipython_directive.py From ImageFusion with MIT License | 5 votes |
def save_image(self, image_file): """ Saves the image file to disk. """ self.ensure_pyplot() command = 'plt.gcf().savefig("%s")'%image_file #print 'SAVEFIG', command # dbg self.process_input_line('bookmark ipy_thisdir', store_history=False) self.process_input_line('cd -b ipy_savedir', store_history=False) self.process_input_line(command, store_history=False) self.process_input_line('cd -b ipy_thisdir', store_history=False) self.process_input_line('bookmark -d ipy_thisdir', store_history=False) self.clear_cout()
Example #17
Source File: ipython_directive.py From ImageFusion with MIT License | 5 votes |
def process_image(self, decorator): """ # build out an image directive like # .. image:: somefile.png # :width 4in # # from an input like # savefig somefile.png width=4in """ savefig_dir = self.savefig_dir source_dir = self.source_dir saveargs = decorator.split(' ') filename = saveargs[1] # insert relative path to image file in source outfile = os.path.relpath(os.path.join(savefig_dir,filename), source_dir) imagerows = ['.. image:: %s'%outfile] for kwarg in saveargs[2:]: arg, val = kwarg.split('=') arg = arg.strip() val = val.strip() imagerows.append(' :%s: %s'%(arg, val)) image_file = os.path.basename(outfile) # only return file name image_directive = '\n'.join(imagerows) return image_file, image_directive # Callbacks for each type of token
Example #18
Source File: examples_and_gallery.py From plotnine with GNU General Public License v2.0 | 5 votes |
def notebook_to_rst(nbfilename): nbfilepath = os.path.join(EXPATH, nbfilename) rstfilename = get_rstfilename(nbfilename) output_files_dir = only_filename_no_ext(rstfilename) metadata_path = os.path.dirname(rstfilename) unique_key = nbfilename.rstrip('.ipynb') resources = { 'metadata': {'path': metadata_path}, 'output_files_dir': output_files_dir, # Prefix for the output image filenames 'unique_key': unique_key } # Read notebook with open(nbfilepath, 'r') as f: nb = nbformat.read(f, as_version=4) # Export exporter = nbsphinx.Exporter(execute='never', allow_errors=True) (body, resources) = exporter.from_notebook_node(nb, resources) # Correct path for the resources for filename in list(resources['outputs'].keys()): tmp = os.path.join(RST_PATH, filename) resources['outputs'][tmp] = resources['outputs'].pop(filename) fw = FilesWriter() fw.build_directory = RST_PATH # Prevent "not in doctree" complains resources['output_extension'] = '' body = 'Examples\n--------\n' + body fw.write(body, resources, notebook_name=rstfilename)
Example #19
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_height_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :height: 100\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual('100', doctree[0]['height']) self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Example #20
Source File: images.py From blackmamba with MIT License | 5 votes |
def figwidth_value(argument): if argument.lower() == 'image': return 'image' else: return directives.length_or_percentage_or_unitless(argument, 'px')
Example #21
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_call_without_braces(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Example #22
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_alt_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :alt: hello world\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual('hello world', doctree[0]['alt']) self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Example #23
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_setup_nodoctype_is_false(self): directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=False) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) svg = open(doctree[0]['uri']).read() self.assertEqual("<?xml version='1.0' encoding='UTF-8'?>\n" "<!DOCTYPE ", svg[:49])
Example #24
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_setup_noviewbox_is_true(self): directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=True) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) svg = open(doctree[0]['uri']).read() self.assertRegexpMatches(svg, r'<svg height="\d+" width="\d+" ')
Example #25
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_setup_noviewbox_is_false(self): directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) svg = open(doctree[0]['uri']).read() self.assertRegexpMatches(svg, r'<svg viewBox="0 0 \d+ \d+" ')
Example #26
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_setup_inline_svg_is_false(self): directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=False) text = (".. rackdiag::\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(1, len(os.listdir(self.tmpdir)))
Example #27
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_align_option2(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :align: center\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(1, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual('center', doctree[0]['align']) self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Example #28
Source File: universal.py From faces with GNU General Public License v2.0 | 5 votes |
def get_tokens(self, txtnodes): # A generator that yields ``(texttype, nodetext)`` tuples for a list # of "Text" nodes (interface to ``smartquotes.educate_tokens()``). texttype = {True: 'literal', # "literal" text is not changed: False: 'plain'} for txtnode in txtnodes: nodetype = texttype[isinstance(txtnode.parent, (nodes.literal, nodes.math, nodes.image, nodes.raw, nodes.problematic))] yield (nodetype, txtnode.astext())
Example #29
Source File: images.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def figwidth_value(argument): if argument.lower() == 'image': return 'image' else: return directives.length_or_percentage_or_unitless(argument, 'px')
Example #30
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_maxwidth_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. rackdiag::\n" " :maxwidth: 100\n" "\n" " 1: server\n" " 2: database\n") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir)) self.assertEqual('100', doctree[0]['width']) self.assertEqual(nodes.system_message, type(doctree[1]))