#!/usr/local/bin/python # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. ''' Simple test case: >>> import markdown >>> text = """ ... BEGIN ... ... ...
... ... | a | b | ... |---|---| ... | c | d | ... ... w | x ... ---|--- ... y | z ... ... END ... """ >>> # test without addon >>> markdown.markdown(text, ['tables']) u'

BEGIN

\\n\ \\n
\\n\\n\ \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n
ab
cd
\\n\ \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n
wx
yz
\\n\

END

' >>> # test with subclass, showing that class has only been added to generated tables >>> markdown.markdown(text, ['tableclass']) u'

BEGIN

\\n\ \\n
\\n\\n\ \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n
ab
cd
\\n\ \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n
wx
yz
\\n\

END

' >>> # Test empty string >>> markdown.markdown("", ['tableclass']) u'' ''' """ Overrides the Python markdown table processor extension Adds <> to the generated tag This is a bit of a hack, as it relies on some aspects of the Python markdown implementation, in particular the class name used to process tables, i.e. TableProcessor. To use this extension, replace 'tables' with 'tableclass' in the EXTENSIONS list in markdownd.py N.B. This extension is an alternative implementation to the one provided in mdx_addtableclass.py To use it, rename as .py """ from markdown import Extension from markdown.extensions.tables import TableProcessor class TableClassProcessor(TableProcessor): def run(self, parent, blocks): # Cannot use super(x, self) as BlockProcessor does not extend object TableProcessor.run(self, parent, blocks) # Assume method adds the table as a child for table in parent.findall('table'): if table.get('class') == None: # Don't override an existing class table.set('class','table') """ Add tableclass to Markdown. """ class TableClassExtension(Extension): def extendMarkdown(self, md, md_globals): md.parser.blockprocessors.add('tableclass', TableClassProcessor(md.parser), '