Skip to content

Commit

Permalink
allow code fence methods when no other code blocks exist
Browse files Browse the repository at this point in the history
rm old language file
  • Loading branch information
tonyfast committed Oct 19, 2024
1 parent d2c16b0 commit 25f3d11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 414 deletions.
8 changes: 3 additions & 5 deletions src/midgy/language/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Python(Markdown, type="text/x-python", language="ipython3"):
dot="midgy.types:Dot",
md="midgy.types:Markdown",
lisp="midgy.types:Hy.eval",
hy="midgy.types:Hy.eval"
hy="midgy.types:Hy.eval",
)
fenced_code_blocks: list = field(
default_factory=["python", "python3", "ipython3", "ipython", ""].copy
Expand Down Expand Up @@ -152,6 +152,7 @@ def fence(self, token, env):
if token.meta.get("is_doctest"):
if self.doctest_code_blocks:
yield from self.fence_doctest(token, env)
raise NotImplementedError()
elif self.fenced_code_blocks:
lang = self.get_lang(token)
# format the prior non-code
Expand All @@ -164,7 +165,6 @@ def fence(self, token, env):
yield from self.fence_noncode(token, env)
else:
return
self.update_env(token, env, continued=False)
yield ""

def fence_code(self, token, env):
Expand All @@ -185,11 +185,10 @@ def fence_code(self, token, env):
# comment out the last of fence dashes
yield self.COMMENT_MARKER
yield from self.generate_block_lines(env, token.map[1])
self.update_env(token, env)
self.update_env(token, env, quoted=False, continued=False)
# we don't allow for continued blocks or explicit quotes with code fences.
# these affordances are only possible with indented code blocks.
# continutation can be acheived using parenthesis continuation
env.update(quoted=False, continued=False)

def fence_doctest(self, token, env):
"""render code fence as python code"""
Expand Down Expand Up @@ -237,7 +236,6 @@ def fence_noncode(self, token, env):
yield last[-1]
else:
yield from rest
env.update(continued=False if method else env.get("continued"))

def front_matter(self, token, env):
"""render front matter as python code with an optional variable name"""
Expand Down
Loading

0 comments on commit 25f3d11

Please sign in to comment.