Skip to content

Commit

Permalink
Add test for wikilinks in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalmoksha committed May 15, 2024
1 parent 653471f commit d2002f3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/tests/commonmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ fn math(markdown: &str, cm: &str) {

commonmark(markdown, cm, Some(&options));
}

#[test_case("This [[url]] that", "This [[url]] that\n")]
#[test_case("This [[url|link label]] that", "This [[url|link label]] that\n")]
fn wikilinks(markdown: &str, cm: &str) {
let mut options = Options::default();
options.extension.wikilinks_title_before_pipe = true;

commonmark(markdown, cm, Some(&options));
}
82 changes: 82 additions & 0 deletions src/tests/wikilinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,88 @@ fn wikilinks_supercedes_relaxed_autolinks() {
);
}

#[test]
fn wikilinks_only_url_in_tables() {
html_opts!(
[extension.wikilinks_title_after_pipe, extension.table],
concat!("| header |\n", "| ------- |\n", "| [[url]] |\n",),
concat!(
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>header</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td><a href=\"url\" data-wikilink=\"true\">url</a></td>\n",
"</tr>\n",
"</tbody>\n",
"</table>\n",
),
);

html_opts!(
[extension.wikilinks_title_before_pipe, extension.table],
concat!("| header |\n", "| ------- |\n", "| [[url]] |\n",),
concat!(
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>header</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td><a href=\"url\" data-wikilink=\"true\">url</a></td>\n",
"</tr>\n",
"</tbody>\n",
"</table>\n",
),
);
}

#[test]
fn wikilinks_full_in_tables_not_supported() {
html_opts!(
[extension.wikilinks_title_after_pipe, extension.table],
concat!("| header |\n", "| ------- |\n", "| [[url|link label]] |\n",),
concat!(
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>header</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td>[[url</td>\n",
"</tr>\n",
"</tbody>\n",
"</table>\n",
),
);

html_opts!(
[extension.wikilinks_title_before_pipe, extension.table],
concat!("| header |\n", "| ------- |\n", "| [[link label|url]] |\n",),
concat!(
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>header</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td>[[link label</td>\n",
"</tr>\n",
"</tbody>\n",
"</table>\n",
),
);
}

#[test]
fn wikilinks_exceeds_label_limit() {
let long_label = format!("[[{:b<1100}]]", "a");
Expand Down

0 comments on commit d2002f3

Please sign in to comment.