Skip to content

Commit

Permalink
‼️ BREAKING: Remove v0.13 deprecations
Browse files Browse the repository at this point in the history
- Configuration variables: `myst_admonition_enable`, `myst_figure_enable`, `myst_dmath_enable`, `myst_amsmath_enable`, `myst_deflist_enable`, `myst_html_img_enable`
- `:::{admonition,class}` -> `:::{admonition}\n:class: class`
- `:::{figure}` -> `:::{figure-md}`
  • Loading branch information
chrisjsewell committed May 2, 2021
1 parent 4f8a39a commit ee5abf0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 135 deletions.
17 changes: 0 additions & 17 deletions myst_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@ def create_myst_config(app):

logger = logging.getLogger(__name__)

# TODO remove deprecations after v0.13.0
deprecations = {
"myst_admonition_enable": "colon_fence",
"myst_figure_enable": "colon_fence",
"myst_dmath_enable": "dollarmath",
"myst_amsmath_enable": "amsmath",
"myst_deflist_enable": "deflist",
"myst_html_img_enable": "html_image",
}
for old, new in deprecations.items():
if app.config[old]:
logger.warning(
f'config `{old}` is deprecated, please add "{new}" to '
"`myst_enable_extensions = []`"
)
app.config["myst_enable_extensions"].append(new)

values = {
name: app.config[f"myst_{name}"]
for name in MdParserConfig().as_dict().keys()
Expand Down
50 changes: 0 additions & 50 deletions myst_parser/docutils_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ def make_document(source_path="notset") -> nodes.document:

REGEX_DIRECTIVE_START = re.compile(r"^[\s]{0,3}([`]{3,10}|[~]{3,10}|[:]{3,10})\{")

# TODO remove deprecated after v0.13.0
# CSS class regex taken from https://www.w3.org/TR/CSS21/syndata.html#characters
REGEX_ADMONTION = re.compile(
r"\{(?P<name>[a-zA-Z]+)(?P<classes>(?:\,-?[_a-zA-Z]+[_a-zA-Z0-9-]*)*)\}(?P<title>.*)" # noqa: E501
)
STD_ADMONITIONS = {
"admonition": nodes.admonition,
"attention": nodes.attention,
"caution": nodes.caution,
"danger": nodes.danger,
"error": nodes.error,
"important": nodes.important,
"hint": nodes.hint,
"note": nodes.note,
"tip": nodes.tip,
"warning": nodes.warning,
}
try:
from sphinx import addnodes

STD_ADMONITIONS["seealso"] = addnodes.seealso
except ImportError:
pass


def token_line(token: Union[Token, NestedTokens], default: Optional[int] = None) -> int:
"""Retrieve the initial line of a token."""
Expand Down Expand Up @@ -853,32 +829,6 @@ def render_myst_role(self, token: Token):
def render_colon_fence(self, token: Token):
"""Render a code fence with ``:`` colon delimiters."""

# TODO remove deprecation after v0.13.0
match = REGEX_ADMONTION.match(token.info.strip())
if match and match.groupdict()["name"] in list(STD_ADMONITIONS) + ["figure"]:
classes = match.groupdict()["classes"][1:].split(",")
name = match.groupdict()["name"]
if classes and classes[0]:
self.create_warning(
"comma-separated classes are deprecated, "
"use `:class:` option instead",
line=token_line(token),
subtype="deprecation",
append_to=self.current_node,
)
# we assume that no other options have been used
token.content = f":class: {' '.join(classes)}\n\n" + token.content
if name == "figure":
self.create_warning(
":::{figure} is deprecated, " "use :::{figure-md} instead",
line=token_line(token),
subtype="deprecation",
append_to=self.current_node,
)
name = "figure-md"

token.info = f"{{{name}}} {match.groupdict()['title']}"

if token.content.startswith(":::"):
# the content starts with a nested fence block,
# but must distinguish between ``:options:``, so we add a new line
Expand Down
21 changes: 0 additions & 21 deletions myst_parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,6 @@ class MdParserConfig:

update_mathjax: bool = attr.ib(default=True, validator=instance_of(bool))

# TODO remove deprecated _enable attributes after v0.13.0
admonition_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)
figure_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)
dmath_enable: bool = attr.ib(default=False, validator=instance_of(bool), repr=False)
amsmath_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)
deflist_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)
html_img_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)
colon_fence_enable: bool = attr.ib(
default=False, validator=instance_of(bool), repr=False
)

enable_extensions: Iterable[str] = attr.ib(factory=lambda: ["dollarmath"])

@enable_extensions.validator
Expand Down
41 changes: 0 additions & 41 deletions tests/test_renderers/fixtures/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,6 @@ Basic note:
hallo
.

--------------------------------
Nested notes:
.
:::: {important}
::: {note,other}
*hallo*
:::
::::
.
<document source="notset">
<important>
<system_message level="2" line="1" source="notset" type="WARNING">
<paragraph>
comma-separated classes are deprecated, use `:class:` option instead [myst.deprecation]
<note classes="other">
<paragraph>
<emphasis>
hallo
.

--------------------------------
Admonition with title:
.
::: {admonition,other} A **title**
*hallo*
:::
.
<document source="notset">
<system_message level="2" line="1" source="notset" type="WARNING">
<paragraph>
comma-separated classes are deprecated, use `:class:` option instead [myst.deprecation]
<admonition classes="other">
<title>
A
<strong>
title
<paragraph>
<emphasis>
hallo
.

--------------------------------
Admonition with options:
.
Expand Down
8 changes: 6 additions & 2 deletions tests/test_sphinx/sourcedirs/extended_syntaxes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ Term 3

: other

:::{figure,other} target
:::{figure-md} target
:class: other

![fun-fish](fun-fish.png)

This is a caption in **Markdown**
:::

:::{figure,other} other-target
:::{figure-md} other-target
:class: other

<img src="fun-fish.png" alt="fishy" class="bg-primary mb-1" width="200px">

This is a caption in **Markdown**
Expand Down
5 changes: 1 addition & 4 deletions tests/test_sphinx/test_sphinx_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ def test_extended_syntaxes(
app.build()
assert "build succeeded" in status.getvalue() # Build succeeded
warnings = warning.getvalue().strip()
# TODO turn back on when deprecations removed after v0.13.0
# assert warnings == ""
assert "comma-separated classes are deprecated" in warnings
assert ":::{figure} is deprecated" in warnings
assert warnings == ""

try:
get_sphinx_app_doctree(app, docname="index", regress=True)
Expand Down

0 comments on commit ee5abf0

Please sign in to comment.