Exemplo n.º 1
0
 def run(self):
     env = self.state.document.settings.env
     if self.arguments[0].startswith('<') and \
        self.arguments[0].endswith('>'):
         # docutils "standard" includes, do not do path processing
         return BaseInclude.run(self)
     rel_filename, filename = env.relfn2path(self.arguments[0])
     self.arguments[0] = filename
     return BaseInclude.run(self)
Exemplo n.º 2
0
 def run(self):
     env = self.state.document.settings.env
     if self.arguments[0].startswith('<') and \
        self.arguments[0].endswith('>'):
         # docutils "standard" includes, do not do path processing
         return BaseInclude.run(self)
     rel_filename, filename = env.relfn2path(self.arguments[0])
     self.arguments[0] = filename
     return BaseInclude.run(self)
Exemplo n.º 3
0
 def run(self):
     # type: () -> List[nodes.Node]
     if self.arguments[0].startswith('<') and \
        self.arguments[0].endswith('>'):
         # docutils "standard" includes, do not do path processing
         return BaseInclude.run(self)
     rel_filename, filename = self.env.relfn2path(self.arguments[0])
     self.arguments[0] = filename
     self.env.note_included(filename)
     return BaseInclude.run(self)
Exemplo n.º 4
0
 def run(self):
     # type: () -> List[nodes.Node]
     if self.arguments[0].startswith('<') and \
        self.arguments[0].endswith('>'):
         # docutils "standard" includes, do not do path processing
         return BaseInclude.run(self)
     rel_filename, filename = self.env.relfn2path(self.arguments[0])
     self.arguments[0] = filename
     self.env.note_included(filename)
     return BaseInclude.run(self)
Exemplo n.º 5
0
    def run(self):
        nbfilename = self.arguments[0]
        rstfilename = get_rstfilename(nbfilename)

        if not os.path.exists(rstfilename):
            return []

        self.arguments[0] = rstfilename
        return Include.run(self)
Exemplo n.º 6
0
    def run(self):
        nbfilename = self.arguments[0]
        rstfilename = get_rstfilename(nbfilename)

        if not os.path.exists(rstfilename):
            return []

        self.arguments[0] = rstfilename
        return Include.run(self)
Exemplo n.º 7
0
 def run(self):
     # disable Sphinx modification to docutils Include
     #env = self.state.document.settings.env
     #if self.arguments[0].startswith('<') and \
     #   self.arguments[0].endswith('>'):
     #    # docutils "standard" includes, do not do path processing
     #    return BaseInclude.run(self)
     #rel_filename, filename = env.relfn2path(self.arguments[0])
     #self.arguments[0] = filename
     return BaseInclude.run(self)
Exemplo n.º 8
0
 def run(self):
     # disable Sphinx modification to docutils Include
     #env = self.state.document.settings.env
     #if self.arguments[0].startswith('<') and \
     #   self.arguments[0].endswith('>'):
     #    # docutils "standard" includes, do not do path processing
     #    return BaseInclude.run(self)
     #rel_filename, filename = env.relfn2path(self.arguments[0])
     #self.arguments[0] = filename
     return BaseInclude.run(self)
 def run(self):
     if (self.arguments[0].startswith('/')
             or self.arguments[0].startswith(os.sep)):
         env = self.state.document.settings.env
         self.arguments[0] = os.path.join(env.srcdir, self.arguments[0][1:])
     fo = tempfile.NamedTemporaryFile(delete=False)
     with open(str(self.arguments[0])) as fi:
         self.invert_blocks(fi, fo)
     self.arguments[0] = fo.name
     fo.close()
     res = BaseInclude.run(self)
     os.unlink(fo.name)
     return res
 def run(self):
     if (self.arguments[0].startswith('/') or
         self.arguments[0].startswith(os.sep)):
         env = self.state.document.settings.env
         self.arguments[0] = os.path.join(env.srcdir, self.arguments[0][1:])
     fo = tempfile.NamedTemporaryFile(delete=False)
     with open(str(self.arguments[0])) as fi:
       self.invert_blocks(fi, fo)
     self.arguments[0] = fo.name
     fo.close()
     res = BaseInclude.run(self)
     os.unlink(fo.name)
     return res
Exemplo n.º 11
0
 def run(self):
     # type: () -> List[nodes.Node]
     print(self.options)
     env = self.state.document.settings.env
     # if self.arguments[0].startswith('<') and \
     #    self.arguments[0].endswith('>'):
     #     # docutils "standard" includes, do not do path processing
     #     return Include.run(self)
     rel_filename, filename = env.relfn2path(self.arguments[0])
     self.arguments[0] = filename
     print(dir(env))
     env.note_included(filename)
     nodes = Include.run(self)
     print(dir(nodes))
     return nodes
Exemplo n.º 12
0
 def run(self):
     if self.arguments[0].startswith('/') or \
            self.arguments[0].startswith(os.sep):
         env = self.state.document.settings.env
         self.arguments[0] = os.path.join(env.srcdir, self.arguments[0][1:])
     return BaseInclude.run(self)
Exemplo n.º 13
0
    def run(self):
        env = self.state.document.settings.env

        if self.arguments[0].startswith('<') and \
           self.arguments[0].endswith('>'):
            # docutils "standard" includes, do not do path processing
            return BaseInclude.run(self)
        rel_filename, filename = env.relfn2path(self.arguments[0])
        self.arguments[0] = filename
        
        if not self.state.document.settings.file_insertion_enabled:
            raise self.warning('"%s" directive disabled.' % self.name)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        source_dir = os.path.dirname(os.path.abspath(source))
        path = directives.path(self.arguments[0])
        if path.startswith('<') and path.endswith('>'):
            path = os.path.join(self.standard_include_path, path[1:-1])
        path = os.path.normpath(os.path.join(source_dir, path))
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)
        encoding = self.options.get(
            'encoding', self.state.document.settings.input_encoding)
        tab_width = self.options.get(
            'tab-width', self.state.document.settings.tab_width)
        try:
            self.state.document.settings.record_dependencies.add(path)
            include_file = io.FileInput(
                source_path=path, encoding=encoding,
                error_handler=(self.state.document.settings.\
                               input_encoding_error_handler),
                handle_io_errors=None)
        except IOError as error:
            raise self.severe('Problems with "%s" directive path:\n%s.' %
                      (self.name, error))
        startline = self.options.get('start-line', None)
        endline = self.options.get('end-line', None)
        try:
            if startline or (endline is not None):
                lines = include_file.readlines()
                rawtext = ''.join(lines[startline:endline])
            else:
                rawtext = include_file.read()
        except UnicodeError as error:
            raise self.severe('Problem with "%s" directive:\n%s' %
                              (self.name, ErrorString(error)))
        # start-after/end-before: no restrictions on newlines in match-text,
        # and no restrictions on matching inside lines vs. line boundaries
        after_text = self.options.get('start-after', None)
        if after_text:
            # skip content in rawtext before *and incl.* a matching text
            after_index = rawtext.find(after_text)
            if after_index < 0:
                raise self.severe('Problem with "start-after" option of "%s" '
                                  'directive:\nText not found.' % self.name)
            rawtext = rawtext[after_index + len(after_text):]
        before_text = self.options.get('end-before', None)
        if before_text:
            # skip content in rawtext after *and incl.* a matching text
            before_index = rawtext.find(before_text)
            if before_index < 0:
                raise self.severe('Problem with "end-before" option of "%s" '
                                  'directive:\nText not found.' % self.name)
            rawtext = rawtext[:before_index]
        if 'literal' in self.options:
            # Convert tabs to spaces, if `tab_width` is positive.
            if tab_width >= 0:
                text = rawtext.expandtabs(tab_width)
            else:
                text = rawtext
            literal_block = nodes.literal_block(rawtext, text, source=path)
            literal_block.line = 1
            return [literal_block]
        else:
            include_lines = statemachine.string2lines(
                rawtext, tab_width, convert_whitespace=1)
            
            include_lines = preProcessLines( include_lines )
            
            self.state_machine.insert_input(include_lines, path)
            return []
Exemplo n.º 14
0
    def run(self):
        env = self.state.document.settings.env

        if self.arguments[0].startswith('<') and \
           self.arguments[0].endswith('>'):
            # docutils "standard" includes, do not do path processing
            return BaseInclude.run(self)
        rel_filename, filename = env.relfn2path(self.arguments[0])
        self.arguments[0] = filename

        if not self.state.document.settings.file_insertion_enabled:
            raise self.warning('"%s" directive disabled.' % self.name)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        source_dir = os.path.dirname(os.path.abspath(source))
        path = directives.path(self.arguments[0])
        if path.startswith('<') and path.endswith('>'):
            path = os.path.join(self.standard_include_path, path[1:-1])
        path = os.path.normpath(os.path.join(source_dir, path))
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)
        encoding = self.options.get(
            'encoding', self.state.document.settings.input_encoding)
        tab_width = self.options.get('tab-width',
                                     self.state.document.settings.tab_width)
        try:
            self.state.document.settings.record_dependencies.add(path)
            include_file = io.FileInput(
                source_path=path, encoding=encoding,
                error_handler=(self.state.document.settings.\
                               input_encoding_error_handler),
                handle_io_errors=None)
        except IOError as error:
            raise self.severe('Problems with "%s" directive path:\n%s.' %
                              (self.name, error))
        startline = self.options.get('start-line', None)
        endline = self.options.get('end-line', None)
        try:
            if startline or (endline is not None):
                lines = include_file.readlines()
                rawtext = ''.join(lines[startline:endline])
            else:
                rawtext = include_file.read()
        except UnicodeError as error:
            raise self.severe('Problem with "%s" directive:\n%s' %
                              (self.name, ErrorString(error)))
        # start-after/end-before: no restrictions on newlines in match-text,
        # and no restrictions on matching inside lines vs. line boundaries
        after_text = self.options.get('start-after', None)
        if after_text:
            # skip content in rawtext before *and incl.* a matching text
            after_index = rawtext.find(after_text)
            if after_index < 0:
                raise self.severe('Problem with "start-after" option of "%s" '
                                  'directive:\nText not found.' % self.name)
            rawtext = rawtext[after_index + len(after_text):]
        before_text = self.options.get('end-before', None)
        if before_text:
            # skip content in rawtext after *and incl.* a matching text
            before_index = rawtext.find(before_text)
            if before_index < 0:
                raise self.severe('Problem with "end-before" option of "%s" '
                                  'directive:\nText not found.' % self.name)
            rawtext = rawtext[:before_index]
        if 'literal' in self.options:
            # Convert tabs to spaces, if `tab_width` is positive.
            if tab_width >= 0:
                text = rawtext.expandtabs(tab_width)
            else:
                text = rawtext
            literal_block = nodes.literal_block(rawtext, text, source=path)
            literal_block.line = 1
            return [literal_block]
        else:
            include_lines = statemachine.string2lines(rawtext,
                                                      tab_width,
                                                      convert_whitespace=1)

            include_lines = preProcessLines(include_lines)

            self.state_machine.insert_input(include_lines, path)
            return []
Exemplo n.º 15
0
 def run(self):
     if self.arguments[0].startswith('/') or \
            self.arguments[0].startswith(os.sep):
         env = self.state.document.settings.env
         self.arguments[0] = os.path.join(env.srcdir, self.arguments[0][1:])
     return BaseInclude.run(self)