Repository navigation
Fix tables - #57
Fix tables#57
Conversation
This commit likely introduces an anti-pattern change? I think we should not expose the whole converter to the element handlers, because these functions previously had only minimal dependencies. |
|
Thanks for your feedback! The rationale for this change comes from the requirement to support inline Markdown in tables; without passing Code blocks and lists represent a simpler case: In contrast, the "tr" => {
// If no thead is found, use the first row as headers
if !has_thead && headers.is_empty() {
headers = extract_row_cells(&child, "th", element.html_to_markdown);
if headers.is_empty() {
let cells =
extract_row_cells(&child, "td", element.html_to_markdown);
if !cells.is_empty() {
headers = cells;
}
}
has_thead = !headers.is_empty();
} else {
let row_cells =
extract_row_cells(&child, "td", element.html_to_markdown);
if !row_cells.is_empty() {
rows.push(row_cells);
}
}
}Inside fn extract_row_cells(
row_node: &Rc<markup5ever_rcdom::Node>,
cell_tag: &str,
html_to_markdown: &HtmlToMarkdown,
) -> Vec<String> {
let mut cells = Vec::new();
for cell_node in get_node_children(row_node) {
if let NodeData::Element { name, .. } = &cell_node.data
&& name.local.as_ref() == cell_tag
{
let cell_content = get_node_content(&cell_node, html_to_markdown)
.trim()
.to_string();
cells.push(cell_content);
}
}
cells
} |
|
Another thought: the current approach for the |
|
Oh, I see, the current design doesn't allow us to easily get the markdown of a child node in the handler. Perhaps we can keep the signature of these functions for now and call walk_node directly in the table handler. We should have a better API for this, later. |
Good idea. |
That's a good idea. The challenges here are in what the code knows during the traversal. Thoughts on this:
But this is a sizable rewrite; for now, I'm happy with the current implementation. |
|
Agreed, merging these changes now. |
|
Thanks! |
Tables can include inline markdown; these changes add support for this feature.