DEV: Apply prettier

This commit is contained in:
David Taylor 2018-10-22 19:49:32 +01:00
parent d53c0bad11
commit 199c8387a1
1 changed files with 43 additions and 33 deletions

View File

@ -24,11 +24,14 @@ function isSafeBoundary(character_code, delimiter_code, md) {
} }
function math_input(state, silent, delimiter_code) { function math_input(state, silent, delimiter_code) {
let pos = state.pos, let pos = state.pos,
posMax = state.posMax; posMax = state.posMax;
if (silent || state.src.charCodeAt(pos) !== delimiter_code || posMax < pos+2) { if (
silent ||
state.src.charCodeAt(pos) !== delimiter_code ||
posMax < pos + 2
) {
return false; return false;
} }
@ -44,7 +47,6 @@ function math_input(state, silent, delimiter_code) {
} }
} }
let found; let found;
for (let i = pos + 1; i < posMax; i++) { for (let i = pos + 1; i < posMax; i++) {
let code = state.src.charCodeAt(i); let code = state.src.charCodeAt(i);
@ -65,8 +67,8 @@ function math_input(state, silent, delimiter_code) {
} }
} }
let data = (state.src.slice(pos+1,found)); let data = state.src.slice(pos + 1, found);
let token = state.push('html_raw', '', 0); let token = state.push("html_raw", "", 0);
const escaped = state.md.utils.escapeHtml(data); const escaped = state.md.utils.escapeHtml(data);
let math_class = delimiter_code === 36 ? "'math'" : "'asciimath'"; let math_class = delimiter_code === 36 ? "'math'" : "'asciimath'";
@ -76,15 +78,14 @@ function math_input(state, silent, delimiter_code) {
} }
function inlineMath(state, silent) { function inlineMath(state, silent) {
return math_input(state, silent, 36 /* $ */) return math_input(state, silent, 36 /* $ */);
} }
function asciiMath(state, silent) { function asciiMath(state, silent) {
return math_input(state, silent, 37 /* % */) return math_input(state, silent, 37 /* % */);
} }
function isBlockMarker(state, start, max, md) { function isBlockMarker(state, start, max, md) {
if (state.src.charCodeAt(start) !== 36 /* $ */) { if (state.src.charCodeAt(start) !== 36 /* $ */) {
return false; return false;
} }
@ -108,16 +109,16 @@ function isBlockMarker(state, start, max, md) {
} }
function blockMath(state, startLine, endLine, silent) { function blockMath(state, startLine, endLine, silent) {
let let start = state.bMarks[startLine] + state.tShift[startLine],
start = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine]; max = state.eMarks[startLine];
if (!isBlockMarker(state, start, max, state.md)) { if (!isBlockMarker(state, start, max, state.md)) {
return false; return false;
} }
if (silent) { return true; } if (silent) {
return true;
}
let nextLine = startLine; let nextLine = startLine;
let closed = false; let closed = false;
@ -129,16 +130,26 @@ function blockMath(state, startLine, endLine, silent){
break; break;
} }
if (isBlockMarker(state, state.bMarks[nextLine] + state.tShift[nextLine], state.eMarks[nextLine], state.md)) { if (
isBlockMarker(
state,
state.bMarks[nextLine] + state.tShift[nextLine],
state.eMarks[nextLine],
state.md
)
) {
closed = true; closed = true;
break; break;
} }
} }
let token = state.push('html_raw', '', 0); let token = state.push("html_raw", "", 0);
let endContent = closed ? state.eMarks[nextLine - 1] : state.eMarks[nextLine]; let endContent = closed ? state.eMarks[nextLine - 1] : state.eMarks[nextLine];
let content = state.src.slice(state.bMarks[startLine+1] + state.tShift[startLine+1], endContent); let content = state.src.slice(
state.bMarks[startLine + 1] + state.tShift[startLine + 1],
endContent
);
const escaped = state.md.utils.escapeHtml(content); const escaped = state.md.utils.escapeHtml(content);
token.content = `<div class='math'>\n${escaped}\n</div>\n`; token.content = `<div class='math'>\n${escaped}\n</div>\n`;
@ -149,7 +160,6 @@ function blockMath(state, startLine, endLine, silent){
} }
export function setup(helper) { export function setup(helper) {
if (!helper.markdownIt) { if (!helper.markdownIt) {
return; return;
} }
@ -162,11 +172,11 @@ export function setup(helper) {
helper.registerPlugin(md => { helper.registerPlugin(md => {
if (enable_asciimath) { if (enable_asciimath) {
md.inline.ruler.after('escape', 'asciimath', asciiMath); md.inline.ruler.after("escape", "asciimath", asciiMath);
} }
md.inline.ruler.after('escape', 'math', inlineMath); md.inline.ruler.after("escape", "math", inlineMath);
md.block.ruler.after('code', 'math', blockMath, { md.block.ruler.after("code", "math", blockMath, {
alt: ['paragraph', 'reference', 'blockquote', 'list'] alt: ["paragraph", "reference", "blockquote", "list"]
}); });
}); });
} }