Fix Removal of Trailing Characters on ATX Headers
This now correctly recognizes the optional ### closing sequence on ATX
headers, and removes it. Now passing 185/621 spec tests.
@@ -207,12 +207,16 @@ fn first_pass(s: &str) -> Tree<Item> {
while limit > 0 && header_text.as_bytes()[limit-1] == b' ' {
limit -= 1;
}
- while limit > 0 && header_text.as_bytes()[limit-1] == b'#' {
- limit -= 1;
+ let mut closer = limit;
+ while closer > 0 && header_text.as_bytes()[closer-1] == b'#' {
+ closer -= 1;
}
+ if closer > 0 && header_text.as_bytes()[closer-1] == b' ' {
+ limit = closer;
while limit > 0 && header_text.as_bytes()[limit-1] == b' ' {
limit -= 1;
}
+ } else if closer == 0 { limit = closer; }
if tree.cur != NIL {
tree.nodes[tree.cur].item.end = limit + header_start;
}
