Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed
https://markdown-it.github.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
10 years ago
|
// Horizontal rule
|
||
|
|
||
1 year ago
|
import { isSpace } from '../common/utils.mjs';
|
||
10 years ago
|
|
||
1 year ago
|
export default function hr(state, startLine, endLine, silent) {
|
||
10 years ago
|
var marker, cnt, ch, token,
|
||
10 years ago
|
pos = state.bMarks[startLine] + state.tShift[startLine],
|
||
10 years ago
|
max = state.eMarks[startLine];
|
||
|
|
||
8 years ago
|
// if it's indented more than 3 spaces, it should be a code block
|
||
|
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
|
||
|
|
||
10 years ago
|
marker = state.src.charCodeAt(pos++);
|
||
|
|
||
|
// Check hr marker
|
||
|
if (marker !== 0x2A/* * */ &&
|
||
|
marker !== 0x2D/* - */ &&
|
||
|
marker !== 0x5F/* _ */) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
10 years ago
|
// markers can be mixed with spaces, but there should be at least 3 of them
|
||
10 years ago
|
|
||
|
cnt = 1;
|
||
|
while (pos < max) {
|
||
|
ch = state.src.charCodeAt(pos++);
|
||
10 years ago
|
if (ch !== marker && !isSpace(ch)) { return false; }
|
||
10 years ago
|
if (ch === marker) { cnt++; }
|
||
|
}
|
||
|
|
||
|
if (cnt < 3) { return false; }
|
||
|
|
||
|
if (silent) { return true; }
|
||
|
|
||
10 years ago
|
state.line = startLine + 1;
|
||
10 years ago
|
|
||
10 years ago
|
token = state.push('hr', 'hr', 0);
|
||
|
token.map = [ startLine, state.line ];
|
||
|
token.markup = Array(cnt + 1).join(String.fromCharCode(marker));
|
||
10 years ago
|
|
||
10 years ago
|
return true;
|
||
1 year ago
|
}
|