Skip to content

Commit 8cc8de3

Browse files
authored
Merge branch 'master' into fix-smartquotes
2 parents dad0f46 + a874755 commit 8cc8de3

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

markdown_it/cli/parse.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ def convert_file(filename):
4040
sys.exit('Cannot open file "{}".'.format(filename))
4141

4242

43-
def interactive(import_readline=False):
43+
def interactive():
4444
"""
4545
Parse user input, dump to stdout, rinse and repeat.
4646
Python REPL style.
4747
"""
48-
if import_readline:
49-
_import_readline()
5048
print_heading()
5149
contents = []
5250
more = False
@@ -98,13 +96,6 @@ def parse_args(args):
9896
return parser.parse_args(args)
9997

10098

101-
def _import_readline():
102-
try:
103-
import readline # noqa: F401
104-
except ImportError:
105-
print("[warning] readline library not available.")
106-
107-
10899
def print_heading():
109100
print("{} (interactive)".format(version_str))
110101
print("Type Ctrl-D to complete input, or Ctrl-C to exit.")

markdown_it/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def render(self, src: str, env: Optional[AttrDict] = None) -> Any:
240240
But you will not need it with high probability. See also comment
241241
in [[MarkdownIt.parse]].
242242
"""
243-
env = env or AttrDict()
243+
if env is None:
244+
env = AttrDict()
244245
return self.renderer.render(self.parse(src, env), self.options, env)
245246

246247
def parseInline(self, src: str, env: Optional[AttrDict] = None) -> List[Token]:

tests/test_api/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from markdown_it import MarkdownIt
22
from markdown_it.token import Token
33
from markdown_it.rules_core import StateCore
4+
from markdown_it.utils import AttrDict
45

56

67
def test_get_rules():
@@ -250,3 +251,16 @@ def test_noneState():
250251

251252
# Check that we can process None str with empty env and block_tokens
252253
md.core.process(state)
254+
255+
256+
def test_empty_env():
257+
"""Test that an empty `env` is mutated, not copied and mutated."""
258+
md = MarkdownIt()
259+
260+
env = AttrDict()
261+
md.render("[foo]: /url\n[foo]", env)
262+
assert "references" in env
263+
264+
env = AttrDict()
265+
md.parse("[foo]: /url\n[foo]", env)
266+
assert "references" in env

tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ def mock_input(prompt):
2424

2525
with patch("builtins.print") as patched:
2626
with patch("builtins.input", mock_input):
27-
parse.interactive(import_readline=False)
27+
parse.interactive()
2828
patched.assert_called()

0 commit comments

Comments
 (0)