Cmark
Cmark
DESCRIPTION
A Raku binding (NOT COMPLETED) to the C lib cmark trying
INSTALL
install cmark lib
linux
git clone https://github.com/commonmark/cmark.git
cd cmark && make && make test && make install
windows
i recommend using vcpkg
vcpkg install cmarkadd the bin dir in the vcpkg packages dir to your ENV PATH. will look like that
whatever\vcpkg\packages\cmark_x64-windows\bin
install the module
zef
zef install Cmark
from source
git clone https://github.com/khalidelboray/raku-cmark.gitcd cmarkzef install .
Example
use Cmark;
my $options = CMARK_OPT_UNSAFE +| CMARK_OPT_SOURCEPOS ;
my $doc = Cmark.parse("# Header [hello](javascript:alert(1))",$options);
say $doc.to-html(); # <h1 data-sourcepos="1:1-1:37">Header <a href="javascript:alert(1)">hello</a></h1>Class Cmark Methods
multi method parse
multi method parse( Str $md, $options = 0 ) returns Cmarktakes the markdown as a Str and the parser options
multi method parse
multi method parse( IO $md, $options = 0 ) returns Cmarktakes the markdown file and passes it's content to the previous one
version
method version ()returns the cmark vserion string
OPTIONS
enum OPTIONS is export (
CMARK_OPT_DEFAULT => 0,
CMARK_OPT_SOURCEPOS => 1 +< 1,
CMARK_OPT_HARDBREAKS => 1 +< 2,
CMARK_OPT_SAFE => 1 +< 3,
CMARK_OPT_UNSAFE => 1 +< 17,
CMARK_OPT_NOBREAKS => 1 +< 4,
CMARK_OPT_NORMALIZE => 1 +< 8,
CMARK_OPT_VALIDATE_UTF8 => 1 +< 9 ,
CMARK_OPT_SMART => 1 +< 10
);CMARK_OPT_DEFAULTDefault options.
CMARK_OPT_SOURCEPOSInclude a
data-sourceposattribute on all block elements.CMARK_OPT_HARDBREAKSRender
softbreakelements as hard line breaks.CMARK_OPT_SAFECMARK_OPT_SAFEis defined here for API compatibility, but it no longer has any effect. "Safe" mode is now the default: setCMARK_OPT_UNSAFEto disable it.CMARK_OPT_UNSAFERender raw HTML and unsafe links (
javascript:,vbscript:,file:, anddata:, except forimage/png,image/gif,image/jpeg, orimage/webpmime types). By default, raw HTML is replaced by a placeholder HTML comment. Unsafe links are replaced by empty strings.CMARK_OPT_NOBREAKSRender
softbreakelements as spaces.CMARK_OPT_NORMALIZELegacy option (no effect).
CMARK_OPT_VALIDATE_UTF8Validate UTF-8 in the input before parsing, replacing illegal sequences with the replacement character U+FFFD.
CMARK_OPT_SMARTConvert straight quotes to curly, to em dashes, - to en dashes.
Doc Methods
to-html
method to-html ( $options = $!options )Converts the parsed Markdown to html given the options (defaults to the options used with parse)
to-xml
method to-xml ( $options = $!options )Converts the parsed Markdown to xml given the options (defaults to the options used with parse)
to-man
method to-man ( $options = $!options, :$width = 0 )Converts the parsed Markdown to man given the options (defaults to the options used with parse) and width
to-commonmark
method to-commonmark ( $options = $!options, :$width = 0 )Converts the parsed Markdown to commnmark given the options (defaults to the options used with parse) and width
to-latex
method to-latex ( $options = $!options, :$width = 0 )Converts the parsed Markdown to latex given the options (defaults to the options used with parse) and width
TODO
Add more tests
Full binding
Docs