Skip to content

Commit

Permalink
馃攢 MERGE: Internal improvements to the code base (#498)
Browse files Browse the repository at this point in the history
Internal improvements, that should mainly not be noticed by users
  • Loading branch information
chrisjsewell committed Jan 9, 2022
2 parents 9039a43 + f5f0b40 commit 74e91e6
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 206 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx/use.md
Expand Up @@ -185,7 +185,7 @@ All myst-parser warnings are prepended by their type, e.g. to suppress:
```

```
WARNING: Non-consecutive header level increase; 1 to 3 [myst.header]
WARNING: Non-consecutive header level increase; H1 to H3 [myst.header]
```

Add to your `conf.py`:
Expand Down
23 changes: 15 additions & 8 deletions myst_parser/directives.py
@@ -1,11 +1,14 @@
"""MyST specific directives"""
from typing import List, Tuple
from copy import copy
from typing import List, Tuple, cast

from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.directives import SphinxDirective
from sphinx.util.docutils import SphinxRole

from myst_parser.mocking import MockState


def align(argument):
return directives.choice(argument, ("left", "center", "right"))
Expand Down Expand Up @@ -61,16 +64,20 @@ def run(self) -> List[nodes.Node]:
figclasses = self.options.pop("class", None)
align = self.options.pop("align", None)

node = nodes.Element()
# TODO test that we are using myst parser
if not isinstance(self.state, MockState):
return [self.figure_error("Directive is only supported in myst parser")]
state = cast(MockState, self.state)

# ensure html image enabled
myst_extensions = self.state._renderer.config.get("myst_extensions", set())
myst_extensions = copy(state._renderer.md_config.enable_extensions)
node = nodes.Element()
try:
self.state._renderer.config.setdefault("myst_extensions", set())
self.state._renderer.config["myst_extensions"].add("html_image")
self.state.nested_parse(self.content, self.content_offset, node)
state._renderer.md_config.enable_extensions = list(
state._renderer.md_config.enable_extensions
) + ["html_image"]
state.nested_parse(self.content, self.content_offset, node)
finally:
self.state._renderer.config["myst_extensions"] = myst_extensions
state._renderer.md_config.enable_extensions = myst_extensions

if not len(node.children) == 2:
return [
Expand Down

0 comments on commit 74e91e6

Please sign in to comment.