def run(self): if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value ' 'for the "align" option within a substitution ' 'definition. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_v_values))) elif self.options['align'] not in self.align_h_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_h_values))) messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null( self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] image_node = nodes.image(self.block_text, **self.options) if 'iconmargin' in self.options: image_node['classes'].append('iconmargin') set_classes(self.options) if 'iconmarginheight' in self.options: image_node['iconmarginheight'] = \ int(self.options['iconmarginheight']) if 'iconmarginraise' in self.options: image_node['iconmarginraise'] = True if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def run(self): if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value ' 'for the "align" option within a substitution ' 'definition. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join( self.align_v_values))) elif self.options['align'] not in self.align_h_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join( self.align_h_values))) messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null(self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] set_classes(self.options) # css3image: customise Class image_node = Css3Image(self.block_text, **self.options) self.add_name(image_node) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def run(self): messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null(self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] # Remove the classes from the image element, will be added either to it # or to the wrapping element later set_classes(self.options) classes = self.options.get('classes', []) if 'classes' in self.options: del self.options['classes'] image_node = nodes.image(self.block_text, **self.options) if not 'alt' in self.options and settings['M_IMAGES_REQUIRE_ALT_TEXT']: error = self.state_machine.reporter.error( 'Images and figures require the alt text. See the M_IMAGES_REQUIRE_ALT_TEXT option.', image_node, line=self.lineno) return [error] self.add_name(image_node) if reference_node: if self.image_class: container_node = nodes.container() container_node['classes'] += [self.image_class] + classes reference_node += image_node container_node += reference_node return messages + [container_node] else: reference_node += image_node return messages + [reference_node] else: if self.image_class: image_node['classes'] += [self.image_class] + classes return messages + [image_node]
def run(self) -> List[nodes.Node]: """ Process the content of the shield directive. """ if "class" in self.options: self.options["class"].append("sphinx_toolbox_shield") else: self.options["class"] = ["sphinx_toolbox_shield"] self.arguments = [str(x) for x in self.arguments] messages = [] reference = directives.uri(self.arguments[0]) self.options["uri"] = reference reference_node = None if "target" in self.options: block = states.escape2null( self.options["target"]).splitlines() # type: ignore block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) # type: ignore if target_type == "refuri": reference_node = nodes.reference(refuri=data) elif target_type == "refname": # pragma: no cover reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data), ) reference_node.indirect_reference_name = data # type: ignore self.state.document.note_refname(reference_node) else: # pragma: no cover # malformed target # data is a system message messages.append(data) del self.options["target"] set_classes(self.options) image_node = nodes.image(self.block_text, **self.options) self.add_name(image_node) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def image(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): if options.has_key('align'): # check for align_v values only if isinstance(state, states.SubstitutionDef): if options['align'] not in align_v_values: error = state_machine.reporter.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option within a substitution definition. ' 'Valid values for "align" are: "%s".' % (name, options['align'], '", "'.join(align_v_values)), nodes.literal_block(block_text, block_text), line=lineno) return [error] elif options['align'] not in align_h_values: error = state_machine.reporter.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (name, options['align'], '", "'.join(align_h_values)), nodes.literal_block(block_text, block_text), line=lineno) return [error] messages = [] reference = directives.uri(arguments[0]) options['uri'] = reference reference_node = None if options.has_key('target'): block = states.escape2null(options['target']).splitlines() block = [line for line in block] target_type, data = state.parse_target(block, block_text, lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del options['target'] set_classes(options) image_node = nodes.image(block_text, **options) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def generateReferenceNode(self): self.reference_node = None if 'target' in self.options: block = states.escape2null(self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': self.reference_node = nodes.reference(refuri=data) elif target_type == 'refname': self.reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) self.reference_node.indirect_reference_name = data self.state.document.note_refname(self.reference_node) else: # malformed target self.messages = data # data is a system message del self.options['target']
def run(self): if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value ' 'for the "align" option within a substitution ' 'definition. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_v_values))) elif self.options['align'] not in self.align_h_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_h_values))) messages = [] # previous code from Image.run() # -------------------------------------------------------------------- sumatra_options = build_options(self.state.document.settings, self.options) # determine which record store to use prj = determine_project(sumatra_options) record_store = determine_record_store(prj, sumatra_options, self.error) # determine the project (short) name project_name = determine_project_name(prj, sumatra_options, self.error) record_label, image_path = get_record_label_and_image_path(self.arguments[0]) record = record_store.get(project_name, record_label) image = get_image(record, image_path, self.options, self.error) # automatically checks digest if hasattr(image, "url"): reference = image.url else: if not os.path.exists(LOCAL_IMAGE_CACHE): os.makedirs(LOCAL_IMAGE_CACHE) reference = image.save_copy(LOCAL_IMAGE_CACHE) # set values for alt and target, if they have not been specified if not 'target' in self.options and hasattr(record_store, 'server_url'): self.options['target'] = record_link_url(record_store.server_url, project_name, record_label) if not 'alt' in self.options: self.options['alt'] = "Data file generated by computation %s" % record_label # -------------------------------------------------------------------- # following code from Image.run() self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null( self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] set_classes(self.options) image_node = nodes.image(self.block_text, **self.options) self.add_name(image_node) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def run(self): messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null(self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] width = None height = None # If scaling requested, open the files and calculate the scaled size # Support both {filename} (3.7.1) and {static} (3.8) placeholders. In # all cases use only width and not both so the max-width can correctly # scale the image down on smaller screen sizes. # TODO: implement ratio-preserving scaling to avoid jumps on load using # the margin-bottom hack if 'scale' in self.options: file = os.path.join(os.getcwd(), settings['PATH']) absuri = reference.format(filename=file, static=file) im = PIL.Image.open(absuri) width = "{}px".format(int(im.width * self.options['scale'] / 100.0)) elif 'width' in self.options: width = self.options['width'] elif 'height' in self.options: height = self.options['height'] # TODO: convert to width instead? # Remove the classes from the image element, will be added either to it # or to the wrapping element later set_classes(self.options) classes = self.options.get('classes', []) if 'classes' in self.options: del self.options['classes'] if 'width' in self.options: del self.options['width'] if 'height' in self.options: del self.options['height'] image_node = nodes.image(self.block_text, width=width, height=height, **self.options) if not 'alt' in self.options and settings['M_IMAGES_REQUIRE_ALT_TEXT']: error = self.state_machine.reporter.error( 'Images and figures require the alt text. See the M_IMAGES_REQUIRE_ALT_TEXT option.', image_node, line=self.lineno) return [error] self.add_name(image_node) if reference_node: if self.image_class: container_node = nodes.container() container_node['classes'] += [self.image_class] + classes reference_node += image_node container_node += reference_node return messages + [container_node] else: reference_node += image_node return messages + [reference_node] else: if self.image_class: image_node['classes'] += [self.image_class] + classes return messages + [image_node]
def run(self): if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value ' 'for the "align" option within a substitution ' 'definition. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join( self.align_v_values))) elif self.options['align'] not in self.align_h_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join( self.align_h_values))) messages = [] # previous code from Image.run() # -------------------------------------------------------------------- sumatra_options = build_options(self.state.document.settings, self.options) # determine which record store to use prj = determine_project(sumatra_options) record_store = determine_record_store(prj, sumatra_options, self.error) # determine the project (short) name project_name = determine_project_name(prj, sumatra_options, self.error) record_label, image_path = get_record_label_and_image_path( self.arguments[0]) record = record_store.get(project_name, record_label) image = get_image(record, image_path, self.options, self.error) # automatically checks digest if hasattr(image, "url"): reference = image.url else: if not os.path.exists(LOCAL_IMAGE_CACHE): os.makedirs(LOCAL_IMAGE_CACHE) reference = image.save_copy(LOCAL_IMAGE_CACHE) # set values for alt and target, if they have not been specified if not 'target' in self.options and hasattr(record_store, 'server_url'): self.options['target'] = record_link_url(record_store.server_url, project_name, record_label) if not 'alt' in self.options: self.options[ 'alt'] = "Data file generated by computation %s" % record_label # -------------------------------------------------------------------- # following code from Image.run() self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null(self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] set_classes(self.options) image_node = nodes.image(self.block_text, **self.options) self.add_name(image_node) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def run(self): messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null( self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] width = None height = None # If scaling requested, open the files and calculate the scaled size # Support both {filename} (3.7.1) and {static} (3.8) placeholders, # also prepend the absolute path in case we're not Pelican. In all # cases use only width and not both so the max-width can correctly # scale the image down on smaller screen sizes. # TODO: implement ratio-preserving scaling to avoid jumps on load using # the margin-bottom hack if 'scale' in self.options: file = os.path.join(os.getcwd(), settings['INPUT']) absuri = os.path.join(file, reference.format(filename=file, static=file)) im = PIL.Image.open(absuri) width = "{}px".format(int(im.width*self.options['scale']/100.0)) elif 'width' in self.options: width = self.options['width'] elif 'height' in self.options: height = self.options['height'] # TODO: convert to width instead? # Remove the classes from the image element, will be added either to it # or to the wrapping element later set_classes(self.options) classes = self.options.get('classes', []) if 'classes' in self.options: del self.options['classes'] if 'width' in self.options: del self.options['width'] if 'height' in self.options: del self.options['height'] image_node = nodes.image(self.block_text, width=width, height=height, **self.options) if not 'alt' in self.options and settings['M_IMAGES_REQUIRE_ALT_TEXT']: error = self.state_machine.reporter.error( 'Images and figures require the alt text. See the M_IMAGES_REQUIRE_ALT_TEXT option.', image_node, line=self.lineno) return [error] self.add_name(image_node) if reference_node: if self.image_class: container_node = nodes.container() container_node['classes'] += [self.image_class] + classes reference_node += image_node container_node += reference_node return messages + [container_node] else: reference_node += image_node return messages + [reference_node] else: if self.image_class: image_node['classes'] += [self.image_class] + classes return messages + [image_node]