Hi, thanks for uploading this. It's nice to have a place to suggest fixes.
I noticed a bug with the rendered markdown that existed in the original page, albeit slightly different.
In your script, an empty cell like this:
<table>
<tr><td>1</td><td></td><td>3</td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
</table>
Generates markdown that is missing that column.
The original one had the same problem, but inserting a blank space like <td> </td>
caused it to generate the correct markdown:
I'm assuming it has to do with this block:
// if there is a thead we append
$(html).find('thead > tr > td').each(function() {
if(fixText($(this).text()) != ""){
table_header = table_header + fixText($(this).text()) + "|";
table_header_footer = table_header_footer + "--- |";
table_header_found = true;
}
});
Which may have looked like this in the original:
// if there is a thead we append
$(html).find('thead > tr > td').each(function() {
if($(this).text() != ""){
table_header = table_header + $(this).text() + "|";
table_header_footer = table_header_footer + "--- |";
table_header_found = true;
}
});
Do you think this would work? It allows for an empty cell.
// if there is a thead we append
$(html).find('thead > tr > td').each(function() {
var fixedText = fixText($(this).text());
if($(this).text() == "" || fixedText != ""){
table_header = table_header + fixText($(this).text()) + "|";
table_header_footer = table_header_footer + "--- |";
table_header_found = true;
}
});
Or since the original one seemed to generate the correct markdown even if the table cell had multiple spaces in it, perhaps just don't "fix" those:
function fixText(text){
//Remove tabs (it's HTML, sothey don't affect, but in Markdown, they do.)
return text.trim().replace('\t','');
}