1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Released under the MIT License.
// Copyright, 2024, by Bnchi.
// Copyright, 2024, by Titus Wormer.
// Copyright, 2026, by Samuel Williams.
//! JS equivalent: https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/handle/break.js
use super::Handle;
use crate::markdown::{
state::{Info, State},
util::pattern_in_scope::pattern_in_scope,
};
use crate::{
mdast::{Break, Node},
message::Message,
};
use alloc::string::ToString;
impl Handle for Break {
fn handle(
&self,
state: &mut State,
info: &Info,
_parent: Option<&Node>,
_node: &Node,
) -> Result<alloc::string::String, Message> {
for pattern in state.r#unsafe.iter() {
// If we can’t put eols in this construct (setext headings, tables), use a
// space instead.
if pattern.character == '\n' && pattern_in_scope(&state.stack, pattern) {
let space_or_tab = info.before.chars().any(|c| c == '\t' || c == ' ');
if space_or_tab {
return Ok("".to_string());
}
return Ok(" ".to_string());
}
}
Ok("\\\n".to_string())
}
}