+ def test_markdown_inline_image_processor_base64(self, test_png):
+ text = f"![1px white inlined]({test_png})"
+ text, html, images = markdown_with_inline_image_support(text)
+
+ assert 'src="cid:' in html
+ assert "](cid:" in text
+ assert len(images) == 1
+ assert test_png in images
+
+ def test_converter_tree_inline_image_base64(
+ self, test_png, const1, fake_filewriter
+ ):
+ text = f"![inline base64 image]({test_png})"
+ path = pathlib.Path(const1)
+ tree = convert_markdown_to_html(
+ text,
+ path,
+ filewriter_fn=fake_filewriter,
+ related_to_html_only=False,
+ )
+ assert tree.subtype == "relative"
+ assert tree.children[0].subtype == "alternative"
+ assert tree.children[1].subtype == "png"
+ written = fake_filewriter.pop()
+ assert tree.children[1].path == written[0]
+ assert written[1] == request.urlopen(test_png).read()
+
+ def test_converter_tree_inline_image_base64_related_to_html(
+ self, test_png, const1, fake_filewriter
+ ):
+ text = f"![inline base64 image]({test_png})"
+ path = pathlib.Path(const1)
+ tree = convert_markdown_to_html(
+ text,
+ path,
+ filewriter_fn=fake_filewriter,
+ related_to_html_only=True,
+ )
+ assert tree.subtype == "alternative"
+ assert tree.children[1].subtype == "relative"
+ assert tree.children[1].children[1].subtype == "png"
+ written = fake_filewriter.pop()
+ assert tree.children[1].children[1].path == written[0]
+ assert written[1] == request.urlopen(test_png).read()
+
+ def test_converter_tree_inline_image_cid(
+ self, const1, fake_filewriter
+ ):
+ text = f"![inline base64 image](cid:{const1})"
+ path = pathlib.Path(const1)
+ tree = convert_markdown_to_html(
+ text,
+ path,
+ filewriter_fn=fake_filewriter,
+ related_to_html_only=False,
+ )
+ assert len(tree.children) == 2
+ assert tree.children[0].cid != const1
+ assert tree.children[0].type != "image"
+ assert tree.children[1].cid != const1
+ assert tree.children[1].type != "image"
+
+ def test_inline_image_collection(
+ self, test_png, const1, const2, fake_filewriter
+ ):
+ test_images = {test_png: InlineImageInfo(cid=const1, desc=const2)}
+ relparts = collect_inline_images(
+ test_images, filewriter_fn=fake_filewriter
+ )
+
+ written = fake_filewriter.pop()
+ assert b"PNG" in written[1]
+
+ assert relparts[0].subtype == "png"
+ assert relparts[0].path == written[0]
+ assert relparts[0].cid == const1
+ assert relparts[0].desc.endswith(const2)
+
+ def test_apply_stylesheet(self):
+ if _PYNLINER:
+ html = "<p>Hello, world!</p>"
+ css = "p { color:red }"
+ out = apply_styling(html, css)
+ assert 'p style="color' in out
+
+ def test_apply_stylesheet_pygments(self):
+ if _PYGMENTS_CSS:
+ html = (
+ f'<div class="{_CODEHILITE_CLASS}">'
+ "<pre>def foo():\n return</pre></div>"
+ )
+ out = apply_styling(html, _PYGMENTS_CSS)
+ assert f'{_CODEHILITE_CLASS}" style="' in out
+
+ def test_mime_tree_relative_within_alternative(
+ self, string_io, const1, capsys, mime_tree_related_to_html
+ ):
+ def converter(
+ drafttext,
+ draftpath,
+ cssfile,
+ related_to_html_only,
+ extensions,
+ tempdir,
+ ):
+ return mime_tree_related_to_html
+
+ do_massage(
+ draft_f=string_io,
+ draftpath=const1,
+ cmd_f=sys.stdout,
+ converter=converter,
+ )