11use crate :: driver:: MarkdonwItOptions ;
22use markdown_it:: parser:: core:: CoreRule ;
33use 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-
247struct TableDecorationRule ;
258
269impl 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}
0 commit comments