Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Dec 19, 2024
1 parent fc8115d commit 530c9fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
5 changes: 0 additions & 5 deletions rednotebook/util/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
ESCAPE_COLOR = r"XBEGINCOLORX\1XSEPARATORX\2XENDCOLORX"
COLOR_ESCAPED = r"XBEGINCOLORX(.*?)XSEPARATORX(.*?)XENDCOLORX"

CHARSET_UTF8 = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'

CSS = """\
<style type="text/css">
:root {
Expand Down Expand Up @@ -211,9 +209,6 @@ def _get_config(target, options):
config["toc"] = 0
config["css-sugar"] = 1

# Fix encoding for export opened in firefox
config["postproc"].append([r"<head>", f"<head>{CHARSET_UTF8}"])

# Line breaks
config["postproc"].append([r"LINEBREAK", "<br />"])

Expand Down
10 changes: 9 additions & 1 deletion rednotebook/util/pango_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ def convert_to_pango(txt, headers=None, options=None):
result = txt2tags.getUnknownErrorMessage()
logging.error(result)

print(result)

# remove unwanted paragraphs
result = result.replace("<p>", "").replace("</p>", "")
result = result.replace('<div class="body"><p>', "").replace("</p></div>", "")

logging.log(
5,
Expand All @@ -73,6 +75,12 @@ def replace_links(match):
return match.group(1)

result = re.sub(REGEX_HTML_LINK, replace_links, result)
print(result)

for new_tag, old_tag in [("del", "s"), ("em", "i"), ("strong", "b")]:
result = result.replace(f"<{new_tag}>", f"<{old_tag}>")
result = result.replace(f"</{new_tag}>", f"</{old_tag}>")
print(result)

try:
Pango.parse_markup(result, -1, "0")
Expand Down
33 changes: 13 additions & 20 deletions tests/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,15 @@ def process(markup):

def test_encoding(self, process):
document = process("Content")
assert ' encoding="UTF-8"' in document

def test_firefox_encoding_bug(self, process):
document = process("Content")
assert (
'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
in document
)
assert '<meta charset="utf-8">' in document

def test_toc(self, process):
document = process("Content")
assert '<div class="toc">' not in document

def test_css_sugar(self, process):
document = process("Content")
assert '<div class="body" id="body">' in document
assert '<div class="body">' in document

@pytest.mark.parametrize(
"markup,expected",
Expand Down Expand Up @@ -139,31 +132,31 @@ def test_colors(self, markup, expected, process):
[
(
'[""/image"".png?50]',
'<img align="middle" width="50" src="/image.png" border="0" alt=""/>',
'<img class="center" width="50" src="/image.png" alt="">',
),
(
'[""/image"".jpg?50]',
'<img align="middle" width="50" src="/image.jpg" border="0" alt=""/>',
'<img class="center" width="50" src="/image.jpg" alt="">',
),
(
'[""/image"".jpeg?50]',
'<img align="middle" width="50" src="/image.jpeg" border="0" alt=""/>',
'<img class="center" width="50" src="/image.jpeg" alt="">',
),
(
'[""/image"".gif?50]',
'<img align="middle" width="50" src="/image.gif" border="0" alt=""/>',
'<img class="center" width="50" src="/image.gif" alt="">',
),
(
'[""/image"".eps?50]',
'<img align="middle" width="50" src="/image.eps" border="0" alt=""/>',
'<img class="center" width="50" src="/image.eps" alt="">',
),
(
'[""/image"".bmp?50]',
'<img align="middle" width="50" src="/image.bmp" border="0" alt=""/>',
'<img class="center" width="50" src="/image.bmp" alt="">',
),
(
'[""/image"".svg?50]',
'<img align="middle" width="50" src="/image.svg" border="0" alt=""/>',
'<img class="center" width="50" src="/image.svg" alt="">',
),
],
)
Expand All @@ -176,19 +169,19 @@ def test_images_resize_allowed_extensions(self, markup, expected, process):
[
(
'[""/image"".png?50]',
'<img align="middle" width="50" src="/image.png" border="0" alt=""/>',
'<img class="center" width="50" src="/image.png" alt="">',
),
(
'[""/image"".jpg]',
'<img align="middle" src="/image.jpg" border="0" alt=""/>',
'<img class="center" src="/image.jpg" alt="">',
),
(
'[""file:///image"".png?10]',
'<img align="middle" width="10" src="file:///image.png" border="0" alt=""/>',
'<img class="center" width="10" src="file:///image.png" alt="">',
),
(
'[""file:///image"".jpg]',
'<img align="middle" ' 'src="file:///image.jpg" border="0" ' 'alt=""/>',
'<img class="center" src="file:///image.jpg" alt="">',
),
],
)
Expand Down

0 comments on commit 530c9fd

Please sign in to comment.