Last active
March 18, 2018 13:17
-
-
Save philgruneich/9296884 to your computer and use it in GitHub Desktop.
Scripts to simplify the syntax for MultiMarkdown tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
table = '''First Header,Second Header,Third Header | |
1st Item,2nd\,Item,3rd Item | |
,One cell,Two cells | |
Two cells,One cell, | |
Awesome''' | |
ttable = [[re.sub('\\\,',',',cell) for cell in re.split('(?<!\\\),', row)] for row in table.split('\n')] | |
columnCount = len(ttable[0]) | |
barCount = columnCount + 1 | |
headerSeparator = '|:-' * columnCount + '|' | |
ttable2 = ['|' + '|'.join([cell.rstrip() if cell != ' ' else cell for cell in row]) + '|' for row in ttable] | |
for row in enumerate(ttable2): | |
rowCount = row[1].count('|') | |
if rowCount < barCount: | |
ttable2[row[0]]+='|' * (barCount - rowCount) | |
ttable2.insert(1, headerSeparator) | |
print '\n'.join(ttable2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
import webbrowser | |
import urllib | |
table = sys.argv[1] | |
ttable = [[re.sub('\\\,',',',cell) for cell in re.split('(?<!\\\),', row)] for row in table.split('\n')] | |
columnCount = len(ttable[0]) | |
barCount = columnCount + 1 | |
headerSeparator = '|:-' * columnCount + '|' | |
ttable2 = ['|' + '|'.join([cell.rstrip() if cell != ' ' else cell for cell in row]) + '|' for row in ttable] | |
for row in enumerate(ttable2): | |
rowCount = row[1].count('|') | |
if rowCount < barCount: | |
ttable2[row[0]]+='|' * (barCount - rowCount) | |
ttable2.insert(1, headerSeparator) | |
callback = 'drafts://x-callback-url/create?text=%s' % urllib.quote('\n'.join(ttable2)) | |
webbrowser.open(callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
table = '''First Header Second Header Third Header | |
1st Item 2nd Item 3rd Item | |
One cell Two cells | |
Two cells One cell | |
Awesome''' | |
ttable = [re.split('(?<=\s)\s', row) for row in table.split('\n')] | |
columnCount = len(ttable[0]) | |
barCount = columnCount + 1 | |
headerSeparator = '|:-' * columnCount + '|' | |
ttable2 = ['|' + '|'.join([cell.rstrip() for cell in row]) + '|' for row in ttable] | |
for row in enumerate(ttable2): | |
rowCount = row[1].count('|') | |
if rowCount < barCount: | |
ttable2[row[0]]+='|' * (barCount - rowCount) | |
ttable2.insert(1, headerSeparator) | |
print '\n'.join(ttable2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment