Giter Club home page Giter Club logo

markdowntables's Introduction

markdownTables - Turn HTML table syntax into Markdown

markdownTables is a simple online tool which enables you to paste in your HTML table code and convert it to Markdown table syntax.

Use it online: https://jmalarcon.github.io/markdowntables

This tool was originally created by Mark Moffat and hosted at his blog. But it disappeared It seems to be back online.

I had a local copy where I fixed a couple of bugs. Since Mark has no repo for this tool in Github, I decided to upload it to my Github space. And here we are :-)

Screen capture

markdowntables's People

Contributors

jmalarcon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

markdowntables's Issues

Rendered markdown is incorrect when table includes empty cells

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.

|1|3|
|1|2|3|

The original one had the same problem, but inserting a blank space like <td> </td> caused it to generate the correct markdown:

|1||3|
|1|2|3|

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','');
}

Caption

Seems like this doesn't support the element.

Conversion for non standard table

Currently This code is not converting non standard html (containing unequal no. of rows and column) tables to markdown tables. Although mark down doesn't support non standard table but should still be represented with empty rows or column .

For Ex -

Column1 Column2 Column3 Column4 Column5
Data1 inner Data 1
test1 test2 test3 test4
inner Data 2
test1 test2 test3 test4
test1 test2 test3 test4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.