Unauthoritative Pronouncements

Subscribe
About

Python Markdown Tables

Third post on this. Summary: This works, and I like the table formatting a heck of a lot better than any alternative Markdown solution I've come across. All non-table text is handled by Markdown (must be installed or replaced). I also got to play with trying to embed a Gist in to Tumblr which is not any fun at all.

https://gist.github.com/3230985

2012-08-01 14:57:00

Category: text


Iterating on Better Markdown Tables

After my post yesterday I thought about it some more and decided, "I really do want these tables to look better without having to do CLI stuff."

I figured out how I wanted to loop through the document and do the selective replacements I wanted and still have Markdown that was perfectly valid for parsing.

Markdown File:

|
_**Month**
_*Day*
__Year_
|
_July
_[index.html](22)
_2012

Result:

Month

Day

Year

July

22

2012

The first version of the script did simple replacements if the line started with a "|" or "_" but this encapsulated the text in HTML tags so the Markdown characters would not evaluate when it was running through a Markdown package after the fact.

I looked up a Python Markdown package so that I could evaluate the Markdown characters per line and then encapsulate the line in the required HTML tags.

Keep in mind, I have a Bachelor of Fine Arts, so I am quite happy with myself for doing something anyone else can do better and faster. (let me have my moment)

Here is the code for doing the table loop:import markdown

Now I can put this python in to Automator and add it as a Service, or a Workflow and just easily deal with markdown I compose rather than manual work. There are some bugs with this Markdown library though. As I’ve iterated on this document I’ve seen issues with h1 and `` code not working.

2012-08-01 11:58:00

Category: text


Not a Fan of Markdown Tables | pyp

I have been tinkering with all kinds of stuff for formatting text for the past week. I’ve lost hours trying to stare at silly ways to parse text, to concatenate files, XML transforms with XSLT, pyp command strings, etc. It’s all been interesting, but everything seemed like hard work. I might as well just use Tumblr for unimportant gibberish and then just manually code my site that just hosts a demo reel, and resume since it’s really not anything I’m constantly iterating on.

The one useful thing that has come out of this is a pyp command to parse tables the way I want them parsed, and not the way Markdown wants them parsed. Tables in all the markdown variants are horrendous for anything more complicated than a small demo table with a couple cells and rows. None of them support line breaks either <br>

Example from MultiMardown’s docs:

|             |          Grouping           ||
First Header  | Second Header | Third Header |
 ------------ | :-----------: | -----------: |
Content       |          *Long Cell*        ||
Content       |   **Cell**    |         Cell |

New section   |     More      |         Data |
And more      |            And more          |

I think it’s a logical approach to handle the data like line-by-line, instead of creating weird ASCII art, or having to manually code <td>,<tr> and escaping. (Note: MMD, and other variants use spaces to control text alignment with in cells, but I think it just makes it harder to read the table at a glance. I kept all my text alignment in my CSS instead, it’s cleaner.)

My preference:

|
_Column 1 Row 1<br>Line 2
_Column 2 Row 1<br>Line 2
|
_Column 1 Row 2<br>Line 2
_Column 2 Row 2<br>Line 2

Run that text through this pyp string and you have a HTML string that can be placed in your markdown file, or in the final HTML file.
cat $FILE "| pyp ' p.startswith("_") or p.startswith("|") | p.replace("_", "<td>") + "</td>" | pp.delimit("|</td>")[1:80] | "<tr>" + p + "</tr>" | pp.oneline() | "<table border='0'>" + p + "</table>"'

Using a pyp command was quick & dirty for prototyping what I wanted. Ideally I will do this in a “proper” way at some point in the future.

Granted, tables aren’t the kind of thing that people are really interested in handling in Markdown to begin with.

2012-07-31 16:15:04

Category: text


My longest mix ever

chrisziegler:

Really pleased with how this one turned out. And if you like it, let Digitally Imported know that I should have a monthly slot on the Progressive channel. Kthx!

2012-02-04 16:01:34

Category: text


FIRST!!!!!!!!!!!!11one

So I heard about this tumblr thing (4 years ago) and decided to give this new (old) format a shot.  I have a low stamina when it comes to social platforms, so this will fail very shortly and shouldn't take up too much of your time.

I want to express my thoughts (such as they are) in more than 140 words, and I wanted to do it in a quick (slapdash) way that didn't consume space on my photography hobby blog.  I don't like to muddle things that I want to be taken seriously (and a photography blog I haven't updated in months is srs blogging).

Just know that I love you (whoever you are) and that I appreciate your eyeballs.

2012-01-04 22:43:08

Category: text