Leave space only code spans as-is
@@ -2672,10 +2672,13 @@ impl<'a> Parser<'a> {
fn make_code_span(&mut self, open: TreeIndex, close: TreeIndex) {
let first_ix = open + 1;
let last_ix = close - 1;
+ let bytes = self.text.as_bytes();
let mut span_start = self.tree[first_ix].item.start;
let mut span_end = self.tree[close].item.start;
+ let mut buf: Option<String> = None;
- let bytes = self.text.as_bytes();
+ // detect all-space sequences, since they are kept as-is as of commonmark 0.29
+ if ! bytes[span_start..span_end].iter().all(|&b| b == b' ') {
let opening = match bytes[span_start] { b' ' | b'\r' | b'\n' => true, _ => false };
let closing = match bytes[span_end - 1] { b' ' | b'\r' | b'\n' => true, _ => false };
let drop_enclosing_whitespace = opening && closing;
@@ -2687,7 +2690,6 @@ impl<'a> Parser<'a> {
}
}
- let mut buf: Option<String> = None;
let mut ix = first_ix;
while ix < close {
@@ -2727,6 +2729,7 @@ impl<'a> Parser<'a> {
}
ix = ix + 1;
}
+ }
let cow = if let Some(buf) = buf {
buf.into()
