mirror of
https://github.com/lexmount/moli.git
synced 2026-10-09 08:01:05 +00:00
Revert "Separate adjacent Markdown code spans"
This reverts commit fcc1c20576.
This commit is contained in:
@@ -176,13 +176,10 @@ impl<'a> Writer<'a> {
|
||||
if text.is_empty() {
|
||||
return;
|
||||
}
|
||||
// Adjacent code elements are distinct inline values. A separator is
|
||||
// required in Markdown; otherwise their code-span delimiters touch and
|
||||
// the rendered text is indistinguishable from one joined value.
|
||||
// Adjacent code elements have separate HTML nodes but no text between
|
||||
// them. Markdown code spans would merge or need an invented space.
|
||||
if self.code.is_some() {
|
||||
self.flush_code();
|
||||
self.output.push(' ');
|
||||
self.line_digits = None;
|
||||
self.flush_code_html();
|
||||
}
|
||||
if preformatted {
|
||||
if !text.is_empty() {
|
||||
@@ -460,6 +457,25 @@ impl<'a> Writer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn flush_code_html(&mut self) {
|
||||
if let Some(code) = self.code.take() {
|
||||
self.output.push_str("<code>");
|
||||
for ch in code.chars() {
|
||||
match ch {
|
||||
'&' => self.output.push_str("&"),
|
||||
'<' => self.output.push_str("<"),
|
||||
'>' => self.output.push_str(">"),
|
||||
'\\' | '`' | '*' | '_' | '[' | ']' | '|' | '~' => {
|
||||
self.output.push('\\');
|
||||
self.output.push(ch);
|
||||
}
|
||||
_ => self.output.push(ch),
|
||||
}
|
||||
}
|
||||
self.output.push_str("</code>");
|
||||
self.line_digits = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_punctuation(ch: char) -> bool {
|
||||
|
||||
@@ -156,7 +156,7 @@ fn keeps_adjacent_code_elements_distinct_and_chooses_safe_delimiters() {
|
||||
dom.text(0, "after");
|
||||
assert_eq!(
|
||||
rendered_html(&convert(&dom, 0)),
|
||||
"<p><code>a`</code> <code>`b</code> <code>`</code> after</p>\n"
|
||||
"<p><code>a`</code><code>`b</code> <code>`</code> after</p>\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,10 +147,9 @@ fn normal_code_moves_unicode_boundary_spaces_outside_delimiters() {
|
||||
#[test]
|
||||
fn adjacent_code_elements_keep_distinct_values() {
|
||||
let html = "<div><code>name</code><code>string</code></div>";
|
||||
assert_eq!(markdown(html, false), "`name` `string`");
|
||||
assert_eq!(
|
||||
rendered_html(&markdown(html, false)),
|
||||
"<p><code>name</code> <code>string</code></p>\n"
|
||||
"<p><code>name</code><code>string</code></p>\n"
|
||||
);
|
||||
assert_eq!(
|
||||
markdown("<code>first</code>suffix<code>second</code>", false),
|
||||
@@ -166,7 +165,7 @@ fn empty_code_between_values_does_not_join_or_invent_code_text() {
|
||||
let result = markdown(&source, preformatted);
|
||||
assert_eq!(
|
||||
rendered_html(&result),
|
||||
"<p><code>name</code> <code>string</code></p>\n",
|
||||
"<p><code>name</code><code>string</code></p>\n",
|
||||
"{source}, preformatted={preformatted}: {result}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user