MCPcopy Index your code
hub / github.com/braziljs/eloquente-javascript / parseBlockMeta

Function parseBlockMeta

src/markdown.mjs:16–61  ·  view source on GitHub ↗
(state, startLine, endLine)

Source from the content-addressed store, hash-verified

14}
15
16function parseBlockMeta(state, startLine, endLine) {
17 let pos = state.bMarks[startLine] + state.tShift[startLine]
18 let max = state.eMarks[startLine]
19 // Check for code block indentation or end of input
20 if (state.sCount[startLine] - state.blkIndent >= 4 || pos + 4 > max) return false
21
22 // Test for `{{` opening marker
23 if (state.src.charCodeAt(pos) != 123 || state.src.charCodeAt(pos + 1) != 123) return false
24
25 let content = state.src.slice(pos + 2, max), single
26
27 if (single = /\}\}\s*$/.exec(content)) {
28 let data = parseData(content.slice(0, single.index))
29 if (!data) return false
30 let token = state.push("meta_" + data.tag, null, 0)
31 token.map = [startLine, startLine + 1]
32 token.args = data.args
33 state.line++
34 return true
35 }
36
37 let data = parseData(content)
38 if (!data) return false
39
40 let line = startLine + 1, close = data.tag + "}}", open = new RegExp("^\\{\\{" + data.tag + "(\\s|$)"), depth = 0
41 for (; line < endLine; line++) {
42 if (line == endLine) throw new SyntaxError("Unterminated meta block")
43 let start = state.bMarks[line] + state.tShift[line]
44 let lineText = state.src.slice(start, state.eMarks[line])
45 if (open.test(lineText)) {
46 depth++
47 } else if (lineText == close) {
48 if (depth) depth--
49 else break
50 }
51 }
52
53 let token = state.push("meta_" + data.tag + "_open", null, 1)
54 token.map = [startLine, line + 1]
55 token.args = data.args
56 state.md.block.tokenize(state, startLine + 1, line)
57 state.push("meta_" + data.tag + "_close", null, -1).args = data.args
58 state.line = line + 1
59
60 return true
61}
62
63function parseBlockTable(state, startLine, endLine) {
64 if (state.sCount[startLine] - state.blkIndent >= 4) return false

Callers

nothing calls this directly

Calls 2

parseDataFunction · 0.85
sliceMethod · 0.45

Tested by

no test coverage detected