Skip to content

Commit 84bce48

Browse files
committed
Add lektor plugin for styling tables
1 parent dda6d74 commit 84bce48

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

configs/markdown-table.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[bootstrap_class]
2+
table = 'table table-striped'
3+
thead = 'thead-dark'

packages/markdown-table/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
build
3+
*.pyc
4+
*.pyo
5+
*.egg-info

packages/markdown-table/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# markdown-table
2+
3+
This is where a description of your plugin goes.
4+
Provide usage instructions here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
from lektor.pluginsystem import Plugin
3+
4+
5+
class MarkdownTablePlugin(Plugin):
6+
name = 'markdown-table'
7+
description = u'Add your description here.'
8+
9+
def get_style(self):
10+
table_class = self.get_config().get('bootstrap_class.table', 'table table-striped')
11+
thead_class = self.get_config().get('bootstrap_class.thead', 'thead-dark')
12+
13+
return [table_class, thead_class]
14+
15+
def style_table(self, header, body):
16+
table_class, thead_class = self.get_style()
17+
return (
18+
'<table class="%s">\n<thead class="%s">%s</thead>\n'
19+
'<tbody>\n%s</tbody>\n</table>\n'
20+
) % (table_class, thead_class, header, body)
21+
22+
def on_markdown_config(self, config, **extra):
23+
class StyleTableMixin(object):
24+
def table(ren, header, body):
25+
return self.style_table(header, body)
26+
config.renderer_mixins.append(StyleTableMixin)

packages/markdown-table/setup.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import ast
2+
import io
3+
import re
4+
5+
from setuptools import setup, find_packages
6+
7+
with io.open('README.md', 'rt', encoding="utf8") as f:
8+
readme = f.read()
9+
10+
_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
11+
12+
with open('lektor_markdown_table.py', 'rb') as f:
13+
description = str(ast.literal_eval(_description_re.search(
14+
f.read().decode('utf-8')).group(1)))
15+
16+
setup(
17+
author='Shubham Pandey',
18+
author_email='shubhampcpandey13@gmail.com',
19+
description=description,
20+
keywords='Lektor plugin',
21+
license='MIT',
22+
long_description=readme,
23+
long_description_content_type='text/markdown',
24+
name='lektor-markdown-table',
25+
packages=find_packages(),
26+
py_modules=['lektor_markdown_table'],
27+
# url='[link to your repository]',
28+
version='0.1',
29+
classifiers=[
30+
'Framework :: Lektor',
31+
'Environment :: Plugins',
32+
],
33+
entry_points={
34+
'lektor.plugins': [
35+
'markdown-table = lektor_markdown_table:MarkdownTablePlugin',
36+
]
37+
}
38+
)

0 commit comments

Comments
 (0)