Skip to content

Commit

Permalink
fix(table): table alignment wasn't reset properly (Inlyne-Project#218)
Browse files Browse the repository at this point in the history
* fix(table): table alignment wasn't reset properly

* test(table): added tests on table alignment
  • Loading branch information
Valentin271 committed Jan 21, 2024
1 parent 46caaa3 commit 5c4827e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 6 deletions.
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

0 comments on commit 5c4827e

Please sign in to comment.