> Besides, isn't markdown supposed to be a superset of HTML?  
>

You can think of markdown as a *sub*set of HTML.  You won't be able to use 
the specify the width, like in your example and if you have merged cells 
you won't be able to duplicate it using Markdown.  There was some initial 
work on a library that would support Latex and HTML tables a couple years 
back (https://github.com/takluyver/tabipy) but it's a complicated process 
trying to support two separate encodings with all the different 
approaches.  The automatic conversion of HTML tables to Latex is something 
I've wanted to be added to nbconvert for a long time but I've never found 
the time to write a converter.

With regards to converting HTML tables to Markdown, if you're tables are 
simple enough to use Markdown then you can use a Python script to partially 
automate the conversion.

In a new cell copy the HTML copy for one of your tables and assign it to 
the variable txt in the code below and you should be able to create a 
Markdown table equivalent.  Admittedly this code only works with clean, 
simple HTML tables.  Also, if you are not familiar with regular expressions 
and would like to try to improve the code you can check out 
http://regexr.com/. 

import re

txt = """your table code
more of your table code
"""

rows = re.compile(r'(?:<tr>)(.?)(?:</tr>)')
headers = re.compile(r'(?:<th>)(.*?)(?:</th>)')
cells = re.compile(r'(?:<td>)(.?)(?:</td>)')

table_data = []
table_text = txt.replace('\n','')
for row in rows.findall(table_text):
    row_content = headers.findall(row)
    if len(row_content)==0:
       row_content = cells.findall(row)
    table_data.append(row_content)

markdown_text = ''
for index, row in enumerate(table_data):
    markdown_text += '|'+'|'.join(row)+'|\n'
    if index == 0:
        markdown_text+='|'+'|'.join(['----']*len(row))+'|\n'
print(markdown_text)

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/62e499b1-5631-4fa5-b7cd-ded9305c32f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to