feat: detect and remove comments
This commit is contained in:
+17
-10
@@ -3,22 +3,29 @@ import re
|
|||||||
from mistletoe.block_token import BlockToken
|
from mistletoe.block_token import BlockToken
|
||||||
from mistletoe.span_token import SpanToken
|
from mistletoe.span_token import SpanToken
|
||||||
|
|
||||||
|
# class SpanComment(SpanToken):
|
||||||
class SpanComment(SpanToken):
|
# """
|
||||||
"""
|
# Coment span token (% Eiersalat).
|
||||||
Coment span token (% Eiersalat).
|
# Identifies a comment in text.
|
||||||
Identifies a comment in text.
|
# """
|
||||||
"""
|
#
|
||||||
|
# pattern = re.compile(r"(%.*\n?)")
|
||||||
pattern = re.compile(r"(%.*\n?)")
|
|
||||||
|
|
||||||
|
|
||||||
class BlockComment(BlockToken):
|
class BlockComment(BlockToken):
|
||||||
|
def __init__(self, match):
|
||||||
|
self.content = match
|
||||||
|
self.children = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start(line):
|
def start(line):
|
||||||
return line.startswith("%")
|
return line.startswith("%")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def check_interrupts_paragraph(cls, lines):
|
||||||
|
return cls.start(lines.peek())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read(cls, lines):
|
def read(cls, lines):
|
||||||
next(lines)
|
comment = re.match(r"%(.*)", next(lines)).group(1).strip()
|
||||||
return None
|
return comment
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from mistletoe.latex_renderer import LaTeXRenderer
|
from mistletoe.latex_renderer import LaTeXRenderer
|
||||||
|
|
||||||
from .comment import BlockComment, SpanComment
|
from .comment import BlockComment
|
||||||
from .dash import Dash
|
from .dash import Dash
|
||||||
from .halfwidth_spaces import HalfwidthSpaces
|
from .halfwidth_spaces import HalfwidthSpaces
|
||||||
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
from .nonbreaking_spaces import NonbreakingSpaces, NonbreakingSpacesDots
|
||||||
@@ -14,7 +14,6 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
Dash,
|
Dash,
|
||||||
BlockComment,
|
BlockComment,
|
||||||
SpanComment,
|
|
||||||
Quote,
|
Quote,
|
||||||
Underline,
|
Underline,
|
||||||
Tag,
|
Tag,
|
||||||
@@ -33,9 +32,6 @@ class FiftyOhmLaTeXRenderer(LaTeXRenderer):
|
|||||||
def render_block_comment(self, token):
|
def render_block_comment(self, token):
|
||||||
return "" # TODO propagate comments to the LaTeX document
|
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):
|
def render_quote(self, token):
|
||||||
return rf"\enquote{{{self.render_inner(token)}}}"
|
return rf"\enquote{{{self.render_inner(token)}}}"
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ from test.util import paragraph
|
|||||||
@pytest.mark.html
|
@pytest.mark.html
|
||||||
def test_comment_html():
|
def test_comment_html():
|
||||||
assertions = {
|
assertions = {
|
||||||
"%Comment\nBar": "Bar",
|
# TODOD: Remove \n
|
||||||
# TODO: This test is not working as expected. The comment should be removed
|
"%Comment\nBar": paragraph("Bar"),
|
||||||
# "%Comment\n" : "a",
|
"%Comment\n": "",
|
||||||
"Foo\n%Comment\nBar": "Foo\nBar",
|
"Foo 100 % Bar": paragraph("Foo 100% Bar"),
|
||||||
|
"Foo\n%Comment\nBar": paragraph("Foo") + paragraph("Bar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
for assertion in assertions:
|
for assertion in assertions:
|
||||||
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == paragraph(assertions[assertion])
|
assert mistletoe.markdown(assertion, FiftyOhmHtmlRenderer) == assertions[assertion]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.latex
|
@pytest.mark.latex
|
||||||
|
|||||||
Reference in New Issue
Block a user