marktex.js
Advanced tools
Comparing version 0.3.1 to 0.3.2
export declare function escapeHTML(s: string): string; | ||
export declare function unescapeBackSlash(s: string): string; |
@@ -11,1 +11,20 @@ "use strict"; | ||
exports.escapeHTML = escapeHTML; | ||
const escapeChars = "\\`_*!#+-.[]{}()"; | ||
function unescapeBackSlash(s) { | ||
let res = "", q = 0, la = 'a'; | ||
for (let i = 0; i < s.length; i++) { | ||
if (la === '\\' && escapeChars.includes(s[i])) { | ||
res += s.slice(q, i - 1); | ||
q = i; | ||
la = 'a'; | ||
} | ||
else { | ||
la = s[i]; | ||
} | ||
} | ||
if (q < s.length) { | ||
return res + s.slice(q); | ||
} | ||
return res; | ||
} | ||
exports.unescapeBackSlash = unescapeBackSlash; |
@@ -159,8 +159,11 @@ "use strict"; | ||
let codeBlock = (el); | ||
if (codeBlock.language && this.highlight) { | ||
codeBlock.body = this.highlight(codeBlock.body, codeBlock.language); | ||
if (this.highlight) { | ||
codeBlock.body = this.highlight(codeBlock.body, codeBlock.language || ''); | ||
} | ||
else { | ||
codeBlock.body = escape_1.escapeHTML(codeBlock.body); | ||
} | ||
ctx.html += '<pre><code' + | ||
(codeBlock.language ? (' class="' + escape_1.escapeHTML(this.wrapCodeClassTag(codeBlock.language)) + '"') : '') + '>' + | ||
escape_1.escapeHTML((el).body) + '</code></pre>'; | ||
codeBlock.body + '</code></pre>'; | ||
} | ||
@@ -167,0 +170,0 @@ renderHTMLBlock(ctx, el) { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const token_1 = require("../token/token"); | ||
const escape_1 = require("../lib/escape"); | ||
// Standard Markdown Rules | ||
@@ -24,20 +25,2 @@ // https://daringfireball.net/projects/markdown/syntax | ||
// | ||
function unescapeBackSlash(s) { | ||
return s | ||
.replace(/\\\\/g, "\\") | ||
.replace(/\\`/g, "`") | ||
.replace(/\\\*/g, "*") | ||
.replace(/\\_/g, "_") | ||
.replace(/\\{/g, "{") | ||
.replace(/\\}/g, "}") | ||
.replace(/\\\[/g, "[") | ||
.replace(/\\]/g, "]") | ||
.replace(/\\\(/g, "(") | ||
.replace(/\\\)/g, ")") | ||
.replace(/\\#/g, "#") | ||
.replace(/\\\+/g, "+") | ||
.replace(/\\-/g, "-") | ||
.replace(/\\\./g, ".") | ||
.replace(/\\!/g, "!"); | ||
} | ||
class NewLineRule { | ||
@@ -191,3 +174,3 @@ constructor() { | ||
stream_1.forwardRegexp(s, capturing); | ||
return new token_1.LinkDefinition(unescapeBackSlash(capturing[1]), capturing[2], capturing[3]); | ||
return new token_1.LinkDefinition(escape_1.unescapeBackSlash(capturing[1]), capturing[2], capturing[3]); | ||
} | ||
@@ -340,3 +323,3 @@ ; | ||
this.description = "Standard Markdown Inline Rule"; | ||
this.regex = /^(?:\\[`_*\[$\\]|[^<`_*\[$\\])+/; | ||
this.regex = /^(?:\\[!`_*\[$\\]|[^<!`_*\[$\\])+/; | ||
} | ||
@@ -349,3 +332,3 @@ match(s, _) { | ||
stream_1.forwardRegexp(s, capturing); | ||
return new token_1.InlinePlain(unescapeBackSlash(capturing[0])); | ||
return new token_1.InlinePlain(escape_1.unescapeBackSlash(capturing[0])); | ||
} | ||
@@ -359,3 +342,3 @@ ; | ||
this.description = "Standard Markdown Inline Rule"; | ||
this.regex = /^(?:[<`_*\[$\\](?:\\[`_*\[$\\]|[^<`_*\[$\\])*|(?:\\[`_*\[$\\]|[^<`_*\[$\\])+)/; | ||
this.regex = /^(?:[!`_*\[$\\<](?:\\[!`_*\[$\\]|[^<!`_*\[$\\])*|(?:\\[!`_*\[$\\]|[^<!`_*\[$\\])+)/; | ||
} | ||
@@ -368,3 +351,3 @@ match(s, _) { | ||
stream_1.forwardRegexp(s, capturing); | ||
return new token_1.InlinePlain(unescapeBackSlash(capturing[0])); | ||
return new token_1.InlinePlain(escape_1.unescapeBackSlash(capturing[0])); | ||
} | ||
@@ -393,6 +376,6 @@ ; | ||
if (capturing[1] !== '') { | ||
return new token_1.ImageLink(unescapeBackSlash(capturing[2]), capturing[3], true, capturing[4]); | ||
return new token_1.ImageLink(escape_1.unescapeBackSlash(capturing[2]), capturing[3], true, capturing[4]); | ||
} | ||
else { | ||
return new token_1.Link(unescapeBackSlash(capturing[2]), capturing[3], true, capturing[4]); | ||
return new token_1.Link(escape_1.unescapeBackSlash(capturing[2]), capturing[3], true, capturing[4]); | ||
} | ||
@@ -443,3 +426,3 @@ } | ||
s.forward(capturing[0].length - 1); | ||
return new token_1.Emphasis(unescapeBackSlash(capturing[2] || capturing[5]), l.length); | ||
return new token_1.Emphasis(escape_1.unescapeBackSlash(capturing[2] || capturing[5]), l.length); | ||
} | ||
@@ -449,3 +432,3 @@ return undefined; | ||
stream_1.forwardRegexp(s, capturing); | ||
return new token_1.Emphasis(unescapeBackSlash(capturing[2] || capturing[5]), l.length); | ||
return new token_1.Emphasis(escape_1.unescapeBackSlash(capturing[2] || capturing[5]), l.length); | ||
} | ||
@@ -467,3 +450,3 @@ ; | ||
stream_1.forwardRegexp(s, capturing); | ||
return new token_1.InlineCode(unescapeBackSlash(capturing[1] || capturing[2])); | ||
return new token_1.InlineCode(escape_1.unescapeBackSlash(capturing[1] || capturing[2])); | ||
} | ||
@@ -470,0 +453,0 @@ ; |
{ | ||
"name": "marktex.js", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "markdown parser", | ||
@@ -11,2 +11,3 @@ "main": "dist/index.js", | ||
"exec": "tsc && node dist/index.js", | ||
"prepublish": "yarn run build", | ||
"t": "./node_modules/.bin/mocha.cmd --reporter spec --require ts-node/register", | ||
@@ -13,0 +14,0 @@ "b": "./node_modules/.bin/mocha.cmd --prof --reporter spec --require ts-node/register", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
400193
59
8065
1