-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathlektor_markdown_table.py
32 lines (25 loc) · 1012 Bytes
/
lektor_markdown_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
# Third-party
from lektor.pluginsystem import Plugin
class MarkdownTablePlugin(Plugin):
name = "markdown-table"
description = "This plugin adds styling to markdown tables"
def get_style(self):
table_class = self.get_config().get(
"bootstrap_class.table", "table table-striped"
)
thead_class = self.get_config().get(
"bootstrap_class.thead", "thead-dark"
)
return [table_class, thead_class]
def style_table(self, header, body):
table_class, thead_class = self.get_style()
return (
'<table class="%s">\n<thead class="%s">%s</thead>\n'
"<tbody>\n%s</tbody>\n</table>\n"
) % (table_class, thead_class, header, body)
def on_markdown_config(self, config, **extra):
class StyleTableMixin(object):
def table(ren, header, body):
return self.style_table(header, body)
config.renderer_mixins.append(StyleTableMixin)