Flask Markdown Tables 🐍

The Struggle 🕳️

I was trying to use a markdown syntax to put some tables in my posts and it was just rendering the raw text 🤔

| Name  | Age |
|-------|-----|
| Alice | 24  |
| Bob   | 19  |
| Charlie | 32 |

Let the googling ensue. But, I was running into brick wall 🧱 after brick wall. Variations on syntax, put an empty line, don't put an empty line etc ♾️.

Solution 🧮

Turns out that the markdown plugin Flask needs an extension to render tables. Once you know you know 🧠.

Easy as Pie 🥧

Now it is as simple as telling your markdown renderer to use the tables extension. Just add

1
    FLATPAGES_MARKDOWN_EXTENSIONS=['codehilite', 'tables'],

to your app.config and you are good to go 🚀. like so:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    app.config.from_mapping(
        SECRET_KEY='dev',
        FLATPAGES_ROOT='pages',
        FLATPAGES_EXTENSION='.md',
        FLATPAGES_MARKDOWN_EXTENSIONS=['codehilite', 'tables'],
        FLATPAGES_EXTENSION_CONFIGS = {
            'codehilite': {
                'linenums': 'True'
            }
        }
    )

for example 🐍. Now we can render tables easy as pie 🥧:

Name Age
Alice 24
Bob 19
Charlie 32

woot; 🎉

📨 Contact GSPC ✉️

ITIL 4 Foundation Certified AWS Certified Cloud Practitioner Certified Terraform Associate AWS Serverless AWS Certified Developer Associate GitHub Foundations Certification GitHub Actions Certification Certified SysOps Administrator Certified AWS Security Specialist Certified AWS DevOps Engineer Professional GCP: Cloud Digital Leader Certification Badge Solutions Architect Associate Solutions Architect Professional Certified AWS AI Practitioner