check-fence.js 485 B

12345678910111213141516171819202122
  1. /**
  2. * @typedef {import('../types.js').Options} Options
  3. * @typedef {import('../types.js').State} State
  4. */
  5. /**
  6. * @param {State} state
  7. * @returns {Exclude<Options['fence'], null | undefined>}
  8. */
  9. export function checkFence(state) {
  10. const marker = state.options.fence || '`'
  11. if (marker !== '`' && marker !== '~') {
  12. throw new Error(
  13. 'Cannot serialize code with `' +
  14. marker +
  15. '` for `options.fence`, expected `` ` `` or `~`'
  16. )
  17. }
  18. return marker
  19. }