凯蒂的解决方案并没有为我工作,所以我推翻了降价表滤波器。
应用程序/ tables.py
# -*- coding: utf-8 -*-
"""
tables
~~~~~~~~~~~~~~
Process Tables (add default 'left' alignment and inline styles)
"""
from flask.ext.markdown import Extension
from markdown.extensions.tables import TableProcessor, etree
class BSTableProcessor(TableProcessor):
""" Process Tables in a Bootstrap compatible way """
def _build_row(self, row, parent, align, border):
""" Given a row of text, build table cells. """
tr = etree.SubElement(parent, 'tr')
tag = 'td'
if parent.tag == 'thead':
tag = 'th'
cells = self._split_row(row, border)
# We use align here rather than cells to ensure every row
# contains the same number of columns.
for i, a in enumerate(align):
c = etree.SubElement(tr, tag)
try:
c.text = cells[i].strip()
except IndexError:
c.text = ""
a = (a or 'left')
c.set('style', "text-align: %s;" % a)
class TableExtension(Extension):
def extendMarkdown(self, md, md_globals):
""" Add an instance of TableProcessor to BlockParser. """
md.parser.blockprocessors.add(
'table', BSTableProcessor(md.parser), '<hashheader')
应用程序/ 初始化的.py
# -*- coding: utf-8 -*-
"""
app
~~~~~~~~~~~~~~
Provides the flask application
"""
from flask import Flask, render_template
from flask.ext.markdown import Markdown
from app.tables import TableExtension
def create_app():
"""Create webapp instance"""
# Flask application
app = Flask(__name__)
md = Markdown(app)
md.register_extension(TableExtension)
# Views
@app.route('/')
def index():
return render_template('markdowned.html')
return app
你能使用JavaScript? – Michas 2012-02-23 22:28:48
@Michas:没有什么可以阻止我,但我不喜欢使用JS进行造型,我不认为这是值得的。我宁愿让它与使用JS不一致。 – mpen 2012-02-23 22:32:00
如果我没有错,你有一些CSS和一些HTML你无法编辑? – Michas 2012-02-23 22:35:35