6

I need help getting a clue. I think my paltry experience compiling C code is a roadblock to understanding how to use some of the Raku modules for using the interface to the CommonMark C library to convert markdown to HTML.

Problem:

I'm on a mac with the cmark library installed with homebrew. I'm using the CommonMark module. It works, but if I have embedded html in my markdown, I get:

<!-- raw HTML omitted -->

in the output. AFAICT, CommonMark has an option for turning this on or off: https://github.com/commonmark/cmark/blob/8a023286198a7e408398e282f293e3b0baebb644/src/html.c#L171

The CommonMark module does not appear to allow me to pass argument to the cmark library. This module seems to: https://raku.land/github:JJ/cmark::Simple

However, I can't really make heads or tails of the documentation because I don't understand how to interface with the cmark library. And I'm not even sure if this module will work on a mac. This module seems to assume it should be installed on debian.

Can someone please clue me in?

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105
StevieD
  • 6,925
  • 2
  • 25
  • 45
  • 1
    I know nothing but what I've found as I poked around to see if I could help. This comment is installment #1. Per [the source for `.to-html`](https://github.com/drforr/perl6-CommonMark/blob/ab0d1c8bfb797c4fb3c9a07405370332420c00e4/lib/CommonMark.pm6#L737-L740) of the [CommonMark](https://github.com/drforr/perl6-CommonMark) Raku module, you would need to call it with an extra argument, type [`int32`](https://docs.raku.org/language/nativetypes#Types_with_native_representation_and_size), to pass options. That value is then passed on as is to the `C` cmark library. – raiph Apr 12 '22 at 18:51
  • 1
    Installment #2. Try `.to-html($input, 1 +< 17)`. (Because the C code you linked shows "" is output if `(!(options & CMARK_OPT_UNSAFE))`; the `options` is presumably the options value passed per "This comment is installment #1" above; you presumably need to pass an `int32` (Raku) / `int32_t` (C) value (let's call it `options`) such that (C code) `options & CMARK_OPT_UNSAFE` is *false*; [cmark.h](https://github.com/commonmark/cmark/blob/bf2be5954342b029afdc431040a9e5ad3d7e41e9/src/cmark.h#L571) shows `CMARK_OPT_UNSAFE` is `1 << 17` (C code) which is `1 +< 17` (Raku).) – raiph Apr 12 '22 at 19:50
  • 2
    Installment #3. ❶ Jeff Goff's Raku module `CommonMark` looks great to me. But it's had no updates since 2018 (Jeff sadly passed away). Since then cmark deprecated the safe constant, introducing the new unsafe one instead. (Maybe we add that new constant?) ❷ JJ's `cmark::Simple` shows no updates since 2020. But JJ is very active in the Raku community. ❸ khalidelboray's Raku module [cmark](https://github.com/khalidelboray/raku-cmark) also shows no updates since 2020 and "NOT COMPLETED". But khalidelboray has done great Raku work, clearly still cares about this module, and is highly active. – raiph Apr 12 '22 at 20:19
  • 1
    PS Even if `.to-html($input, 1 +< 17)` does *not* work, hopefully you've figured stuff out some other way and/or the info I've provided is enough to help you make progress. If instead what I've suggested *does* work, then maybe one of us can write up an answer to your SO with it in, and we can work toward figuring out what the best path forward for Rakoons is given that there are *three* packages that seem to be doing pretty much the same thing. Redundancy is fine, but it can still make sense to consider doing some simple rationalization so we're not unduly duplicating coding and doc, agreed? – raiph Apr 12 '22 at 20:29
  • 1
    @raiph, you've done it again! That worked. Thanks. Know any good search terms so I can look up a tutorial on this stuff so I can fix this knowledge gap of mine? And sorry to hear about Jeff. His work shall live on in mine. – StevieD Apr 12 '22 at 20:44
  • 1
    I think `CMARK_OPT_UNSAFE` is by far and away the most important. I think if you focus on making sense of that you'll cover most of the ground that's interesting. To be clear, I was literally unaware of these modules before reading your SO and know almost nothing about C other than what I've picked up by osmosis as a result of being a dev and Raku having NativeCall. What I do have is infinite (pathological) patience and trial-and-error chops when searching using SO, google, github, etc driven by the goal to find answers to Rakoons questions on SO. – raiph Apr 12 '22 at 23:46
  • I should probably update the documentation, and re-release late Jeff Goff's module. If you raise an issue in any, or both, of them, I'll try and fix it – jjmerelo Apr 19 '22 at 18:43
  • 1
    Created an issue https://github.com/JJ/raku-cmark/issues/2 – jjmerelo Apr 20 '22 at 10:46

0 Answers0