Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit align for headers #241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ impl HtmlInterpreter {
.push(InterpreterElement::ordered_list(start_index));
}
TagName::Header(header_type) => {
let align = html::find_align(&tag.attrs);
let mut align = html::find_align(&tag.attrs);
align = self.align_or_inherit(align);
self.push_current_textbox();
self.push_spacer();
if let html::HeaderType::H1 = header_type {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: src/interpreter/tests.rs
description: " --- md\n\n\n<div align=\"center\">\n <h4>\n <a href=\"#install\">\n Install\n </a>\n <span> | </span>\n <a href=\"#usage\">\n Usage\n </a>\n </h4>\n</div>\n\n --- html\n\n<div align=\"center\">\n <h4>\n <a href=\"#install\">\n Install\n </a>\n <span> | </span>\n <a href=\"#usage\">\n Usage\n </a>\n </h4>\n</div>\n"
expression: "interpret_md_with_opts(text, opts)"
---
[
Spacer(
InvisibleSpacer(5),
),
TextBox(
TextBox {
align: Center,
is_anchor: Some("#install---------usage-"),
texts: [
Text {
text: "Install",
color: Some(Color { r: 0.09, g: 0.13, b: 1.00 }),
style: BOLD ,
link: Some("#install"),
..
},
Text {
text: " ",
default_color: Color(BLACK),
..
},
Text {
text: " | ",
default_color: Color(BLACK),
style: BOLD ,
..
},
Text {
text: " Usage",
color: Some(Color { r: 0.09, g: 0.13, b: 1.00 }),
style: BOLD ,
link: Some("#usage"),
..
},
Text {
text: " ",
default_color: Color(BLACK),
..
},
],
..
},
),
Spacer(
InvisibleSpacer(5),
),
]
15 changes: 15 additions & 0 deletions src/interpreter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ _italic_
<u>underline</u>
";

// TODO: this still has all sorts of issues (the anchor and extra whitespace)
const HEADER_INHERIT_ALIGN: &str = r##"
<div align="center">
<h4>
<a href="#install">
Install
</a>
<span> | </span>
<a href="#usage">
Usage
</a>
</h4>
</div>"##;

snapshot_interpreted_elements!(
(footnotes_list_prefix, FOOTNOTES_LIST_PREFIX),
(checklist_has_no_text_prefix, CHECKLIST_HAS_NO_TEXT_PREFIX),
Expand All @@ -362,6 +376,7 @@ snapshot_interpreted_elements!(
(horizontal_ruler, HORIZONTAL_RULER),
(small_text, SMALL_TEXT),
(text_styles, TEXT_STYLES),
(header_inherit_align, HEADER_INHERIT_ALIGN),
);

const UNDERLINE_IN_CODEBLOCK: &str = "\
Expand Down