コード例 #1
0
ファイル: __init__.py プロジェクト: hir3n0/JWK
 def parse(self, inputstring, document):
     """Parse `inputstring` and populate `document`, a document tree."""
     self.setup_parse(inputstring, document)
     # provide fallbacks in case the document has only generic settings
     self.document.settings.setdefault('tab_width', 8)
     self.document.settings.setdefault('syntax_highlight', 'long')
     self.statemachine = states.RSTStateMachine(
         state_classes=self.state_classes,
         initial_state=self.initial_state,
         debug=document.reporter.debug_flag)
     inputlines = docutils.statemachine.string2lines(
         inputstring,
         tab_width=document.settings.tab_width,
         convert_whitespace=True)
     for i, line in enumerate(inputlines):
         if len(line) > self.document.settings.line_length_limit:
             error = self.document.reporter.error(
                 'Line %d exceeds the line-length-limit.' % (i + 1))
             self.document.append(error)
             break
     else:
         self.statemachine.run(inputlines, document, inliner=self.inliner)
     # restore the "default" default role after parsing a document
     if '' in roles._roles:
         del roles._roles['']
     self.finish_parse()
コード例 #2
0
ファイル: pep_title.py プロジェクト: DavidMertz/peps
def _line_to_nodes(text: str) -> list[nodes.Node]:
    """Parse RST string to nodes."""
    document = utils.new_document("<inline-rst>")
    document.settings.pep_references = document.settings.rfc_references = False  # patch settings
    states.RSTStateMachine(state_classes=states.state_classes, initial_state="Body").run([text], document)  # do parsing
    roles._roles.pop("", None)  # restore the "default" default role after parsing a document
    return document[0].children
コード例 #3
0
ファイル: rest.py プロジェクト: zogzog/cubicweb
 def __init__(self):
     self.initial_state = 'Body'
     self.state_classes = states.state_classes
     self.inliner = states.Inliner()
     self.statemachine = states.RSTStateMachine(
         state_classes=self.state_classes,
         initial_state=self.initial_state,
         debug=0)
コード例 #4
0
 def parse(self, inputstring, document):
     """Parse `inputstring` and populate `document`, a document tree."""
     self.setup_parse(inputstring, document)
     self.statemachine = states.RSTStateMachine(
           state_classes=self.state_classes,
           initial_state=self.initial_state,
           debug=document.reporter.debug_flag)
     inputlines = docutils.statemachine.string2lines(
           inputstring, tab_width=document.settings.tab_width,
           convert_whitespace=1)
     self.statemachine.run(inputlines, document, inliner=self.inliner)
     self.finish_parse()
コード例 #5
0
ファイル: __init__.py プロジェクト: 05050830/catkin_ws
 def parse(self, inputstring, document):
     """Parse `inputstring` and populate `document`, a document tree."""
     self.setup_parse(inputstring, document)
     self.statemachine = states.RSTStateMachine(
           state_classes=self.state_classes,
           initial_state=self.initial_state,
           debug=document.reporter.debug_flag)
     inputlines = docutils.statemachine.string2lines(
           inputstring, tab_width=document.settings.tab_width,
           convert_whitespace=True)
     self.statemachine.run(inputlines, document, inliner=self.inliner)
     # restore the "default" default role after parsing a document
     if '' in roles._roles:
         del roles._roles['']
     self.finish_parse()
コード例 #6
0
ファイル: pod.py プロジェクト: mgage/docutils-rosetta
    def parse(self, inputstring, document):
        self.setup_parse(inputstring, document)

        rst_statemachine = states.RSTStateMachine(
              state_classes=states.state_classes,
              initial_state='Body',
              debug=document.reporter.debug_flag
        )

        self.transform = PODTransform(rst_statemachine=rst_statemachine,
                                      document=self.document)
        self.transform.document = document

        self.document = self.transform.parse(inputstring + '\n').document()

        self.finish_parse()
コード例 #7
0
    def parse(self, inputstring, document):
        # type: (Any, nodes.document) -> None
        """Parse text and generate a document tree.

        This accepts StringList as an inputstring parameter.
        It enables to handle mixed contents (cf. :confval:`rst_prolog`) correctly.
        """
        if isinstance(inputstring, StringList):
            self.setup_parse(inputstring, document)
            self.statemachine = states.RSTStateMachine(
                state_classes=self.state_classes,
                initial_state=self.initial_state,
                debug=document.reporter.debug_flag)
            # Give inputstring directly to statemachine.
            self.statemachine.run(inputstring, document, inliner=self.inliner)
            self.finish_parse()
        else:
            # otherwise, inputstring might be a string. It will be handled by superclass.
            docutils.parsers.rst.Parser.parse(self, inputstring, document)
コード例 #8
0
    def parse(self, inputstring, document):
        """Parse `inputstring` and populate `document`, a document tree."""
        document.meta_block = collections.defaultdict(list)

        # following code swiped from docutils/parsers/rst/__init__.py
        # and tweaked to call our own string2lines (that only strips
        # U+0020 trailing whitespace).
        # docutils.parsers.rst.Parser.parse (self, inputstring,
        # document)

        self.setup_parse(inputstring, document)
        self.statemachine = states.RSTStateMachine(
            state_classes=self.state_classes,
            initial_state=self.initial_state,
            debug=document.reporter.debug_flag)
        inputlines = string2lines(inputstring,
                                  tab_width=document.settings.tab_width,
                                  convert_whitespace=1)
        self.statemachine.run(inputlines, document, inliner=self.inliner)
        self.finish_parse()
コード例 #9
0
ファイル: parsers.py プロジェクト: jianwang2020/sphinx_demo
    def parse(self, inputstring: Union[str, StringList], document: nodes.document) -> None:
        """Parse text and generate a document tree."""
        self.setup_parse(inputstring, document)  # type: ignore
        self.statemachine = states.RSTStateMachine(
            state_classes=self.state_classes,
            initial_state=self.initial_state,
            debug=document.reporter.debug_flag)

        # preprocess inputstring
        if isinstance(inputstring, str):
            lines = docutils.statemachine.string2lines(
                inputstring, tab_width=document.settings.tab_width,
                convert_whitespace=True)

            inputlines = StringList(lines, document.current_source)
        else:
            inputlines = inputstring

        self.decorate(inputlines)
        self.statemachine.run(inputlines, document, inliner=self.inliner)
        self.finish_parse()
コード例 #10
0
ファイル: doc2.py プロジェクト: rickbutton/JMTK
 def __init__(self, rfc2822=None, inliner=None):
     self.statemachine = states.RSTStateMachine(
         state_classes=self.state_classes,
         initial_state="Body",
         debug=document.reporter.debug_flag)