From c1cccce057080fe10fbb82aa1cfaba13d6370960 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Jun 2023 14:24:50 -0400 Subject: [PATCH 1/6] fix formatting of flowStyle description --- setup.cfg | 2 +- sphinx_asdf/directives.py | 6 +- sphinx_asdf/md2rst.py | 192 -------------------------------------- 3 files changed, 5 insertions(+), 195 deletions(-) delete mode 100644 sphinx_asdf/md2rst.py diff --git a/setup.cfg b/setup.cfg index 7d5af72..d1fc1c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,7 @@ install_requires = graphviz matplotlib myst-parser - mistune~=0.8.4 + mistune sphinx sphinx-astropy sphinx_bootstrap_theme diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index 93c4179..20eaa1a 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -1,15 +1,16 @@ import posixpath from pprint import pformat -import yaml from docutils import nodes from docutils.parsers.rst import directives from docutils.statemachine import ViewList +import mistune +from mistune.renderers.rst import RSTRenderer from sphinx import addnodes from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import nested_parse_with_titles +import yaml -from .md2rst import md2rst from .nodes import ( asdf_ref, asdf_tree, @@ -161,6 +162,7 @@ def _markdown_to_nodes(self, text, filename): by Michael Droetboom. """ rst = ViewList() + md2rst = mistune.create_markdown(renderer=RSTRenderer(), plugins=["math"]) for i, line in enumerate(md2rst(text).split("\n")): rst.append(line, filename, i + 1) diff --git a/sphinx_asdf/md2rst.py b/sphinx_asdf/md2rst.py deleted file mode 100644 index e465e8a..0000000 --- a/sphinx_asdf/md2rst.py +++ /dev/null @@ -1,192 +0,0 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst - -""" -Implements a markdown to reST converter using the mistune markdown -parser. - -This module was written by Michael Droetboom and has been copied from -http://github.com/spacetelescope/asdf-standard. See -../licenses/ASDF_STANDARD_LICENSE.rst for license information. -""" - -import re -import textwrap - -import mistune - - -class BlockLexer(mistune.BlockLexer): - # Adds math support - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.enable_math() - - def enable_math(self): - self.rules.block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL) - self.default_rules = ["block_math"] + mistune.BlockLexer.default_rules - - def parse_block_math(self, m): - self.tokens.append({"type": "block_math", "text": m.group(1)}) - - -class Markdown(mistune.Markdown): - def output_block_math(self): - return self.renderer.block_math(self.token["text"]) - - -class InlineLexer(mistune.InlineLexer): - # Adds math support - - default_rules = ["math"] + mistune.InlineLexer.default_rules - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.enable_math() - - def enable_math(self): - self.rules.text = re.compile(r"^[\s\S]+?(?=[\\`" - return f"`{text} <{link}>`__" - - def link(self, link, title, text): - if link.startswith("javascript:"): - link = "" - if link.startswith("ref:"): - return f":ref:`{text} <{link[4:]}>`" - return f"`{text} <{link}>`__" - - def image(self, src, title, text): - if src.startswith("javascript:"): - src = "" - options = {} - if text: - options["alt"] = text - return self._directive("image", "", [src], options) - - def tag(self, html): - if self.options.get("skip_html"): - return "" - return ":raw:`%s`" % html - - def newline(self): - return "" - - def footnote_ref(self, key, index): - raise NotImplementedError() - - def footnote_item(self, key, text): - raise NotImplementedError() - - def footnotes(self, text): - raise NotImplementedError() - - def math(self, text): - return ":math:`%s`" % text - - def block_math(self, text): - return self._directive("math", text) - - -def md2rst(content): - """ - Convert the given string in markdown to a string of reST. - """ - renderer = RstRenderer() - md = Markdown(block=BlockLexer, inline=InlineLexer, renderer=renderer) - return md.render(content) From 1dd98e343f31ccfc0be0e5fdd139c512e7f21647 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Jun 2023 14:27:30 -0400 Subject: [PATCH 2/6] increase min python to 3.9, drop unused dependencies --- setup.cfg | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index d1fc1c6..3bad07e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,16 +12,13 @@ github_project = spacetelescope/sphinx-asdf [options] packages = find: -python_requires = >=3.6 +python_requires = >=3.9 include_package_data = True setup_requires = setuptools_scm install_requires = asdf astropy>=5.0.4 docutils - graphviz - matplotlib - myst-parser mistune sphinx sphinx-astropy From 101eeb62fde2665472ccc38797b589b98a7ff4f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:28:30 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sphinx_asdf/directives.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index 20eaa1a..12d0896 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -1,15 +1,15 @@ import posixpath from pprint import pformat +import mistune +import yaml from docutils import nodes from docutils.parsers.rst import directives from docutils.statemachine import ViewList -import mistune from mistune.renderers.rst import RSTRenderer from sphinx import addnodes from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import nested_parse_with_titles -import yaml from .nodes import ( asdf_ref, From 179cb574ecfe08db17694a8465b7f4bb8d1d44a0 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Jun 2023 14:34:48 -0400 Subject: [PATCH 4/6] remove myst-parser from conf --- sphinx_asdf/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_asdf/conf.py b/sphinx_asdf/conf.py index 08ded14..ede38df 100644 --- a/sphinx_asdf/conf.py +++ b/sphinx_asdf/conf.py @@ -38,4 +38,4 @@ latex_logo = f"{static_dir}/logo.pdf" sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname("__file__")), "sphinxext")) -extensions += ["sphinx_asdf", "sphinx_inline_tabs", "myst_parser"] +extensions += ["sphinx_asdf", "sphinx_inline_tabs"] From 061261e8c0aa5ad426e8af38877792d697e007f0 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Jun 2023 15:07:11 -0400 Subject: [PATCH 5/6] add math rsupport to mistune RST renderer --- sphinx_asdf/directives.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index 12d0896..521aa25 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -45,6 +45,10 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) +def _math_to_rst(renderer, txt, block_state): + return f':math:{txt}' + + class AsdfAutoschemas(SphinxDirective): required_arguments = 0 optional_arguments = 2 @@ -162,7 +166,9 @@ def _markdown_to_nodes(self, text, filename): by Michael Droetboom. """ rst = ViewList() - md2rst = mistune.create_markdown(renderer=RSTRenderer(), plugins=["math"]) + renderer = RSTRenderer() + renderer.register('inline_math', _math_to_rst) + md2rst = mistune.create_markdown(renderer=renderer, plugins=["math"]) for i, line in enumerate(md2rst(text).split("\n")): rst.append(line, filename, i + 1) From 813e8d97e0503c74e756a507493b5f19a42b342b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Jun 2023 19:07:31 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sphinx_asdf/directives.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index 521aa25..18a511b 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -46,7 +46,7 @@ def __init__(self, *args, **kwargs): def _math_to_rst(renderer, txt, block_state): - return f':math:{txt}' + return f":math:{txt}" class AsdfAutoschemas(SphinxDirective): @@ -167,7 +167,7 @@ def _markdown_to_nodes(self, text, filename): """ rst = ViewList() renderer = RSTRenderer() - renderer.register('inline_math', _math_to_rst) + renderer.register("inline_math", _math_to_rst) md2rst = mistune.create_markdown(renderer=renderer, plugins=["math"]) for i, line in enumerate(md2rst(text).split("\n")): rst.append(line, filename, i + 1)