def publish_msgstr(app, source, source_path, source_line, config, settings): # type: (Sphinx, unicode, unicode, int, Config, Dict) -> nodes.document """Publish msgstr (single line) into docutils document :param sphinx.application.Sphinx app: sphinx application :param unicode source: source text :param unicode source_path: source path for warning indication :param source_line: source line for warning indication :param sphinx.config.Config config: sphinx config :param docutils.frontend.Values settings: docutils settings :return: document :rtype: docutils.nodes.document """ from sphinx.io import SphinxI18nReader reader = SphinxI18nReader(app) parser = app.registry.create_source_parser(app, 'restructuredtext') doc = reader.read( source=StringInput(source=source, source_path="%s:%s:<translated>" % (source_path, source_line)), parser=parser, settings=settings, ) try: doc = doc[0] except IndexError: # empty node pass return doc
def publish_msgstr(app, source, source_path, source_line, config, settings): # type: (Sphinx, unicode, unicode, int, Config, Dict) -> nodes.document """Publish msgstr (single line) into docutils document :param sphinx.application.Sphinx app: sphinx application :param unicode source: source text :param unicode source_path: source path for warning indication :param source_line: source line for warning indication :param sphinx.config.Config config: sphinx config :param docutils.frontend.Values settings: docutils settings :return: document :rtype: docutils.nodes.document """ from sphinx.io import SphinxI18nReader reader = SphinxI18nReader( app=app, parsers=app.registry.get_source_parsers(), parser_name='restructuredtext', # default parser ) reader.set_lineno_for_reporter(source_line) doc = reader.read( source=StringInput(source=source, source_path=source_path), parser=reader.parser, settings=settings, ) try: doc = doc[0] except IndexError: # empty node pass return doc
def publish_msgstr(app: "Sphinx", source: str, source_path: str, source_line: int, config: Config, settings: Any) -> Element: """Publish msgstr (single line) into docutils document :param sphinx.application.Sphinx app: sphinx application :param str source: source text :param str source_path: source path for warning indication :param source_line: source line for warning indication :param sphinx.config.Config config: sphinx config :param docutils.frontend.Values settings: docutils settings :return: document :rtype: docutils.nodes.document """ try: # clear rst_prolog temporarily rst_prolog = config.rst_prolog config.rst_prolog = None # type: ignore from sphinx.io import SphinxI18nReader reader = SphinxI18nReader() reader.setup(app) filetype = get_filetype(config.source_suffix, source_path) parser = app.registry.create_source_parser(app, filetype) doc = reader.read( source=StringInput(source=source, source_path="%s:%s:<translated>" % (source_path, source_line)), parser=parser, settings=settings, ) try: doc = doc[0] # type: ignore except IndexError: # empty node pass return doc finally: config.rst_prolog = rst_prolog # type: ignore