Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃攢 MERGE: Internal improvements to the code base #498

Merged
merged 5 commits into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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