use crate::clean::RenderedLink;
use crate::doctest;
use crate::html::escape::Escape;
+use crate::html::format::Buffer;
use crate::html::highlight;
use crate::html::toc::TocBuilder;
html, BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag,
};
-use super::format::Buffer;
-
#[cfg(test)]
mod tests;
let mut stopped_early = false;
fn push(s: &mut String, text_length: &mut usize, text: &str) {
- s.push_str(text);
+ write!(s, "{}", Escape(text)).unwrap();
*text_length += text.len();
}
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
t("dud [link]", "dud [link]");
t("code `let x = i32;` ...", "code <code>let x = i32;</code> …");
- t("type `Type<'static>` ...", "type <code>Type<'static></code> …");
+ t("type `Type<'static>` ...", "type <code>Type<'static></code> …");
+ // Test to ensure escaping and length-limiting work well together.
+ // The output should be limited based on the input length,
+ // rather than the output, because escaped versions of characters
+ // are usually longer than how the character is actually displayed.
+ t(
+ "& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &",
+ "& & & & & & & & & & & & \
+ & & & & & & & & & & & & \
+ & & & & & …",
+ );
t("# top header", "top header");
t("# top header\n\nfollowed by a paragraph", "top header");
t("## header", "header");