badboy / mdbook-toc

A preprocessor for mdbook to add inline Table of Contents support.
Mozilla Public License 2.0
163 stars 20 forks source link

Tables with column ending with HTML tag aren't rendered right #19

Closed syvb closed 2 years ago

syvb commented 3 years ago

Enable mdbook-toc in the book.toml, then put this into a page:

a | b
--|--
<span>a</span> | b

produces a and b are on two different rows The table should be one row, not two rows with one column per row. This only happens when this extension is used, which is odd because this doesn't use any of the extension's features.

badboy commented 3 years ago

I think this might be yet another instance of a roundtripping bug in pulldown-cmark-to-cmark really. Here's a test case for mdbook-toc we can add when we get that fixed:

diff --git tests/it.rs tests/it.rs
index 6f257e4..4c6b350 100644
--- tests/it.rs
+++ tests/it.rs
@@ -145,3 +145,8 @@ fn similar_heading_different_casing() {

     assert_toc!("similar_heading_different_casing");
 }
+
+#[test]
+fn tables_with_html() {
+    assert_toc!("tables_with_html");
+}
diff --git tests/tables_with_html.in.md tests/tables_with_html.in.md
new file mode 100644
index 0000000..9f13052
--- /dev/null
+++ tests/tables_with_html.in.md
@@ -0,0 +1,5 @@
+# Heading
+
+| Head 1 | Head 2 |
+|--------|--------|
+| <span>Row 1</span> | Row 2  |
diff --git tests/tables_with_html.out.md tests/tables_with_html.out.md
new file mode 100644
index 0000000..97e5b03
--- /dev/null
+++ tests/tables_with_html.out.md
@@ -0,0 +1,5 @@
+# Heading
+
+|Head 1|Head 2|
+|------|------|
+|<span>Row 1</span>|Row 2|

It currently faills because an extra newline is added:

---- tables_with_html stdout ----
thread 'tables_with_html' panicked at 'assertion failed: `(left == right)`

Diff < left / right > :
<"# Heading\n\n|Head 1|Head 2|\n|------|------|\n|<span>Row 1</span>|Row 2|"
>"# Heading\n\n|Head 1|Head 2|\n|------|------|\n|<span>Row 1</span>\n|Row 2|"