MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / parseBlockTable

Function parseBlockTable

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

Source from the content-addressed store, hash-verified

61}
62
63function parseBlockTable(state, startLine, endLine) {
64 if (state.sCount[startLine] - state.blkIndent >= 4) return false
65
66 let line = startLine, lines = []
67 for (; line < endLine; line++) {
68 let start = state.bMarks[line] + state.tShift[line]
69 let lineText = state.src.slice(start, state.eMarks[line])
70 if (!/\S/.test(lineText)) break
71 if (lineText[0] != "|") return false
72 lines.push(lineText.slice(1))
73 }
74
75 if (!lines.length) return false
76
77 state.push("table_open", "table", 1).map = [startLine, line]
78 for (let i = 0; i < lines.length; i++) {
79 state.push("tr_open", "tr", 1).map = [startLine + i, startLine + i + 1]
80 let m, content = /((?:[^`|]|`.*?`)+)\|?/g
81 while (m = content.exec(lines[i])) {
82 state.push("td_open", "td", 1).map = [startLine + i, startLine + i + 1]
83 let inline = state.push("inline", "", 0)
84 inline.content = m[1].trim()
85 inline.map = [startLine + i, startLine + i + 1]
86 inline.children = []
87 state.push("td_close", "td", -1)
88 }
89 state.push("tr_close", "tr", -1)
90 }
91 state.push("table_close", "table", -1)
92 state.line = line + 1
93
94 return true
95}
96
97function parseInlineMeta(state, silent) {
98 if (state.src.charCodeAt(state.pos) != 91) return false // '['

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected