Skip to content

A platform for community discussion. Free, open, simple.

FIX: `HtmlToMarkdown` didn't support `tfoot` in tables

Gerhard Schlagerb01905c7244a
diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb
index eff00c66341..1dbcf2b3b4f 100644
--- a/lib/html_to_markdown.rb
+++ b/lib/html_to_markdown.rb
@@ -220,7 +220,7 @@ class HtmlToMarkdown
"\n\n#{traverse(node)}\n\n"
end
- TRAVERSABLES ||= %w[aside font span thead tbody tfooter u]
+ TRAVERSABLES ||= %w[aside font span thead tbody tfoot u]
TRAVERSABLES.each { |tag| define_method("visit_#{tag}") { |node| traverse(node) } }
def visit_tt(node)
diff --git a/spec/lib/html_to_markdown_spec.rb b/spec/lib/html_to_markdown_spec.rb
index 51aac6c3659..a26f8f2313a 100644
--- a/spec/lib/html_to_markdown_spec.rb
+++ b/spec/lib/html_to_markdown_spec.rb
@@ -527,6 +527,14 @@ RSpec.describe HtmlToMarkdown do
<td>line</td>
</tr>
</tbody>
+ <tfoot>
+ <tr>
+ <td>This</td>
+ <td>is</td>
+ <td>the</td>
+ <td>footer</td>
+ </tr>
+ </tfoot>
</table>
HTML
@@ -535,6 +543,7 @@ RSpec.describe HtmlToMarkdown do
| - | - | - | - |
| I am | the | **first** | row |
| And this | is the | 2<sup>nd</sup> | line |
+ | This | is | the | footer |
MD
expect(html_to_markdown(html)).to eq(markdown.strip)
@@ -565,24 +574,24 @@ RSpec.describe HtmlToMarkdown do
<table>
<tr>
<th>
-
+
1
-
+
</th>
<th>
-
+
2
-
+
</th>
<th>
-
+
3
-
+
</th>
<th>
-
+
4
-
+
</th>
</tr>
<tr>
@@ -592,12 +601,12 @@ RSpec.describe HtmlToMarkdown do
</td>
<td>
-
+
**Two**
</td>
<td>
-
+
Three
</td>
@@ -625,14 +634,14 @@ RSpec.describe HtmlToMarkdown do
<table>
<tr>
<th>
-
+
1
-
+
</th>
<th>
-
+
2
-
+
</th>
</tr>
<tr>
@@ -671,31 +680,31 @@ RSpec.describe HtmlToMarkdown do
<th>
1
-
+
</th>
<th>
-
+
2
-
+
</th>
</tr>
<tr>
<td>
A
-
+
</td>
<td rowspan="2">
-
+
B
-
+
</td>
</tr>
<tr>
<td>
-
+
C
-
+
</td>
</tr>
</table>