Skip to content

Commit 52760d4

Browse files
committed
add class-name directly in the table tag
1 parent 391c4ac commit 52760d4

2 files changed

Lines changed: 8 additions & 27 deletions

File tree

ext/markdown_it_ruby/src/extensions/table_decoration.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
use crate::driver::MarkdonwItOptions;
22
use markdown_it::parser::core::CoreRule;
33
use markdown_it::plugins::extra::tables::Table;
4-
use markdown_it::{MarkdownIt, Node, NodeValue, Renderer};
4+
use markdown_it::{MarkdownIt, Node};
55

66
#[derive(Debug)]
7-
pub struct TableDecoration {
8-
pub table: Table,
9-
pub class_name: String,
10-
}
11-
12-
impl NodeValue for TableDecoration {
13-
fn render(&self, node: &Node, fmt: &mut dyn Renderer) {
14-
let class_name = self.class_name.clone();
15-
let div_attrs = vec![("class", class_name)];
16-
fmt.open("div", &div_attrs);
17-
fmt.cr();
18-
self.table.render(node, fmt);
19-
fmt.cr();
20-
fmt.close("div");
21-
}
22-
}
23-
247
struct TableDecorationRule;
258

269
impl CoreRule for TableDecorationRule {
@@ -33,12 +16,10 @@ impl CoreRule for TableDecorationRule {
3316
};
3417
root.walk_mut(|node, _| {
3518
if let Some(table) = node.cast::<Table>() {
36-
node.replace(TableDecoration {
37-
table: Table {
38-
alignments: table.alignments.clone(),
39-
},
40-
class_name: table_class_name.clone(),
41-
})
19+
node.replace(Table {
20+
alignments: table.alignments.clone(),
21+
});
22+
node.attrs = vec![("class", table_class_name.clone())];
4223
}
4324
});
4425
}
@@ -65,7 +46,7 @@ fn test_table_decoration() {
6546

6647
assert_eq!(
6748
html,
68-
"<div class=\"table\">\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">左寄せタイトル</th>\n<th style=\"text-align:center\">センタリング</th>\n<th style=\"text-align:right\">右寄せタイトル</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\">column</td>\n<td style=\"text-align:center\">column</td>\n<td style=\"text-align:right\">column</td>\n</tr>\n</tbody>\n</table>\n</div>"
49+
"<table class=\"table\">\n<thead>\n<tr>\n<th style=\"text-align:left\">左寄せタイトル</th>\n<th style=\"text-align:center\">センタリング</th>\n<th style=\"text-align:right\">右寄せタイトル</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\">column</td>\n<td style=\"text-align:center\">column</td>\n<td style=\"text-align:right\">column</td>\n</tr>\n</tbody>\n</table>\n"
6950
)
7051
}
7152

@@ -82,7 +63,7 @@ fn test_table_decoration() {
8263

8364
assert_eq!(
8465
html,
85-
"<div class=\"custom-table-class-name\">\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">左寄せタイトル</th>\n<th style=\"text-align:center\">センタリング</th>\n<th style=\"text-align:right\">右寄せタイトル</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\">column</td>\n<td style=\"text-align:center\">column</td>\n<td style=\"text-align:right\">column</td>\n</tr>\n</tbody>\n</table>\n</div>"
66+
"<table class=\"custom-table-class-name\">\n<thead>\n<tr>\n<th style=\"text-align:left\">左寄せタイトル</th>\n<th style=\"text-align:center\">センタリング</th>\n<th style=\"text-align:right\">右寄せタイトル</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\">column</td>\n<td style=\"text-align:center\">column</td>\n<td style=\"text-align:right\">column</td>\n</tr>\n</tbody>\n</table>\n"
8667
)
8768
}
8869
}

spec/markdown_it_ruby_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
let(:expected_output) { File.read('spec/fixtures/dummy_output.html') }
3131

3232
it 'converts markdown content to html' do
33-
expect(subject).to match(expected_output)
33+
expect(subject).to eq(expected_output)
3434
end
3535
end
3636
end

0 commit comments

Comments
 (0)