Skip to content

Commit

Permalink
Merge pull request #61 from brson/nested-tables
Browse files Browse the repository at this point in the history
Fix parsing of tables nested in other block elements
  • Loading branch information
Ashe Connor authored Apr 30, 2018
2 parents 7151c60 + b05c6d7 commit 4b2d20d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn try_opening_row<'a, 'o>(
if parser.blank {
return None;
}
let this_row = row(line).unwrap();
let this_row = row(&line[parser.first_nonspace..]).unwrap();
let new_row = parser.add_child(
container,
NodeValue::TableRow(false),
Expand Down
91 changes: 91 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,94 @@ fn smart_chars() {
|opts| opts.smart = true,
);
}

#[test]
fn nested_tables_1() {
html_opts(
concat!(
"- p\n",
"\n",
" |a|b|\n",
" |-|-|\n",
" |c|d|\n",
),
concat!(
"<ul>\n",
"<li>\n",
"<p>p</p>\n",
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>a</th>\n",
"<th>b</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td>c</td>\n",
"<td>d</td>\n",
"</tr></tbody></table>\n",
"</li>\n",
"</ul>\n",
),
|opts| opts.ext_table = true,
);
}

#[test]
fn nested_tables_2() {
html_opts(
concat!(
"- |a|b|\n",
" |-|-|\n",
" |c|d|\n",
),
concat!(
"<ul>\n",
"<li>\n",
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>a</th>\n",
"<th>b</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td>c</td>\n",
"<td>d</td>\n",
"</tr></tbody></table>\n",
"</li>\n",
"</ul>\n",
),
|opts| opts.ext_table = true,
);
}

#[test]
fn nested_tables_3() {
html_opts(
concat!(
"> |a|b|\n",
"> |-|-|\n",
"> |c|d|\n",
),
concat!(
"<blockquote>\n",
"<table>\n",
"<thead>\n",
"<tr>\n",
"<th>a</th>\n",
"<th>b</th>\n",
"</tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr>\n",
"<td>c</td>\n",
"<td>d</td>\n",
"</tr></tbody></table>\n",
"</blockquote>\n",
),
|opts| opts.ext_table = true,
);
}

0 comments on commit 4b2d20d

Please sign in to comment.