mdx_smartypants / mdx_smartypants.py

Jonathan Eunice 01f9a36 



Jonathan Eunice 25fe726 

Jonathan Eunice 251fb53 

Jonathan Eunice ff6c7e5 
Jonathan Eunice 25fe726 









Jonathan Eunice ff6c7e5 



Jonathan Eunice 25fe726 
Jonathan Eunice ff6c7e5 



Jonathan Eunice 01f9a36 
Jonathan Eunice 3b2ef3a 
"""An extension to Python Markdown that uses smartypants to provide
typographically nicer ("curly") quotes, proper ("em" and "en") dashes, etc.
"""

from markdown.postprocessors import Postprocessor
from markdown.extensions import Extension
from smartypants import smartyPants
from namedentities import named_entities


# Monkeypatch the base smartypants module to add the style tag to the list
# of tags not delved into. This fix has been suggested to the smartypants
# author and package maintainer. But until they update it, there's monkey
# patching.
import smartypants, re

smartypants.tags_to_skip_regex = re.compile(r"<(/)?(pre|code|kbd|script|style|math)[^>]*>", re.I)

class SmartypantsPost(Postprocessor):
    
    def run(self, text):
        return named_entities(smartyPants(text))

class SmartypantsExt(Extension):
    
    def extendMarkdown(self, md, md_globals):
        md.postprocessors.add('smartypants', SmartypantsPost(md), '_end')

def makeExtension(configs=None):
    return SmartypantsExt(configs=configs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.