-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render Markdown on the text terminal output #2559
Comments
For the specific case of rendering tables, we could use box-drawing characteres as was often used on MS-DOS programs like this: Maybe with some python code equivalent to this: |
+1 for fontbakery reminding me of Rogue |
I took some free time this weekend to experiment with this funny idea. I got the following markdown table from our
|
How do you access this hinting impact check Felipe? |
https://font-bakery.readthedocs.io/en/latest/fontbakery/profiles/googlefonts.html#com.google.fonts/check/hinting_impact
Em dom, 23 de jun de 2019 13:44, Chris Simpkins <notifications@github.com>
escreveu:
… How do you access this hinting impact check Felipe?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2559>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABUFLE4FZMVX75PWXEOKITP36R65ANCNFSM4H2TVEPA>
.
|
@aurium, here's the issue describing the markdown table parsing/rendering task I'll look for the table drawing routines in my hard-drive and post them here soon |
here's an early prototype. Feel free to reuse this code in a pull request: def hinting_impact(font, ttfautohint_stats):
"""Show hinting filesize impact.
Current implementation simply logs useful info
but there's no fail scenario for this checker."""
hinted = ttfautohint_stats["hinted_size"]
dehinted = ttfautohint_stats["dehinted_size"]
increase = hinted - dehinted
change = (float(hinted)/dehinted - 1) * 100
def filesize_formatting(s):
if s < 1024:
return f"{s} bytes"
elif s < 1024*1024:
return "{:.1f}kb".format(s/1024)
else:
return "{:.1f}Mb".format(s/(1024*1024))
hinted_size = filesize_formatting(hinted)
dehinted_size = filesize_formatting(dehinted)
increase = filesize_formatting(increase)
results_table = "Hinting filesize impact:\n\n"
results_table += f"| | {font} |\n"
results_table += "|:--- | ---:|\n"
results_table += f"| Dehinted Size | {dehinted_size} |\n"
results_table += f"| Hinted Size | {hinted_size} |\n"
results_table += f"| Increase | {increase} |\n"
results_table += f"| Change | {change:.1f} % |\n"
return results_table
def add_border(buf, width, height):
#top border
newbuf = u"\u2554" + (width-2)*u"\u2550" + u"\u2557\n"
#content
for line in buf.split('\n'):
newbuf += u"\u2551" + line + " "*max(0, width - len(line) - 2) + u"\u2551\n"
#whitespace
for i in range(max(0, height - len(buf.split('\n')) -2)):
newbuf += u"\u2551" + " "*(width-2) + u"\u2551\n"
#bottom border
newbuf += u"\u255A" + (width-2)*u"\u2550" + u"\u255D\n"
return newbuf
def padded(widths, cells):
padded_cells = []
for i, cell in enumerate(cells):
padded_cells.append(cell + " "*max(0, widths[i]-len(cell)))
return padded_cells
def render_table(lines):
table = []
widths = []
for line in lines:
cells = line.split("|")
cells.pop(0)
cells.pop(-1)
table.append(cells)
for i, cell in enumerate(cells):
if i >= len(widths):
widths.append(len(cell))
else:
widths[i] = max(widths[i], len(cell))
# compute total table width:
width = len(widths) + 1
for w in widths:
width += w
#top border
newbuf = u"\u2554" + u"\u2564".join([w*u"\u2550" for w in widths]) + u"\u2557\n"
#header
newbuf += u"\u2551" + u"\u2502".join(padded(widths, table[0])) + u"\u2551\n"
#header separator
newbuf += u"\u255F" + u"\u253C".join([w*u"\u2500" for w in widths]) + u"\u2562\n"
#table body
for i in range(2,len(table)):
newbuf += u"\u2551" + u"\u2502".join(padded(widths, table[i])) + u"\u2551\n"
#bottom border
newbuf += u"\u255A" + u"\u2567".join([w*u"\u2550" for w in widths]) + u"\u255D\n"
return newbuf
def render_markdown(buf):
new_buf=""
table_lines = []
for line in buf.split('\n'):
if '|' in line:
table_lines.append(line)
else:
if table_lines:
new_buf += render_table(table_lines)
table_lines = []
new_buf += line + "\n"
return new_buf
stats = {
'hinted_size': 22345,
'dehinted_size': 12345,
}
input_str = hinting_impact("Foo-Regular.ttf", stats)
output = render_markdown(input_str)
print (input_str)
print (add_border(output, 80, 20)) |
Hi folks, I'm working on this, and i think makes sense to parse status messages as MD and I just make a MD Table parser to work with However, I will be happy to know what kind of vertical separator you prefer. I'm putting 3 options below and you can vote with 👍 or 👎 emoji reaction on the comment top-right corner. (Hey, sure, you can comment against my beliefs if you disagree. I'm open to listen.) |
it would be nice to use Markdown syntax for everything and then render it into something more beautiful than what we get now in cases like this:
The text was updated successfully, but these errors were encountered: