feat: detect and remove comments

This commit is contained in:
Tim Grelka
2025-02-16 17:51:51 +01:00
parent 8882834136
commit 38635a7abd
3 changed files with 24 additions and 20 deletions
+17 -10
View File
@@ -3,22 +3,29 @@ import re
from mistletoe.block_token import BlockToken
from mistletoe.span_token import SpanToken
class SpanComment(SpanToken):
"""
Coment span token (% Eiersalat).
Identifies a comment in text.
"""
pattern = re.compile(r"(%.*\n?)")
# class SpanComment(SpanToken):
# """
# Coment span token (% Eiersalat).
# Identifies a comment in text.
# """
#
# pattern = re.compile(r"(%.*\n?)")
class BlockComment(BlockToken):
def __init__(self, match):
self.content = match
self.children = []
@staticmethod
def start(line):
return line.startswith("%")
@classmethod
def check_interrupts_paragraph(cls, lines):
return cls.start(lines.peek())
@classmethod
def read(cls, lines):
next(lines)
return None
comment = re.match(r"%(.*)", next(lines)).group(1).strip()
return comment
+1 -5
View File
@@ -1,6 +1,6 @@
from mistletoe.latex_renderer import LaTeXRenderer
from .comment import BlockComment, SpanComment
from .comment import BlockComment
from .dash import Dash
from .halfwidth_spaces import HalfwidthSpaces
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
@@ -14,7 +14,6 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
super().__init__(
Dash,
BlockComment,
SpanComment,
Quote,
Underline,
Tag,
@@ -33,9 +32,6 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
def render_block_comment(self, token):
return "" # TODO propagate comments to the LaTeX document
def render_span_comment(self, token):
return "" # TODO propagate comments to the LaTeX document
def render_quote(self, token):
return rf"\enquote{{{self.render_inner(token)}}}"