mod delimiters;
use self::delimiters::{longest_consecutive_run, min_safe_code_span_delimiter_length};
use crate::converter::Context;
use crate::converter::dom_context::DomContext;
use crate::converter::inline::HandlerContext;
use crate::converter::inline::wrapped::emit_code_span;
use crate::converter::main::walk_node;
use crate::converter::text::dedent_code_block;
use crate::converter::walk::{CaptureEnd, Close, Open};
use crate::options::ConversionOptions;
use std::rc::Rc;
#[cfg(feature = "visitor")]
use crate::converter::utility::serialization::serialize_node;
#[cfg(feature = "visitor")]
use std::borrow::Cow;
const MIN_FENCE_LENGTH: usize = 3;
pub fn open_code(
node_handle: &tl::NodeHandle,
tag: &tl::HTMLTag,
parser: &tl::Parser,
context: &Context,
children: &mut Vec<tl::NodeHandle>,
) -> Open {
children.extend(tag.children().top().iter().copied());
if context.code_element_is_transparent() {
return Open::children_only();
}
let links = Rc::new(std::cell::RefCell::new(Vec::new()));
let breaks = Rc::new(std::cell::RefCell::new(Vec::new()));
let code_ctx = Context {
in_code: true,
inline_code_breaks: Some((node_handle.get_inner(), breaks.clone())),
inline_code_links: if context.in_code {
context.inline_code_links.clone()
} else if contains_anchor(tag, parser) {
Some(links.clone())
} else {
None
},
..context.clone()
};
Open {
scope: Some(Rc::new(code_ctx)),
close: Close::Capture(CaptureEnd::Code(CodeEnd {
links,
breaks,
source_whitespace_only: children.iter().all(|child| {
matches!(child.get(parser), Some(tl::Node::Raw(raw))
if crate::text::decode_html_entities_cow(&raw.as_utf8_str()).trim().is_empty())
}),
})),
}
}
pub struct CodeEnd {
links: Rc<std::cell::RefCell<Vec<crate::converter::context::InlineCodeLink>>>,
breaks: Rc<std::cell::RefCell<Vec<usize>>>,
source_whitespace_only: bool,
}
pub fn close_code(end: &CodeEnd, content: &str, mut handler: HandlerContext<'_>) {
if content.is_empty() {
return;
}
#[cfg(feature = "visitor")]
if let Some(tl::Node::Tag(tag)) = handler.node_handle.get(handler.parser) {
if tag.name().as_utf8_str().eq_ignore_ascii_case("code") {
if let Some(custom_output) = visit_inline_code(tag, content, &handler) {
handler.output.push_str(&custom_output);
return;
}
}
}
if content.bytes().all(|byte| byte == b'\n') && !end.breaks.borrow().is_empty() {
for _ in 0..end.breaks.borrow().len() {
emit_collected_code_break(&mut handler);
}
return;
}
if end.source_whitespace_only
&& content.bytes().all(|byte| byte == b'\n')
&& end.breaks.borrow().is_empty()
&& handler.options.whitespace_mode == crate::options::WhitespaceMode::Normalized
{
crate::converter::inline::wrapped::emit_whitespace_only_inline_body(content, handler.output);
return;
}
if end
.breaks
.borrow()
.first()
.is_some_and(|offset| content[..*offset].bytes().all(|byte| byte == b'\n'))
&& content.starts_with('\n')
&& !handler.output.is_empty()
&& crate::converter::utility::white_space::space_is_owed(handler.output)
{
emit_collected_code_break(&mut handler);
}
emit_inline_code_with_links(content, &end.links.borrow(), &mut handler);
if end
.breaks
.borrow()
.last()
.is_some_and(|offset| content[*offset + 1..].bytes().all(|byte| byte == b'\n'))
&& content.ends_with('\n')
&& crate::converter::utility::siblings::following_sibling_content(
handler.node_handle.get_inner(),
handler.parser,
handler.dom_context,
) == crate::converter::utility::siblings::FollowingContent::Inline
{
emit_collected_code_break(&mut handler);
}
}
pub(in crate::converter) fn contains_anchor(tag: &tl::HTMLTag<'_>, parser: &tl::Parser<'_>) -> bool {
let mut pending = tag.children().top().to_vec();
while let Some(handle) = pending.pop() {
if let Some(tl::Node::Tag(child)) = handle.get(parser) {
if child.name().as_utf8_str().eq_ignore_ascii_case("a") && child.attributes().get("href").is_some() {
return true;
}
pending.extend(child.children().top().iter().copied());
}
}
false
}
fn emit_inline_code_with_links(
content: &str,
links: &[crate::converter::context::InlineCodeLink],
handler: &mut HandlerContext<'_>,
) {
if links.is_empty() {
emit_code_content(content, handler);
return;
}
let mut start = 0;
let mut pending_break = false;
let mut emitted = false;
for link in links {
emit_linked_code_text(
&content[start..link.range.start],
&mut pending_break,
&mut emitted,
handler,
);
if pending_break && emitted {
emit_collected_code_break(handler);
}
pending_break = false;
handler.output.push_str(&link.markdown);
emitted = true;
start = link.range.end;
}
emit_linked_code_text(&content[start..], &mut pending_break, &mut emitted, handler);
}
fn emit_linked_code_text(
content: &str,
pending_break: &mut bool,
emitted: &mut bool,
handler: &mut HandlerContext<'_>,
) {
let break_count = content.matches('\n').count();
for (index, segment) in content.split('\n').enumerate() {
*pending_break |= index > 0;
if segment.is_empty() {
continue;
}
if *pending_break && *emitted {
emit_collected_code_break(handler);
}
let segment = if (handler.context.in_table_cell || handler.context.in_heading) && index < break_count {
segment.trim_end()
} else {
segment
};
if segment.is_empty() {
continue;
}
emit_code_content(segment, handler);
*emitted = true;
*pending_break = false;
}
}
fn emit_collected_code_break(handler: &mut HandlerContext<'_>) {
if handler.context.in_table_cell || handler.context.in_heading {
handler.output.push(' ');
} else {
handler
.output
.push_str(crate::converter::main_helpers::hard_break_marker(handler.options));
}
}
fn emit_code_content(content: &str, handler: &mut HandlerContext<'_>) {
emit_inline_code(
content,
handler.output,
handler.options,
handler.node_handle,
handler.parser,
handler.dom_context,
);
}
fn walk_children(tag: &tl::HTMLTag<'_>, output: &mut String, context: &Context, handler: &HandlerContext<'_>) {
for child_handle in tag.children().top().iter() {
walk_node(
child_handle,
handler.parser,
output,
crate::converter::block::container::HandlerContext::new(
handler.options,
context,
handler.depth + 1,
handler.dom_context,
),
);
}
}
#[cfg(feature = "visitor")]
fn visit_inline_code(tag: &tl::HTMLTag<'_>, content: &str, handler: &HandlerContext<'_>) -> Option<String> {
use crate::visitor::{NodeContext, NodeType};
let visitor_handle = handler.context.visitor.as_ref()?;
let node_id = handler.node_handle.get_inner();
let node_context = NodeContext::with_lazy_attributes(
NodeType::Code,
Cow::Borrowed("code"),
tag,
handler.depth,
handler.dom_context.get_sibling_index(node_id).unwrap_or(0),
handler
.dom_context
.parent_tag_name(node_id, handler.parser)
.map(Cow::Borrowed),
true,
);
let result = visitor_handle
.lock()
.expect("visitor mutex poisoned")
.visit_code_inline(&node_context, content);
if handler.options.whitespace_mode == crate::options::WhitespaceMode::Strict
&& (matches!(&result, crate::visitor::VisitResult::Skip)
|| matches!(&result, crate::visitor::VisitResult::Custom(custom) if custom.trim_matches([' ', '\t']).is_empty()))
{
handler.dom_context.record_absent_breaks(node_id, true);
}
visitor_output(result, handler)
}
pub(in crate::converter) fn emit_inline_code(
content: &str,
output: &mut String,
options: &ConversionOptions,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
dom_ctx: &DomContext,
) {
let separator = crate::converter::main_helpers::hard_break_marker(options);
let mut first = true;
for segment in content.split('\n').filter(|segment| !segment.is_empty()) {
if first {
let mut span = String::with_capacity(segment.len() + 2);
format_inline_code(segment, &mut span);
emit_code_span(&span, segment, output, node_handle, parser, dom_ctx);
} else {
output.push_str(separator);
format_inline_code(segment, output);
}
first = false;
}
}
pub fn handle_pre(tag: &tl::HTMLTag, handler: HandlerContext<'_>) {
let cell_break_offsets = (handler.context.in_table_cell && handler.options.br_in_tables).then(|| {
std::rc::Rc::new(std::cell::RefCell::new(
crate::converter::context::CapturedOffsets::default(),
))
});
let code_ctx = Context {
in_code: true,
in_code_block: true,
pre_cell_break_offsets: cell_break_offsets.clone(),
..handler.context.clone()
};
let language = detect_language(tag, handler.parser);
let mut content = String::with_capacity(256);
walk_children(tag, &mut content, &code_ctx, &handler);
if content.is_empty() {
return;
}
if handler.options.code_block_style == crate::options::CodeBlockStyle::Indented
&& !handler.context.in_table_cell
&& matches!(
crate::converter::utility::siblings::previous_content_block(
handler.node_handle,
handler.parser,
handler.dom_context
),
Some("ul" | "ol")
)
{
if handler.context.in_list_item {
crate::converter::list::utils::start_block_in_list_item(handler.output, handler.context, handler.options);
} else {
separate_code_block(handler.output, handler.context);
}
handler.output.push_str("<!-- -->\n\n");
}
let offsets = cell_break_offsets
.as_ref()
.map(|offsets| offsets.borrow().positions())
.unwrap_or_default();
let segmented = (!offsets.is_empty()).then(|| content.clone());
let processed = process_pre_content(content, handler.options.whitespace_mode, false);
#[cfg(feature = "visitor")]
if let Some(custom_output) = visit_code_block(tag, language.as_deref(), &processed, &handler) {
handler.output.push_str(&custom_output);
} else {
format_code_block(
segmented.as_deref().unwrap_or(&processed),
&offsets,
language.as_deref(),
handler.output,
handler.options,
handler.context,
);
}
#[cfg(not(feature = "visitor"))]
format_code_block(
segmented.as_deref().unwrap_or(&processed),
&offsets,
language.as_deref(),
handler.output,
handler.options,
handler.context,
);
if let Some(ref collector) = handler.context.structure_collector {
collector.borrow_mut().push_code(&processed, language.as_deref());
}
}
pub(in crate::converter) fn is_line_element_in_pre(tag_name: &str) -> bool {
matches!(
tag_name,
"address"
| "article"
| "aside"
| "center"
| "dialog"
| "div"
| "footer"
| "header"
| "hgroup"
| "main"
| "nav"
| "search"
| "section"
)
}
fn start_pre_line(output: &mut String) {
if !output.is_empty() && !output.ends_with('\n') {
output.push('\n');
}
}
pub(in crate::converter) fn handle_line_element_in_pre(
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: crate::converter::block::container::HandlerContext<'_>,
) {
start_pre_line(output);
crate::converter::block::container::handle_passthrough(node_handle, parser, output, handler);
start_pre_line(output);
}
fn detect_language(tag: &tl::HTMLTag<'_>, parser: &tl::Parser<'_>) -> Option<String> {
language_from_class(tag).or_else(|| {
tag.children().top().iter().find_map(|child_handle| {
let tl::Node::Tag(child_tag) = child_handle.get(parser)? else {
return None;
};
(child_tag.name() == "code")
.then(|| language_from_class(child_tag))
.flatten()
})
})
}
fn language_from_class(tag: &tl::HTMLTag<'_>) -> Option<String> {
let classes = tag.attributes().get("class")??;
let class_text = classes.as_utf8_str();
let classes = crate::text::decode_attribute_value_cow(&class_text);
classes.split_whitespace().find_map(|class| {
class
.strip_prefix("language-")
.or_else(|| class.strip_prefix("lang-"))
.map(str::to_string)
})
}
pub(in crate::converter) fn process_pre_content(
mut content: String,
whitespace_mode: crate::options::WhitespaceMode,
tag_feed_dropped: bool,
) -> String {
let leading = content.len() - content.trim_start_matches('\n').len();
let kept = if whitespace_mode == crate::options::WhitespaceMode::Strict {
leading.saturating_sub(usize::from(tag_feed_dropped)).min(1)
} else {
leading.saturating_sub(1)
};
content.drain(..leading - kept);
content
}
#[cfg(feature = "visitor")]
fn visit_code_block(
tag: &tl::HTMLTag<'_>,
language: Option<&str>,
content: &str,
handler: &HandlerContext<'_>,
) -> Option<String> {
use crate::visitor::{NodeContext, NodeType};
let visitor_handle = handler.context.visitor.as_ref()?;
let node_id = handler.node_handle.get_inner();
let node_context = NodeContext::with_lazy_attributes(
NodeType::Pre,
Cow::Borrowed("pre"),
tag,
handler.depth,
handler.dom_context.get_sibling_index(node_id).unwrap_or(0),
handler
.dom_context
.parent_tag_name(node_id, handler.parser)
.map(Cow::Borrowed),
false,
);
let result =
visitor_handle
.lock()
.expect("visitor mutex poisoned")
.visit_code_block(&node_context, language, content);
if handler.options.whitespace_mode == crate::options::WhitespaceMode::Strict
&& (matches!(&result, crate::visitor::VisitResult::Skip)
|| matches!(&result, crate::visitor::VisitResult::Custom(custom) if custom.trim_matches([' ', '\t']).is_empty()))
{
handler.dom_context.record_absent_breaks(node_id, true);
}
visitor_output(result, handler)
}
#[cfg(feature = "visitor")]
fn visitor_output(result: crate::visitor::VisitResult, handler: &HandlerContext<'_>) -> Option<String> {
use crate::visitor::VisitResult;
match result {
VisitResult::Continue => None,
VisitResult::Custom(custom) => {
crate::converter::structure_capture::replace_element(handler.context, Some(&custom));
Some(custom)
}
VisitResult::Skip => {
crate::converter::structure_capture::replace_element(handler.context, None);
Some(String::new())
}
VisitResult::PreserveHtml => {
let html = serialize_node(handler.node_handle, handler.parser);
crate::converter::structure_capture::replace_element(handler.context, Some(&html));
Some(html)
}
VisitResult::Error(error) => {
crate::converter::structure_capture::replace_element(handler.context, None);
if handler.context.visitor_error.borrow().is_none() {
*handler.context.visitor_error.borrow_mut() = Some(error);
}
None
}
}
}
pub(in crate::converter) fn format_inline_code(content: &str, output: &mut String) {
let contains_backtick = content.contains('`');
let needs_delimiter_spaces = {
let first_char = content.chars().next();
let last_char = content.chars().last();
let starts_with_space = first_char == Some(' ');
let ends_with_space = last_char == Some(' ');
let starts_with_backtick = first_char == Some('`');
let ends_with_backtick = last_char == Some('`');
starts_with_backtick || ends_with_backtick || (starts_with_space && ends_with_space && contains_backtick)
};
let (num_backticks, needs_spaces) = if contains_backtick {
(min_safe_code_span_delimiter_length(content), needs_delimiter_spaces)
} else {
(1, needs_delimiter_spaces)
};
for _ in 0..num_backticks {
output.push('`');
}
if needs_spaces {
output.push(' ');
}
output.push_str(content);
if needs_spaces {
output.push(' ');
}
for _ in 0..num_backticks {
output.push('`');
}
}
fn format_code_block(
content: &str,
cell_break_offsets: &[usize],
language: Option<&str>,
output: &mut String,
options: &ConversionOptions,
ctx: &Context,
) {
if ctx.in_table_cell {
let trimmed_content = content.trim_matches('\n');
if !trimmed_content.is_empty() && !ctx.convert_as_inline && !ctx.in_code {
crate::converter::main_helpers::separate_block_in_cell(output, options.br_in_tables);
}
format_preformatted_cell_content(
content,
cell_break_offsets,
output,
options.br_in_tables,
options.whitespace_mode == crate::options::WhitespaceMode::Strict,
);
return;
}
if ctx.in_list_item {
format_code_block_in_list_item(content, language, output, options, ctx);
return;
}
separate_code_block(output, ctx);
render_code_block(content, language, output, options);
}
pub(in crate::converter) fn render_code_block(
content: &str,
language: Option<&str>,
output: &mut String,
options: &ConversionOptions,
) {
match options.code_block_style {
crate::options::CodeBlockStyle::Indented => format_indented_code_block(content, output),
crate::options::CodeBlockStyle::Backticks | crate::options::CodeBlockStyle::Tildes => {
format_fenced_code_block(content, language, output, options);
}
}
}
fn separate_code_block(output: &mut String, context: &Context) {
if context.convert_as_inline || output.is_empty() || output.ends_with("\n\n") {
return;
}
if output.ends_with('\n') {
output.push('\n');
} else {
output.push_str("\n\n");
}
}
fn format_indented_code_block(content: &str, output: &mut String) {
let indented = content
.trim_start_matches('\n')
.lines()
.map(|line| {
if line.is_empty() {
String::new()
} else {
format!(" {line}")
}
})
.collect::<Vec<_>>()
.join("\n");
output.push_str(&indented);
output.push_str("\n\n");
}
fn format_fenced_code_block(content: &str, language: Option<&str>, output: &mut String, options: &ConversionOptions) {
let fence_char = if options.code_block_style == crate::options::CodeBlockStyle::Backticks {
'`'
} else {
'~'
};
let fence_length = (longest_consecutive_run(content, fence_char) + 1).max(MIN_FENCE_LENGTH);
let fence: String = std::iter::repeat_n(fence_char, fence_length).collect();
output.push_str(&fence);
if let Some(language) = language {
output.push_str(language);
} else if !options.code_language.is_empty() {
output.push_str(&options.code_language);
}
output.push('\n');
output.push_str(content.trim_end_matches('\n'));
output.push('\n');
output.push_str(&fence);
output.push_str("\n\n");
}
pub(in crate::converter) fn format_preformatted_cell_content(
content: &str,
break_offsets: &[usize],
output: &mut String,
br_in_tables: bool,
preserve_whitespace: bool,
) {
if !br_in_tables || break_offsets.is_empty() {
let normalized = normalize_preformatted_cell_segment(content, preserve_whitespace);
let folded = crate::text::fold_cell_line_breaks_verbatim_cow(&normalized);
if !folded.is_empty() {
format_inline_code(folded.as_ref(), output);
}
return;
}
let (normalized, break_offsets) = normalize_preformatted_cell_content(content, break_offsets, preserve_whitespace);
let mut start = 0;
let mut wrote_segment = false;
let mut pending_breaks = 0;
for offset in break_offsets {
if offset < start || !normalized.is_char_boundary(offset) {
continue;
}
let segment = crate::text::fold_cell_line_breaks_verbatim_cow(&normalized[start..offset]);
if !segment.is_empty() {
if wrote_segment {
for _ in 0..pending_breaks {
output.push_str("<br>");
}
}
format_inline_code(segment.as_ref(), output);
wrote_segment = true;
pending_breaks = 0;
}
pending_breaks += 1;
start = offset + 1;
}
let segment = crate::text::fold_cell_line_breaks_verbatim_cow(&normalized[start..]);
if !segment.is_empty() {
if wrote_segment {
for _ in 0..pending_breaks {
output.push_str("<br>");
}
}
format_inline_code(segment.as_ref(), output);
}
}
fn normalize_preformatted_cell_content(
content: &str,
break_offsets: &[usize],
preserve_whitespace: bool,
) -> (String, Vec<usize>) {
let core = content.trim_matches('\n');
let core_start = content.len() - content.trim_start_matches('\n').len();
let normalized = if preserve_whitespace {
core.to_string()
} else {
dedent_code_block(core)
};
let newline_offsets: Vec<usize> = normalized.match_indices('\n').map(|(offset, _)| offset).collect();
let normalized_break_offsets = break_offsets
.iter()
.filter_map(|&offset| offset.checked_sub(core_start))
.filter(|&offset| offset < core.len() && core.as_bytes().get(offset) == Some(&b'\n'))
.map(|offset| core[..offset].bytes().filter(|&byte| byte == b'\n').count())
.filter_map(|ordinal| newline_offsets.get(ordinal).copied())
.collect();
(normalized, normalized_break_offsets)
}
fn normalize_preformatted_cell_segment(content: &str, preserve_whitespace: bool) -> String {
let content = content.trim_matches('\n');
if preserve_whitespace {
content.to_string()
} else {
dedent_code_block(content)
}
}
fn format_code_block_in_list_item(
content: &str,
language: Option<&str>,
output: &mut String,
options: &ConversionOptions,
ctx: &Context,
) {
let mut rendered = String::new();
let plain_ctx = Context {
in_list_item: false,
..ctx.clone()
};
format_code_block(content, &[], language, &mut rendered, options, &plain_ctx);
let is_continuation = !ctx.convert_as_inline
&& !output.is_empty()
&& !crate::converter::list::utils::line_is_bare_list_marker(output);
if is_continuation {
crate::converter::trim_trailing_whitespace(output);
if !output.ends_with("\n\n") {
if output.ends_with('\n') {
output.push('\n');
} else {
output.push_str("\n\n");
}
}
}
let indent =
crate::converter::list::utils::continuation_indent_string(ctx.list_indent_columns, options).unwrap_or_default();
for (index, segment) in rendered.split_inclusive('\n').enumerate() {
let line = segment.strip_suffix('\n').unwrap_or(segment);
if line.is_empty() || (index == 0 && !is_continuation) {
output.push_str(segment);
} else {
output.push_str(&indent);
output.push_str(segment);
}
}
}
pub struct PreEnd {
offsets: Option<Rc<std::cell::RefCell<crate::converter::context::CapturedOffsets>>>,
language: Option<String>,
}
pub fn open_pre(
tag: &tl::HTMLTag,
parser: &tl::Parser,
context: &Context,
options: &ConversionOptions,
children: &mut Vec<tl::NodeHandle>,
) -> Open {
let offsets = (context.in_table_cell && options.br_in_tables).then(|| {
Rc::new(std::cell::RefCell::new(
crate::converter::context::CapturedOffsets::default(),
))
});
let code_ctx = Context {
in_code: true,
in_code_block: true,
pre_cell_break_offsets: offsets.clone(),
..context.clone()
};
children.extend(tag.children().top().iter().copied());
Open {
scope: Some(Rc::new(code_ctx)),
close: Close::Capture(CaptureEnd::Pre(PreEnd {
offsets,
language: detect_language(tag, parser),
})),
}
}
pub fn close_pre(end: &PreEnd, captured: &str, handler: HandlerContext<'_>) {
if captured.is_empty() {
return;
}
let Some(tl::Node::Tag(tag)) = handler.node_handle.get(handler.parser) else {
return;
};
#[cfg(not(feature = "visitor"))]
let _ = tag;
let content = captured.to_owned();
let language = &end.language;
let cell_break_offsets = &end.offsets;
if handler.options.code_block_style == crate::options::CodeBlockStyle::Indented
&& !handler.context.in_table_cell
&& matches!(
crate::converter::utility::siblings::previous_content_block(
handler.node_handle,
handler.parser,
handler.dom_context
),
Some("ul" | "ol")
)
{
if handler.context.in_list_item {
crate::converter::list::utils::start_block_in_list_item(handler.output, handler.context, handler.options);
} else {
separate_code_block(handler.output, handler.context);
}
handler.output.push_str("<!-- -->\n\n");
}
let offsets = cell_break_offsets
.as_ref()
.map(|offsets| offsets.borrow().positions())
.unwrap_or_default();
let segmented = (!offsets.is_empty()).then(|| content.clone());
let processed = process_pre_content(content, handler.options.whitespace_mode, false);
#[cfg(feature = "visitor")]
if let Some(custom_output) = visit_code_block(tag, language.as_deref(), &processed, &handler) {
handler.output.push_str(&custom_output);
} else {
format_code_block(
segmented.as_deref().unwrap_or(&processed),
&offsets,
language.as_deref(),
handler.output,
handler.options,
handler.context,
);
}
#[cfg(not(feature = "visitor"))]
format_code_block(
segmented.as_deref().unwrap_or(&processed),
&offsets,
language.as_deref(),
handler.output,
handler.options,
handler.context,
);
if let Some(ref collector) = handler.context.structure_collector {
collector.borrow_mut().push_code(&processed, language.as_deref());
}
}
pub fn open_line_element_in_pre(
node: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
children: &mut Vec<tl::NodeHandle>,
) -> Option<Open> {
let Some(tl::Node::Tag(tag)) = node.get(parser) else {
return None;
};
start_pre_line(output);
children.extend(tag.children().top().iter().copied());
Some(Open {
scope: None,
close: Close::PreLine,
})
}
pub fn close_line_element_in_pre(output: &mut String) {
start_pre_line(output);
}