Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion markdown_it/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def render(self, src: str, env: Optional[AttrDict] = None) -> Any:
But you will not need it with high probability. See also comment
in [[MarkdownIt.parse]].
"""
env = env or AttrDict()
if env is None:
env = AttrDict()
return self.renderer.render(self.parse(src, env), self.options, env)

def parseInline(self, src: str, env: Optional[AttrDict] = None) -> List[Token]:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from markdown_it import MarkdownIt
from markdown_it.token import Token
from markdown_it.rules_core import StateCore
from markdown_it.utils import AttrDict


def test_get_rules():
Expand Down Expand Up @@ -250,3 +251,16 @@ def test_noneState():

# Check that we can process None str with empty env and block_tokens
md.core.process(state)


def test_empty_env():
"""Test that an empty `env` is mutated, not copied and mutated."""
md = MarkdownIt()

env = AttrDict()
md.render("[foo]: /url\n[foo]", env)
assert "references" in env

env = AttrDict()
md.parse("[foo]: /url\n[foo]", env)
assert "references" in env