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 []
Beispiel #2
0
    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]
Beispiel #3
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]
Beispiel #4
0
def toc_ref(fullname, refid):
    name = whitespace_normalize_name(fullname),
    return TocRef('', fullname,
                  name=name, refuri=as_refuri(refid), classes=['toc'])
Beispiel #5
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]