1. Jonathan Eunice
  2. mdx_smartypants


Jonathan Eunice  committed 25fe726

added fix for smartypants improper munging of inline style blocks

  • Participants
  • Parent commits 251fb53
  • Branches default

Comments (0)

Files changed (4)

File README.txt

View file
     pip install mdx_smartypants
-Failing that, fall back to the older approach::
-    easy_install mdx_smartypants
-(You may need to begin these with "sudo " to authorize installation.)
+(You may need to prefix this with "sudo " to authorize installation.)
     sweet. Definitely 7–8 on a ‘10-point scale’. Now it has
+The smartypants module (as of version wrongly
+munges punctuation within style sections found in the document
+As of version 1.0.7, mdx_smartypants monkey-patches a fix for this.

File example.py

View file
 import mdx_smartypants
 text = """
-Markdown makes HTML from simple text files. But--it lacks typographic
-"prettification." That... That'd be sweet. Definitely 7---8 on a '10-point
-scale'. Now it has it.
+    Markdown makes HTML from simple text files. But--it lacks typographic
+    "prettification." That... That'd be sweet. Definitely 7---8 on a '10-point
+    scale'. Now it has it.
+    Huzzah!
 print markdown.markdown(text, extensions=['smartypants'])

File mdx_smartypants.py

View file
 typographically nicer ("curly") quotes, proper ("em" and "en") dashes, etc.
-import markdown	
+from markdown.postprocessors import Postprocessor
+from markdown.extensions import Extension
 from smartypants import smartyPants
 from namedentities import named_entities
-class SmartypantsPost(markdown.postprocessors.Postprocessor):
+# 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(markdown.extensions.Extension):
+class SmartypantsExt(Extension):
     def extendMarkdown(self, md, md_globals):
         md.postprocessors.add('smartypants', SmartypantsPost(md), '_end')

File setup.py

View file
-    version='1.0.6',
+    version='1.0.7',
     author='Jonathan Eunice',
     description='Python-Markdown extension using smartypants to emit typographically nicer ("curly") quotes, proper ("em" and "en") dashes, etc.',