diff --git a/example/example.html b/example/example.html index e46b151..7ecb278 100644 --- a/example/example.html +++ b/example/example.html @@ -79,3 +79,4 @@
"); break;
case MD_SPAN_DEL: render_literal(r, ""); break;
case MD_SPAN_LATEXMATH: render_literal(r, ""); break;
@@ -452,12 +465,12 @@ static int text_callback(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, vo
render_literal(
r,
r->imgnest == 0 ?
- ((r->flags & MD_HTML_FLAG_XHTML) ? "
\n" : "
\n") :
+ ((r->flags & OutputFlagXHTML) ? "
\n" : "
\n") :
" "
);
break;
- render_literal(r, (r->flags & MD_HTML_FLAG_XHTML) ? "
\n" : "
\n"); break;
+ render_literal(r, (r->flags & OutputFlagXHTML) ? "
\n" : "
\n"); break;
case MD_TEXT_SOFTBR: render_literal(r, (r->imgnest == 0 ? "\n" : " ")); break;
case MD_TEXT_HTML: render_text(r, text, size); break;
diff --git a/src/fmt_html.h b/src/fmt_html.h
index a903981..cfe8215 100644
--- a/src/fmt_html.h
+++ b/src/fmt_html.h
@@ -1,11 +1,9 @@
#pragma once
-#define MD_HTML_FLAG_XHTML 0x0008 // instead of e.g.
, generate
-
typedef struct FmtHTML {
- u32 flags; // MD_HTML_FLAG_*
- u32 parserFlags; // passed along to md_parse
- WBuf* outbuf;
+ OutputFlags flags;
+ u32 parserFlags; // passed along to md_parse
+ WBuf* outbuf;
// optional callbacks
JSTextFilterFun onCodeBlock;
diff --git a/src/md.c b/src/md.c
index b0c6225..f17f8cc 100644
--- a/src/md.c
+++ b/src/md.c
@@ -4,12 +4,6 @@
#include "fmt_html.h"
// #include "fmt_json.h"
-// these should be in sync with "OutputFlags" in md.js
-typedef enum OutputFlags {
- OutputFlagHTML = 1 << 0,
- OutputFlagXHTML = 1 << 1,
-} OutputFlags;
-
typedef enum ErrorCode {
ERR_NONE,
ERR_MD_PARSE,
@@ -41,19 +35,16 @@ export size_t parseUTF8(
WBufReset(&outbuf);
- if (outflags & OutputFlagHTML) {
+ if ((outflags & OutputFlagHTML) || (outflags & OutputFlagXHTML)) {
WBufReserve(&outbuf, inbuflen * 2); // approximate output size to minimize reallocations
FmtHTML fmt = {
- .flags = 0,
+ .flags = outflags,
.parserFlags = parser_flags,
.outbuf = &outbuf,
.onCodeBlock = onCodeBlock,
};
- if (outflags & OutputFlagXHTML)
- fmt.flags |= MD_HTML_FLAG_XHTML;
-
if (fmt_html(inbufptr, inbuflen, &fmt) != 0) {
// fmt_html returns status of md_parse which only fails in extreme cases
// like when out of memory. md4c does not provide error codes or error messages.
diff --git a/src/md.js b/src/md.js
index c5d05cd..c85a52f 100644
--- a/src/md.js
+++ b/src/md.js
@@ -41,10 +41,11 @@ export const ParseFlags = {
NO_HTML: 0x0020 | 0x0040, // NO_HTML_BLOCKS | NO_HTML_SPANS
}
-// these should be in sync with "OutputFlags" in md.c
+// these should be in sync with "OutputFlags" in common.h
const OutputFlags = {
- HTML: 1 << 0, // Output HTML
- XHTML: 1 << 1, // Output XHTML (only has effect with HTML flag set)
+ HTML: 1 << 0, // Output HTML
+ XHTML: 1 << 1, // Output XHTML (only has effect with HTML flag set)
+ AllowJSURI: 1 << 2, // Allow "javascript:" URIs
}
@@ -56,7 +57,8 @@ export function parse(source, options) {
options.parseFlags
)
- let outputFlags = 0
+ let outputFlags = options.allowJSURIs ? OutputFlags.AllowJSURI : 0
+
switch (options.format) {
case "xhtml":
outputFlags |= OutputFlags.HTML | OutputFlags.XHTML