Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C code crashes when rendering strikethrough #29

Open
brandonchinn178 opened this issue Feb 5, 2023 · 1 comment
Open

C code crashes when rendering strikethrough #29

brandonchinn178 opened this issue Feb 5, 2023 · 1 comment

Comments

@brandonchinn178
Copy link

This works:

commonmarkToHtml [] [extStrikethrough] "a ~b~ c"

But this fails:

nodeToHtml [] [extStrikethrough] $ commonmarkToNode [] [extStrikethrough] "a ~b~ c"
Assertion failed: (false), function S_render_node, file html.c, line 445.
@brandonchinn178 brandonchinn178 changed the title Strike through fails going through Node C code crashes when rendering strikethrough Feb 5, 2023
@kivikakk
Copy link
Owner

kivikakk commented Feb 6, 2023

We need to use the cmark_node_new_with_ext variant to create the strikethrough node. I have the start of something here:

diff --git a/CMarkGFM.hsc b/CMarkGFM.hsc
index db2a194..103aee4 100644
--- a/CMarkGFM.hsc
+++ b/CMarkGFM.hsc
@@ -500,7 +500,10 @@ fromNode (Node _ nodeType children) = do
                      return n
             SOFTBREAK   -> c_cmark_node_new (#const CMARK_NODE_SOFTBREAK)
             LINEBREAK   -> c_cmark_node_new (#const CMARK_NODE_LINEBREAK)
-            STRIKETHROUGH -> c_cmark_node_new (fromIntegral . Unsafe.unsafePerformIO $ peek c_CMARK_NODE_STRIKETHROUGH)
+            STRIKETHROUGH -> do
+                     [ext] <- resolveExts [extStrikethrough]
+                     nodeType <- fromIntegral <$> peek c_CMARK_NODE_STRIKETHROUGH
+                     c_cmark_node_new_with_ext nodeType ext
             TABLE _             -> error "constructing table not supported"
             TABLE_ROW           -> error "constructing table row not supported"
             TABLE_CELL          -> error "constructing table cell not supported"
@@ -525,6 +528,9 @@ foreign import ccall "string.h strlen"
 foreign import ccall "cmark-gfm.h cmark_node_new"
     c_cmark_node_new :: Int -> IO NodePtr
 
+foreign import ccall "cmark-gfm.h cmark_node_new_with_ext"
+    c_cmark_node_new_with_ext :: Int -> ExtensionPtr -> IO NodePtr
+
 foreign import ccall "cmark-gfm.h cmark_render_html"
     c_cmark_render_html :: NodePtr -> CInt -> LlistPtr ExtensionPtr -> IO CString
 
diff --git a/test/test-cmark.hs b/test/test-cmark.hs
index 6f53c3a..bdb3333 100644
--- a/test/test-cmark.hs
+++ b/test/test-cmark.hs
@@ -34,5 +34,6 @@ tests = TestList [
   , "&lt;xmp>\n" ~=? commonmarkToHtml [optUnsafe] [extTagfilter] "<xmp>"
   , "<ul>\n<li><input type=\"checkbox\" disabled=\"\" /> foo</li>\n<li><input type=\"checkbox\" checked=\"\" disabled=\"\" /> bar</li>\n</ul>\n" ~=? commonmarkToHtml [] [extTaskList] "- [ ] foo\n- [x] bar"
   , "<p>Here is footnote<sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n<section class=\"footnotes\" data-footnotes>\n<ol>\n<li id=\"fn-1\">\n<p>abc <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n</li>\n</ol>\n</section>\n" ~=? commonmarkToHtml [optFootnotes] [] "Here is footnote[^1]\n\n[^1]: abc"
+  , "<p>lol</p>" ~=? nodeToHtml [] [extStrikethrough] $ commonmarkToNode [] [extStrikethrough] "a ~b~ c"
   ]
 

Unfortunately I haven't the time to get a development environment for this setup again presently, so I leave this open to a contributor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants