text.js 593 B

123456789101112131415161718192021222324
  1. /**
  2. * @import {Element as HastElement, Text as HastText} from 'hast'
  3. * @import {Text as MdastText} from 'mdast'
  4. * @import {State} from '../state.js'
  5. */
  6. import {trimLines} from 'trim-lines'
  7. /**
  8. * Turn an mdast `text` node into hast.
  9. *
  10. * @param {State} state
  11. * Info passed around.
  12. * @param {MdastText} node
  13. * mdast node.
  14. * @returns {HastElement | HastText}
  15. * hast node.
  16. */
  17. export function text(state, node) {
  18. /** @type {HastText} */
  19. const result = {type: 'text', value: trimLines(String(node.value))}
  20. state.patch(node, result)
  21. return state.applyData(node, result)
  22. }