summaryrefslogtreecommitdiff
path: root/node_modules/markdown-it/lib/rules_block/heading.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-01-20 13:43:34 +0100
committerMinteck <contact@minteck.org>2022-01-20 13:43:34 +0100
commitc2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1 (patch)
tree226598e8d17d20e3721358f7c60b1cc6b851163a /node_modules/markdown-it/lib/rules_block/heading.js
downloadcobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.tar.gz
cobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.tar.bz2
cobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.zip
Initial commit
Diffstat (limited to 'node_modules/markdown-it/lib/rules_block/heading.js')
-rw-r--r--node_modules/markdown-it/lib/rules_block/heading.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/node_modules/markdown-it/lib/rules_block/heading.js b/node_modules/markdown-it/lib/rules_block/heading.js
new file mode 100644
index 0000000..9863f48
--- /dev/null
+++ b/node_modules/markdown-it/lib/rules_block/heading.js
@@ -0,0 +1,55 @@
+// heading (#, ##, ...)
+
+'use strict';
+
+var isSpace = require('../common/utils').isSpace;
+
+
+module.exports = function heading(state, startLine, endLine, silent) {
+ var ch, level, tmp, token,
+ pos = state.bMarks[startLine] + state.tShift[startLine],
+ max = state.eMarks[startLine];
+
+ // if it's indented more than 3 spaces, it should be a code block
+ if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
+
+ ch = state.src.charCodeAt(pos);
+
+ if (ch !== 0x23/* # */ || pos >= max) { return false; }
+
+ // count heading level
+ level = 1;
+ ch = state.src.charCodeAt(++pos);
+ while (ch === 0x23/* # */ && pos < max && level <= 6) {
+ level++;
+ ch = state.src.charCodeAt(++pos);
+ }
+
+ if (level > 6 || (pos < max && !isSpace(ch))) { return false; }
+
+ if (silent) { return true; }
+
+ // Let's cut tails like ' ### ' from the end of string
+
+ max = state.skipSpacesBack(max, pos);
+ tmp = state.skipCharsBack(max, 0x23, pos); // #
+ if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {
+ max = tmp;
+ }
+
+ state.line = startLine + 1;
+
+ token = state.push('heading_open', 'h' + String(level), 1);
+ token.markup = '########'.slice(0, level);
+ token.map = [ startLine, state.line ];
+
+ token = state.push('inline', '', 0);
+ token.content = state.src.slice(pos, max).trim();
+ token.map = [ startLine, state.line ];
+ token.children = [];
+
+ token = state.push('heading_close', 'h' + String(level), -1);
+ token.markup = '########'.slice(0, level);
+
+ return true;
+};