mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-04 12:39:29 +08:00
27 lines
627 B
Text
27 lines
627 B
Text
/**
|
||
* @typedef {import('../types.js').Handle} Handle
|
||
* @typedef {import('mdast').Break} Break
|
||
*/
|
||
|
||
import {patternInScope} from '../util/pattern-in-scope.js'
|
||
|
||
/**
|
||
* @type {Handle}
|
||
* @param {Break} _
|
||
*/
|
||
export function hardBreak(_, _1, context, safe) {
|
||
let index = -1
|
||
|
||
while (++index < context.unsafe.length) {
|
||
// If we can’t put eols in this construct (setext headings, tables), use a
|
||
// space instead.
|
||
if (
|
||
context.unsafe[index].character === '\n' &&
|
||
patternInScope(context.stack, context.unsafe[index])
|
||
) {
|
||
return /[ \t]/.test(safe.before) ? '' : ' '
|
||
}
|
||
}
|
||
|
||
return '\\\n'
|
||
}
|