예제 #1
0
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
예제 #2
0
def validate_config(app: Sphinx, config: Config):
    r"""
	Validate the provided configuration values.

	:param app: The Sphinx app.
	:param config:
	"""

    rst_prolog: Union[str, StringList] = config.rst_prolog or ''

    nbsp_sub = ".. |nbsp| unicode:: 0xA0\n   :trim:"
    if nbsp_sub not in rst_prolog:
        rst_prolog = StringList(rst_prolog)
        rst_prolog.append(nbsp_sub)

    config.rst_prolog = str(rst_prolog)  # type: ignore