Skip to content

Commit

Permalink
highlight html
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfast committed Aug 16, 2024
1 parent 265fc67 commit b8f17d4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/midgy/tangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import markdown_it
import markdown_it.renderer
import pygments

__all__ = ()

Expand All @@ -30,9 +31,10 @@ def renderToken(self, tokens, idx, options, env):
string = super().renderToken(tokens, idx, options, env)
if len(string) == 2 and string == "<>":
return ""

return string


@dataclass
class Tangle:
_type = None
Expand Down Expand Up @@ -218,8 +220,17 @@ def initalize_parser_defaults(self, parser):
parser.block.ruler.before("table", "front_matter", _front_matter_lexer)
parser.use(footnote.footnote_plugin).use(deflist.deflist_plugin)
parser.disable("footnote_tail")
parser.code_formatter = pygments.formatters.get_formatter_by_name("html", noclasses=True)
parser.options["highlight"] = self.highlight
return parser

def highlight(self, source, lang, attrs):
return pygments.highlight(
source,
pygments.lexers.get_lexer_by_name(lang),
self.parser.code_formatter,
)

def is_code_block(self, token):
"""is the token a code block entry"""
if self.indented_code_blocks and token.type == BLOCK:
Expand Down

0 comments on commit b8f17d4

Please sign in to comment.