58 lines
1.8 KiB
Rust
58 lines
1.8 KiB
Rust
|
|
//! Cluster 7 — Markdown-style alignment markers on the header
|
||
|
|
//! separator row (`|:--|--:|:--:|`) propagate to the AST and HTML.
|
||
|
|
|
||
|
|
use nuwiki_core::ast::{BlockNode, TableAlign};
|
||
|
|
use nuwiki_core::render::{HtmlRenderer, Renderer};
|
||
|
|
use nuwiki_core::syntax::vimwiki::VimwikiSyntax;
|
||
|
|
use nuwiki_core::syntax::SyntaxPlugin;
|
||
|
|
|
||
|
|
fn parse(src: &str) -> nuwiki_core::ast::DocumentNode {
|
||
|
|
VimwikiSyntax::new().parse(src)
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn separator_row_with_no_anchors_yields_defaults() {
|
||
|
|
let doc = parse("| h1 | h2 |\n|----|----|\n| a | b |\n");
|
||
|
|
let table = match &doc.children[0] {
|
||
|
|
BlockNode::Table(t) => t,
|
||
|
|
_ => panic!("expected table"),
|
||
|
|
};
|
||
|
|
assert_eq!(
|
||
|
|
table.alignments,
|
||
|
|
vec![TableAlign::Default, TableAlign::Default]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn left_right_center_anchors_parsed() {
|
||
|
|
let doc = parse("| a | b | c |\n|:---|---:|:---:|\n| 1 | 2 | 3 |\n");
|
||
|
|
let table = match &doc.children[0] {
|
||
|
|
BlockNode::Table(t) => t,
|
||
|
|
_ => panic!("expected table"),
|
||
|
|
};
|
||
|
|
assert_eq!(
|
||
|
|
table.alignments,
|
||
|
|
vec![TableAlign::Left, TableAlign::Right, TableAlign::Center]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn html_renderer_emits_text_align_style() {
|
||
|
|
let doc = parse("| a | b | c |\n|:---|---:|:---:|\n| 1 | 2 | 3 |\n");
|
||
|
|
let out = HtmlRenderer::new().render_to_string(&doc).unwrap();
|
||
|
|
assert!(
|
||
|
|
out.contains(r#"<th style="text-align: left;"> a </th>"#),
|
||
|
|
"got: {out}"
|
||
|
|
);
|
||
|
|
assert!(out.contains(r#"<th style="text-align: right;"> b </th>"#));
|
||
|
|
assert!(out.contains(r#"<th style="text-align: center;"> c </th>"#));
|
||
|
|
assert!(out.contains(r#"<td style="text-align: left;"> 1 </td>"#));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn render_without_alignment_omits_style_attr() {
|
||
|
|
let doc = parse("| a | b |\n|---|---|\n| 1 | 2 |\n");
|
||
|
|
let out = HtmlRenderer::new().render_to_string(&doc).unwrap();
|
||
|
|
assert!(!out.contains("text-align"));
|
||
|
|
}
|