@bonniernews/md2html
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -36,10 +36,17 @@ "use strict"; | ||
indentation = 0, | ||
previousIndentation = 0; | ||
previousIndentation = 0, | ||
blockIndex = -1; | ||
for (let idx = 0; idx <= len; ++idx) { | ||
++blockIndex; | ||
charcode = markdown.charCodeAt(idx); | ||
if (charcode == CHARS.NEW_LINE || charcode == CHARS.CARRIAGE_RETURN) { | ||
blockIndex = -1; | ||
let lookahead = markdown.charCodeAt(idx + 1); | ||
if (lookahead == CHARS.NEW_LINE || lookahead == CHARS.CARRIAGE_RETURN) continue; | ||
if (lookahead == CHARS.NEW_LINE || lookahead == CHARS.CARRIAGE_RETURN) { | ||
continue; | ||
} | ||
previousIndentation = indentation; | ||
@@ -75,3 +82,6 @@ indentation = 0; | ||
if (!nstate || (nstate & NSTATE.FLOWCONTENT) == NSTATE.FLOWCONTENT) continue; | ||
if (!nstate || (nstate & NSTATE.FLOWCONTENT) == NSTATE.FLOWCONTENT) { | ||
continue; | ||
} | ||
nstate = undefined; | ||
@@ -91,5 +101,4 @@ const lastState = state.pop(); | ||
let size = 1, | ||
valid; | ||
let offset; | ||
let size = 1; | ||
let offset, valid; | ||
@@ -129,3 +138,6 @@ for (offset = idx + 1; offset < len; ++offset) { | ||
continue; | ||
} else if (markdown.charCodeAt(idx + 1) !== CHARS.SPACE) { | ||
} else if (blockIndex != 0) { | ||
markup += "-"; | ||
continue; | ||
} else if (markdown.charCodeAt(idx + 1) != CHARS.SPACE) { | ||
nstate = NSTATE.PHRASINGCONTENT; | ||
@@ -259,5 +271,4 @@ markup += "<p>"; | ||
} else if (charcode == CHARS.ENDBRACKET) { | ||
let link = "", | ||
valid; | ||
let offset; | ||
let link = ""; | ||
let offset, valid; | ||
@@ -264,0 +275,0 @@ for (offset = idx + 1; offset < len; ++offset) { |
51
index.js
@@ -29,10 +29,17 @@ export function render(markdown) { | ||
const len = markdown.length - 1; | ||
let nstate, charcode, indentation = 0, previousIndentation = 0; | ||
let nstate, | ||
charcode, | ||
indentation = 0, | ||
previousIndentation = 0, | ||
blockIndex = -1; | ||
for (let idx = 0; idx <= len; ++idx) { | ||
++blockIndex; | ||
charcode = markdown.charCodeAt(idx); | ||
if (charcode == CHARS.NEW_LINE || charcode == CHARS.CARRIAGE_RETURN) { | ||
blockIndex = -1; | ||
let lookahead = markdown.charCodeAt(idx + 1); | ||
if (lookahead == CHARS.NEW_LINE || lookahead == CHARS.CARRIAGE_RETURN) continue; | ||
if (lookahead == CHARS.NEW_LINE || lookahead == CHARS.CARRIAGE_RETURN) { | ||
continue; | ||
} | ||
@@ -64,3 +71,5 @@ previousIndentation = indentation; | ||
if (!nstate || (nstate & NSTATE.FLOWCONTENT) == NSTATE.FLOWCONTENT) continue; | ||
if (!nstate || (nstate & NSTATE.FLOWCONTENT) == NSTATE.FLOWCONTENT) { | ||
continue; | ||
} | ||
@@ -75,3 +84,4 @@ nstate = undefined; | ||
continue; | ||
} else if (charcode == CHARS.HASH) { // # | ||
} else if (charcode == CHARS.HASH) { | ||
// # | ||
if (nstate && (nstate & NSTATE.FLOWCONTENT) == 0) { | ||
@@ -82,4 +92,4 @@ markup += "#"; | ||
let size = 1, valid; | ||
let offset; | ||
let size = 1; | ||
let offset, valid; | ||
for (offset = idx + 1; offset < len; ++offset) { | ||
@@ -118,3 +128,6 @@ const lookahead = markdown.charCodeAt(offset); | ||
continue; | ||
} else if (markdown.charCodeAt(idx + 1) !== CHARS.SPACE) { | ||
} else if (blockIndex != 0) { | ||
markup += "-"; | ||
continue; | ||
} else if (markdown.charCodeAt(idx + 1) != CHARS.SPACE) { | ||
nstate = NSTATE.PHRASINGCONTENT; | ||
@@ -132,6 +145,8 @@ markup += "<p>"; | ||
markup += state.pop(); | ||
} else if (indentation > previousIndentation) { // start sublist | ||
} else if (indentation > previousIndentation) { | ||
// start sublist | ||
markup += "<ul>"; | ||
state.push("</ul>"); | ||
} else if (indentation < previousIndentation) { // close sublist | ||
} else if (indentation < previousIndentation) { | ||
// close sublist | ||
markup += state.pop(); // close last item | ||
@@ -141,3 +156,4 @@ markup += state.pop(); // close sublist | ||
} | ||
} else { // start new list | ||
} else { | ||
// start new list | ||
markup += "<ul>"; | ||
@@ -185,3 +201,5 @@ state.push("</ul>"); | ||
const src = {value: "", charsOnly: true}, alt = {value: ""}, title = {value: ""}; | ||
const src = { value: "", charsOnly: true, }, | ||
alt = { value: "", }, | ||
title = { value: "", }; | ||
let offset; | ||
@@ -217,3 +235,2 @@ let attr = alt; | ||
markup += "<img src=\"" + src.value + "\""; | ||
@@ -239,4 +256,4 @@ if (alt.value) { | ||
} else if (charcode == CHARS.ENDBRACKET) { | ||
let link = "", valid; | ||
let offset; | ||
let link = ""; | ||
let offset, valid; | ||
for (offset = idx + 1; offset < len; ++offset) { | ||
@@ -260,3 +277,5 @@ const lookahead = markdown.charCodeAt(offset); | ||
markup = markup.replace("<a href=\"#link\">", "<a href=\"" + link + "\">") + state.pop(); | ||
markup = | ||
markup.replace("<a href=\"#link\">", "<a href=\"" + link + "\">") + | ||
state.pop(); | ||
@@ -263,0 +282,0 @@ continue; |
{ | ||
"name": "@bonniernews/md2html", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Zero dependency markdown to html converter", | ||
@@ -5,0 +5,0 @@ "module": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17497
503