paragraph.mjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Paragraph
  2. export default function paragraph (state, startLine, endLine) {
  3. const terminatorRules = state.md.block.ruler.getRules('paragraph')
  4. const oldParentType = state.parentType
  5. let nextLine = startLine + 1
  6. state.parentType = 'paragraph'
  7. // jump line-by-line until empty one or EOF
  8. for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) {
  9. // this would be a code block normally, but after paragraph
  10. // it's considered a lazy continuation regardless of what's there
  11. if (state.sCount[nextLine] - state.blkIndent > 3) { continue }
  12. // quirk for blockquotes, this line should already be checked by that rule
  13. if (state.sCount[nextLine] < 0) { continue }
  14. // Some tags can terminate paragraph without empty line.
  15. let terminate = false
  16. for (let i = 0, l = terminatorRules.length; i < l; i++) {
  17. if (terminatorRules[i](state, nextLine, endLine, true)) {
  18. terminate = true
  19. break
  20. }
  21. }
  22. if (terminate) { break }
  23. }
  24. const content = state.getLines(startLine, nextLine, state.blkIndent, false).trim()
  25. state.line = nextLine
  26. const token_o = state.push('paragraph_open', 'p', 1)
  27. token_o.map = [startLine, state.line]
  28. const token_i = state.push('inline', '', 0)
  29. token_i.content = content
  30. token_i.map = [startLine, state.line]
  31. token_i.children = []
  32. state.push('paragraph_close', 'p', -1)
  33. state.parentType = oldParentType
  34. return true
  35. }