html.js 648 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * @import {Element} from 'hast'
  3. * @import {Html} from 'mdast'
  4. * @import {State} from '../state.js'
  5. * @import {Raw} from '../../index.js'
  6. */
  7. /**
  8. * Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
  9. * nothing).
  10. *
  11. * @param {State} state
  12. * Info passed around.
  13. * @param {Html} node
  14. * mdast node.
  15. * @returns {Element | Raw | undefined}
  16. * hast node.
  17. */
  18. export function html(state, node) {
  19. if (state.options.allowDangerousHtml) {
  20. /** @type {Raw} */
  21. const result = {type: 'raw', value: node.value}
  22. state.patch(node, result)
  23. return state.applyData(node, result)
  24. }
  25. return undefined
  26. }