Skip to content

Commit

Permalink
Handle blockquotes in first table column (#156)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Feb 29, 2024
1 parent a77f280 commit e8f151d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/rst2rfcxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,19 @@ rst2rfcxml::output_table_row(ostream& output_stream)
_table_cell_rst.clear();
}

bool
rst2rfcxml::is_cell_blank(string current, int column)
{
size_t start_column = _column_indices[column];
size_t end_column = (_column_indices.size() > (column + 1)) ? _column_indices[column + 1] : current.size();
for (size_t i = start_column; i < end_column && i < current.size(); i++) {
if (!isspace(current[i])) {
return false;
}
}
return true;
}

// Perform table handling.
// Returns true if a valid table line was processed, false if it's not a table line.
bool
Expand Down Expand Up @@ -746,7 +759,7 @@ rst2rfcxml::handle_table_line(string current, string next, ostream& output_strea
// Each line of text starts a new row, except when there is a blank cell in the first column.
// In that case, that line of text is parsed as a continuation line.
size_t start_column = _column_indices[0];
bool new_row = (current.length() > start_column) && !isspace(current[start_column]);
bool new_row = (current.length() > start_column) && !is_cell_blank(current, 0);

if (new_row && !_table_cell_rst.empty()) {
// Output previous row which is now complete.
Expand Down
2 changes: 2 additions & 0 deletions lib/rst2rfcxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class rst2rfcxml
bool
handle_variable_initializations(std::string line);
bool
is_cell_blank(std::string current, int column);
bool
handle_table_line(std::string current, std::string next, std::ostream& output_stream);
bool
handle_title_line(std::string current, std::string next, std::ostream& output_stream);
Expand Down
61 changes: 61 additions & 0 deletions test/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,67 @@ Bar Another example
)");
}

TEST_CASE("table centered", "[basic]")
{
test_rst2rfcxml(
R"(
====== ===== ==============================================
source value description
====== ===== ==============================================
K 0 use 32-bit 'imm' value as source operand
X 1 use 'src_reg' register value as source operand
====== ===== ==============================================
)",
R"(<table>
<thead>
<tr>
<th>source</th>
<th>value</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<blockquote>
K
</blockquote>
</td>
<td>
<blockquote>
0
</blockquote>
</td>
<td>
<t>
use 32-bit 'imm' value as source operand
</t>
</td>
</tr>
<tr>
<td>
<blockquote>
X
</blockquote>
</td>
<td>
<blockquote>
1
</blockquote>
</td>
<td>
<t>
use 'src_reg' register value as source operand
</t>
</td>
</tr>
</tbody>
</table>
)");
}

TEST_CASE("table with literal cell", "[basic]")
{
test_rst2rfcxml(
Expand Down

0 comments on commit e8f151d

Please sign in to comment.