style$(abcjs): some code style fixes
This commit is contained in:
parent
fe111c207c
commit
a4f0c11726
@ -1,18 +1,13 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable no-continue */
|
||||||
|
import abcjs from 'abcjs';
|
||||||
|
|
||||||
function abcNotation(state, startLine, endLine, silent) {
|
function abcNotation(state, startLine, endLine, silent) {
|
||||||
const validateParams = params => params.trim().match(/^abc$/);
|
const validateParams = params => params.trim().match(/^abc$/);
|
||||||
|
let nextLine;
|
||||||
|
let autoClosed = false;
|
||||||
|
|
||||||
let pos,
|
let start = state.bMarks[startLine] + state.tShift[startLine];
|
||||||
nextLine,
|
let max = state.eMarks[startLine];
|
||||||
markup,
|
|
||||||
params,
|
|
||||||
token,
|
|
||||||
oldParent,
|
|
||||||
oldLineMax,
|
|
||||||
markerLength,
|
|
||||||
autoClosed = false,
|
|
||||||
start = state.bMarks[startLine] + state.tShift[startLine],
|
|
||||||
max = state.eMarks[startLine];
|
|
||||||
|
|
||||||
// Check out the first character quickly,
|
// Check out the first character quickly,
|
||||||
// this filters out all non-codeblocks
|
// this filters out all non-codeblocks
|
||||||
@ -22,15 +17,15 @@ function abcNotation(state, startLine, endLine, silent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check out the rest of the marker string
|
// Check out the rest of the marker string
|
||||||
const markerStart = pos;
|
const markerStart = start;
|
||||||
pos = state.skipChars(pos, marker);
|
start = state.skipChars(start, marker);
|
||||||
markerLength = pos - markerStart;
|
const markerLength = start - markerStart;
|
||||||
if (markerLength < 3) {
|
if (markerLength < 3) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
markup = state.src.slice(start, pos);
|
const markup = state.src.slice(markerLength, start);
|
||||||
params = state.src.slice(pos, max);
|
const params = state.src.slice(start, max);
|
||||||
if (!validateParams(params)) {
|
if (!validateParams(params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -70,16 +65,15 @@ function abcNotation(state, startLine, endLine, silent) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = state.skipChars(pos, marker);
|
start = state.skipChars(start, marker);
|
||||||
// closing fence must be at least as long as the opening one
|
// closing fence must be at least as long as the opening one
|
||||||
if (pos - markerStart < markerLength) {
|
if (start - markerStart < markerLength) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure tail has spaces only
|
// make sure tail has spaces only
|
||||||
pos = state.skipSpaces(pos);
|
start = state.skipSpaces(start);
|
||||||
|
if (start < max) {
|
||||||
if (pos < max) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,8 +82,8 @@ function abcNotation(state, startLine, endLine, silent) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_parent = state.parentType;
|
const oldParent = state.parentType;
|
||||||
old_line_max = state.lineMax;
|
const oldLineMax = state.lineMax;
|
||||||
state.parentType = 'container';
|
state.parentType = 'container';
|
||||||
|
|
||||||
// If a fence has heading spaces, they should be removed from its inner block
|
// If a fence has heading spaces, they should be removed from its inner block
|
||||||
@ -98,21 +92,24 @@ function abcNotation(state, startLine, endLine, silent) {
|
|||||||
// this will prevent lazy continuations from ever going past our end marker
|
// this will prevent lazy continuations from ever going past our end marker
|
||||||
state.lineMax = nextLine;
|
state.lineMax = nextLine;
|
||||||
|
|
||||||
token = state.push('fence_abc', 'div', 1);
|
const token = state.push('fence_abc', 'div', 1);
|
||||||
token.info = params;
|
token.info = params;
|
||||||
// token.content = state.getLines(startLine + 1, nextLine, markerLength, true);
|
|
||||||
token.markup = markup;
|
token.markup = markup;
|
||||||
token.block = true;
|
token.block = true;
|
||||||
token.map = [startLine, nextLine];
|
token.map = [startLine, nextLine];
|
||||||
|
|
||||||
state.parentType = old_parent;
|
const abc = state.getLines(startLine + 1, nextLine, markerLength, true);
|
||||||
state.lineMax = old_line_max;
|
const renderedSvg = abcjs.parseOnly(abc);
|
||||||
|
console.error(renderedSvg);
|
||||||
|
|
||||||
|
state.parentType = oldParent;
|
||||||
|
state.lineMax = oldLineMax;
|
||||||
state.line = nextLine + (autoClosed ? 1 : 0);
|
state.line = nextLine + (autoClosed ? 1 : 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default md => {
|
export default (md) => {
|
||||||
md.block.ruler.before('fence', 'fence_abc', abcNotation, {
|
md.block.ruler.before('fence', 'fence_abc', abcNotation, {
|
||||||
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user