format-code-as-indented.js 568 B

12345678910111213141516171819202122
  1. /**
  2. * @import {State} from 'mdast-util-to-markdown'
  3. * @import {Code} from 'mdast'
  4. */
  5. /**
  6. * @param {Code} node
  7. * @param {State} state
  8. * @returns {boolean}
  9. */
  10. export function formatCodeAsIndented(node, state) {
  11. return Boolean(
  12. state.options.fences === false &&
  13. node.value &&
  14. // If there’s no info…
  15. !node.lang &&
  16. // And there’s a non-whitespace character…
  17. /[^ \r\n]/.test(node.value) &&
  18. // And the value doesn’t start or end in a blank…
  19. !/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node.value)
  20. )
  21. }