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

fix(table): table alignment wasn't reset properly #218

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
10 changes: 4 additions & 6 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,12 @@ impl TokenSink for HtmlInterpreter {
}
"th" => {
self.state.text_options.bold += 1;
if let Some(align) = html::find_align(&tag.attrs) {
self.current_textbox.set_align(align);
}
let align = html::find_align(&tag.attrs);
self.current_textbox.set_align(align.unwrap_or(Align::Left));
}
"td" => {
if let Some(align) = html::find_align(&tag.attrs) {
self.current_textbox.set_align(align);
}
let align = html::find_align(&tag.attrs);
self.current_textbox.set_align(align.unwrap_or(Align::Left));
}
"table" => {
self.push_spacer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
source: src/interpreter/tests.rs
description: " --- md\n\n| left default | left forced | centered | right | left default |\n| ------------ | :---------- | :------: | ----: | ------------ |\n| text | text | text | text | text |\n\n\n --- html\n\n<table>\n<thead>\n<tr>\n<th>left default</th>\n<th align=\"left\">left forced</th>\n<th align=\"center\">centered</th>\n<th align=\"right\">right</th>\n<th>left default</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>text</td>\n<td align=\"left\">text</td>\n<td align=\"center\">text</td>\n<td align=\"right\">text</td>\n<td>text</td>\n</tr>\n</tbody>\n</table>\n"
expression: interpret_md(text)
---
[
Spacer(
InvisibleSpacer(5),
),
Table(
Table {
headers: [
TextBox {
texts: [
Text {
text: "left default",
default_color: Color(BLACK),
style: BOLD ,
..
},
],
..
},
TextBox {
texts: [
Text {
text: "left forced",
default_color: Color(BLACK),
style: BOLD ,
..
},
],
..
},
TextBox {
align: Center,
texts: [
Text {
text: "centered",
default_color: Color(BLACK),
style: BOLD ,
..
},
],
..
},
TextBox {
align: Right,
texts: [
Text {
text: "right",
default_color: Color(BLACK),
style: BOLD ,
..
},
],
..
},
TextBox {
texts: [
Text {
text: "left default",
default_color: Color(BLACK),
style: BOLD ,
..
},
],
..
},
],
rows: [
[
TextBox {
texts: [
Text {
text: "text",
default_color: Color(BLACK),
..
},
],
..
},
TextBox {
texts: [
Text {
text: "text",
default_color: Color(BLACK),
..
},
],
..
},
TextBox {
align: Center,
texts: [
Text {
text: "text",
default_color: Color(BLACK),
..
},
],
..
},
TextBox {
align: Right,
texts: [
Text {
text: "text",
default_color: Color(BLACK),
..
},
],
..
},
TextBox {
texts: [
Text {
text: "text",
default_color: Color(BLACK),
..
},
],
..
},
],
],
},
),
Spacer(
InvisibleSpacer(5),
),
]
7 changes: 7 additions & 0 deletions src/interpreter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ tags:
# Markdown h1 header
";

const ALIGNED_TABLE: &str = "\
| left default | left forced | centered | right | left default |
| ------------ | :---------- | :------: | ----: | ------------ |
| text | text | text | text | text |
";

snapshot_interpreted_elements!(
(footnotes_list_prefix, FOOTNOTES_LIST_PREFIX),
(checklist_has_no_text_prefix, CHECKLIST_HAS_NO_TEXT_PREFIX),
Expand All @@ -234,6 +240,7 @@ snapshot_interpreted_elements!(
(para_in_ordered_list, PARA_IN_ORDERED_LIST),
(code_in_ordered_list, CODE_IN_ORDERED_LIST),
(yaml_frontmatter, YAML_FRONTMATTER),
(aligned_table, ALIGNED_TABLE),
);

/// Spin up a server, so we can test network requests without external services
Expand Down