code.mjs 686 B

123456789101112131415161718192021222324252627282930
  1. // Code block (4 spaces padded)
  2. export default function code (state, startLine, endLine/*, silent */) {
  3. if (state.sCount[startLine] - state.blkIndent < 4) { return false }
  4. let nextLine = startLine + 1
  5. let last = nextLine
  6. while (nextLine < endLine) {
  7. if (state.isEmpty(nextLine)) {
  8. nextLine++
  9. continue
  10. }
  11. if (state.sCount[nextLine] - state.blkIndent >= 4) {
  12. nextLine++
  13. last = nextLine
  14. continue
  15. }
  16. break
  17. }
  18. state.line = last
  19. const token = state.push('code_block', 'code', 0)
  20. token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + '\n'
  21. token.map = [startLine, state.line]
  22. return true
  23. }