Wrap tables in an overflow-x wrapper div

This commit is contained in:
Jade 2021-07-30 01:11:36 -07:00 committed by Jade Lovelace
parent fde88c22a8
commit 85df785cd3
2 changed files with 22 additions and 1 deletions

View File

@ -31,6 +31,11 @@ code {
word-break: break-word; word-break: break-word;
} }
/* make wide tables scroll if they overflow */
.table-wrapper {
overflow-x: auto;
}
/* Don't change font size in headers. */ /* Don't change font size in headers. */
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
font-size: unset; font-size: unset;

View File

@ -177,12 +177,28 @@ pub fn render_markdown_with_path(text: &str, curly_quotes: bool, path: Option<&P
let p = new_cmark_parser(text, curly_quotes); let p = new_cmark_parser(text, curly_quotes);
let events = p let events = p
.map(clean_codeblock_headers) .map(clean_codeblock_headers)
.map(|event| adjust_links(event, path)); .map(|event| adjust_links(event, path))
.flat_map(|event| {
let (a, b) = wrap_tables(event);
a.into_iter().chain(b)
});
html::push_html(&mut s, events); html::push_html(&mut s, events);
s s
} }
/// Wraps tables in a `.table-wrapper` class to apply overflow-x rules to.
fn wrap_tables(event: Event<'_>) -> (Option<Event<'_>>, Option<Event<'_>>) {
match event {
Event::Start(Tag::Table(_)) => (
Some(Event::Html(r#"<div class="table-wrapper">"#.into())),
Some(event),
),
Event::End(Tag::Table(_)) => (Some(event), Some(Event::Html(r#"</div>"#.into()))),
_ => (Some(event), None),
}
}
fn clean_codeblock_headers(event: Event<'_>) -> Event<'_> { fn clean_codeblock_headers(event: Event<'_>) -> Event<'_> {
match event { match event {
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(ref info))) => { Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(ref info))) => {