def run (self):
     pth = self.courtPathFromJurisdiction(self.arguments[0])
     rawlines = ""
     ifh = open(pth)
     while 1:
         line = ifh.readline()
         if not line: break
         if nodes.whitespace_normalize_name(line).startswith(".. reporter-key::"):
             reporter_key = re.sub("\.\.\s+reporter-key::\s*","",line).strip()
             pth = self.reporterPathFromJurisdiction(self.arguments[0],reporter_key)
             newlines = open(pth).read()
             newlines = newlines.split("\n")
             for i in range(0,len(newlines),1):
                 newlines[i] = re.sub("^(\s*)(\.\.\s+reporter::.*)","\\1\\2\n\\1      :jurisdiction: %s" % self.arguments[0],newlines[i])
                 newlines[i] = "   " + newlines[i]
             newlines = "\n".join(newlines)
             rawlines += newlines
         else:
             rawlines += line
     tab_width = self.options.get(
         'tab-width', self.state.document.settings.tab_width)
     include_lines = statemachine.string2lines(rawlines, tab_width,
                                               convert_whitespace=True)
     self.state_machine.insert_input(include_lines, pth)
     return []
Ejemplo n.º 2
0
def toc_ref(fullname, refid):
    name = (whitespace_normalize_name(fullname), )
    return TocRef("",
                  fullname,
                  name=name,
                  refuri=as_refuri(refid),
                  classes=["toc"])
Ejemplo n.º 3
0
def toc_ref(fullname, refid):
    name = whitespace_normalize_name(fullname),
    return TocRef('',
                  fullname,
                  name=name,
                  refuri=as_refuri(refid),
                  classes=['toc'])
Ejemplo n.º 4
0
Archivo: images.py Proyecto: xcore/xdoc
    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]
Ejemplo n.º 6
0
    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]
Ejemplo n.º 7
0
    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]
Ejemplo n.º 8
0
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]
Ejemplo n.º 9
0
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]
Ejemplo n.º 10
0
 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 reference(
     self, match: Match, lineno: int, anonymous: bool = False
 ) -> DispatchResult:
     """Handle simple references,  e.g. reference_ and anonymous__ """
     referencename = match.group("refname")
     refname = normalize_name(referencename)
     referencenode = nodes.reference(
         referencename + match.group("refend"),
         referencename,
         name=whitespace_normalize_name(referencename),
     )
     referencenode[0].rawsource = referencename
     if anonymous:
         referencenode["anonymous"] = 1
     else:
         referencenode["refname"] = refname
         self.document.note_refname(referencenode)
     string = match.string
     matchstart = match.start("whole")
     matchend = match.end("whole")
     return (string[:matchstart], [referencenode], string[matchend:], [])
Ejemplo n.º 12
0
def toc_ref(fullname, refid):
    name = whitespace_normalize_name(fullname),
    return TocRef('', fullname,
                  name=name, refuri=as_refuri(refid), classes=['toc'])
Ejemplo n.º 13
0
    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 phrase_ref(
        self, before: str, after: str, rawsource: str, escaped: str, text: str
    ) -> DispatchResult:
        """Handle phrase references e.g. `phrase ref`_, `embedded <ref_>`_ """
        match = self.patterns.embedded_link.search(escaped)
        if match:  # embedded <URI> or <alias_>
            text = unescape(escaped[: match.start(0)])
            rawtext = unescape(escaped[: match.start(0)], True)
            aliastext = unescape(match.group(2))
            rawaliastext = unescape(match.group(2), True)
            underscore_escaped = rawaliastext.endswith(r"\_")
            if aliastext.endswith("_") and not (
                underscore_escaped or self.patterns.uri.match(aliastext)
            ):
                aliastype = "name"
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = "uri"
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = " ".join(
                    "".join(unescape(part).split()) for part in alias_parts
                )
                alias = self.adjust_uri(alias)
                if alias.endswith(r"\_"):
                    alias = alias[:-2] + "_"
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError("problem with embedded link: %r" % aliastext)
            if not text:
                text = alias
                rawtext = rawaliastext
        else:
            target = None
            rawtext = unescape(escaped, True)

        refname = normalize_name(text)
        reference = nodes.reference(
            rawsource, text, name=whitespace_normalize_name(text)
        )
        reference[0].rawsource = rawtext

        node_list = [reference]

        if rawsource[-2:] == "__":
            if target and (aliastype == "name"):
                reference["refname"] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == "uri"):
                reference["refuri"] = alias
            else:
                reference["anonymous"] = 1
        else:
            if target:
                target["names"].append(refname)
                if aliastype == "name":
                    reference["refname"] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference["refuri"] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference["refname"] = refname
                self.document.note_refname(reference)
        return before, node_list, after, []
Ejemplo n.º 15
0
    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]