summaryrefslogtreecommitdiff
path: root/packages/markdown-it-14.1.0/lib/rules_block/code.mjs
blob: e45e6f9ace655b3c20a349c9d8c779f4979e3602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Code block (4 spaces padded)

export default function code (state, startLine, endLine/*, silent */) {
  if (state.sCount[startLine] - state.blkIndent < 4) { return false }

  let nextLine = startLine + 1
  let last = nextLine

  while (nextLine < endLine) {
    if (state.isEmpty(nextLine)) {
      nextLine++
      continue
    }

    if (state.sCount[nextLine] - state.blkIndent >= 4) {
      nextLine++
      last = nextLine
      continue
    }
    break
  }

  state.line = last

  const token   = state.push('code_block', 'code', 0)
  token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + '\n'
  token.map     = [startLine, state.line]

  return true
}