inline-code.js 678 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @import {Element, Text} from 'hast'
  3. * @import {InlineCode} from 'mdast'
  4. * @import {State} from '../state.js'
  5. */
  6. /**
  7. * Turn an mdast `inlineCode` node into hast.
  8. *
  9. * @param {State} state
  10. * Info passed around.
  11. * @param {InlineCode} node
  12. * mdast node.
  13. * @returns {Element}
  14. * hast node.
  15. */
  16. export function inlineCode(state, node) {
  17. /** @type {Text} */
  18. const text = {type: 'text', value: node.value.replace(/\r?\n|\r/g, ' ')}
  19. state.patch(node, text)
  20. /** @type {Element} */
  21. const result = {
  22. type: 'element',
  23. tagName: 'code',
  24. properties: {},
  25. children: [text]
  26. }
  27. state.patch(node, result)
  28. return state.applyData(node, result)
  29. }