break.js 501 B

1234567891011121314151617181920
  1. module.exports = hardBreak
  2. var patternInScope = require('../util/pattern-in-scope')
  3. function hardBreak(node, _, context, safe) {
  4. var index = -1
  5. while (++index < context.unsafe.length) {
  6. // If we can’t put eols in this construct (setext headings, tables), use a
  7. // space instead.
  8. if (
  9. context.unsafe[index].character === '\n' &&
  10. patternInScope(context.stack, context.unsafe[index])
  11. ) {
  12. return /[ \t]/.test(safe.before) ? '' : ' '
  13. }
  14. }
  15. return '\\\n'
  16. }