break.js 568 B

12345678910111213141516171819202122
  1. /**
  2. * @import {Element, Text} from 'hast'
  3. * @import {Break} from 'mdast'
  4. * @import {State} from '../state.js'
  5. */
  6. /**
  7. * Turn an mdast `break` node into hast.
  8. *
  9. * @param {State} state
  10. * Info passed around.
  11. * @param {Break} node
  12. * mdast node.
  13. * @returns {Array<Element | Text>}
  14. * hast element content.
  15. */
  16. export function hardBreak(state, node) {
  17. /** @type {Element} */
  18. const result = {type: 'element', tagName: 'br', properties: {}, children: []}
  19. state.patch(node, result)
  20. return [state.applyData(node, result), {type: 'text', value: '\n'}]
  21. }