index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @typedef {import('micromark-util-types').Encoding} Encoding
  3. * @typedef {import('micromark-util-types').Options} Options
  4. * @typedef {import('micromark-util-types').Value} Value
  5. */
  6. import {compile} from './lib/compile.js'
  7. import {parse} from './lib/parse.js'
  8. import {postprocess} from './lib/postprocess.js'
  9. import {preprocess} from './lib/preprocess.js'
  10. export {compile} from './lib/compile.js'
  11. export {parse} from './lib/parse.js'
  12. export {postprocess} from './lib/postprocess.js'
  13. export {preprocess} from './lib/preprocess.js'
  14. /**
  15. * Compile markdown to HTML.
  16. *
  17. * > Note: which encodings are supported depends on the engine.
  18. * > For info on Node.js, see:
  19. * > <https://nodejs.org/api/util.html#whatwg-supported-encodings>.
  20. *
  21. * @overload
  22. * @param {Value} value
  23. * Markdown to parse (`string` or `Uint8Array`).
  24. * @param {Encoding | null | undefined} encoding
  25. * Character encoding to understand `value` as when it’s a `Uint8Array`
  26. * (`string`, default: `'utf8'`).
  27. * @param {Options | null | undefined} [options]
  28. * Configuration.
  29. * @returns {string}
  30. * Compiled HTML.
  31. *
  32. * @overload
  33. * @param {Value} value
  34. * Markdown to parse (`string` or `Uint8Array`).
  35. * @param {Options | null | undefined} [options]
  36. * Configuration.
  37. * @returns {string}
  38. * Compiled HTML.
  39. *
  40. * @param {Value} value
  41. * Markdown to parse (`string` or `Uint8Array`).
  42. * @param {Encoding | Options | null | undefined} [encoding]
  43. * Character encoding to understand `value` as when it’s a `Uint8Array`
  44. * (`string`, default: `'utf8'`).
  45. * @param {Options | null | undefined} [options]
  46. * Configuration.
  47. * @returns {string}
  48. * Compiled HTML.
  49. */
  50. export function micromark(value, encoding, options) {
  51. if (typeof encoding !== 'string') {
  52. options = encoding
  53. encoding = undefined
  54. }
  55. return compile(options)(
  56. postprocess(
  57. parse(options).document().write(preprocess()(value, encoding, true))
  58. )
  59. )
  60. }