commonmark/cmark

Make `CMARK_OPT_UNSAFE` settable during runtime

Closed this issue · 4 comments

hinell commented

Hi. I'm linking against library and would like to be able to set CMARK_OPT_UNSAFE via method options,

Currently it's respected only during compile time and in cli binary.

Thanks!

Currently it's respected only during compile time and in cli binary, which.

This isn't true. CMARK_OPT_UNSAFE can be passed to several API functions at runtime.

hinell commented

@nwellnhof No doubt about that but is there any way oen can pass it to the ... cmark_markdown_to_html(...) call? Thanks.

Here's the declaration of cmark_markdown_to_html:

char *cmark_markdown_to_html(const char *text, size_t len, int options);

Just pass CMARK_OPT_UNSAFE, maybe ORed with other flags, as options argument.

hinell commented

@nwellnhof Sorry, didn't notice the definitions. They are buried below, which is kinda surprising:

cmark/src/cmark.h

Lines 545 to 571 in 7195c67

#define CMARK_OPT_DEFAULT 0
/**
* ### Options affecting rendering
*/
/** Include a `data-sourcepos` attribute on all block elements.
*/
#define CMARK_OPT_SOURCEPOS (1 << 1)
/** Render `softbreak` elements as hard line breaks.
*/
#define CMARK_OPT_HARDBREAKS (1 << 2)
/** `CMARK_OPT_SAFE` is defined here for API compatibility,
but it no longer has any effect. "Safe" mode is now the default:
set `CMARK_OPT_UNSAFE` to disable it.
*/
#define CMARK_OPT_SAFE (1 << 3)
/** Render raw HTML and unsafe links (`javascript:`, `vbscript:`,
* `file:`, and `data:`, except for `image/png`, `image/gif`,
* `image/jpeg`, or `image/webp` mime types). By default,
* raw HTML is replaced by a placeholder HTML comment. Unsafe
* links are replaced by empty strings.
*/
#define CMARK_OPT_UNSAFE (1 << 17)

Thanks!