This commit is contained in:
Kovid Goyal 2014-02-27 09:19:08 +05:30
parent 2aa20b15c3
commit f9abbe9800

View File

@ -416,7 +416,7 @@ def cb_story(args):
args["entry"]["title"] = smartyPants(args["entry"]["title"], attributes) args["entry"]["title"] = smartyPants(args["entry"]["title"], attributes)
### interal functions below here # interal functions below here
def smartyPants(text, attr=default_smartypants_attr): def smartyPants(text, attr=default_smartypants_attr):
convert_quot = False # should we translate " entities into normal quotes? convert_quot = False # should we translate " entities into normal quotes?
@ -468,14 +468,22 @@ def smartyPants(text, attr=default_smartypants_attr):
do_stupefy = "1" do_stupefy = "1"
else: else:
for c in attr: for c in attr:
if c == "q": do_quotes = "1" if c == "q":
elif c == "b": do_backticks = "1" do_quotes = "1"
elif c == "B": do_backticks = "2" elif c == "b":
elif c == "d": do_dashes = "1" do_backticks = "1"
elif c == "D": do_dashes = "2" elif c == "B":
elif c == "i": do_dashes = "3" do_backticks = "2"
elif c == "e": do_ellipses = "1" elif c == "d":
elif c == "w": convert_quot = "1" do_dashes = "1"
elif c == "D":
do_dashes = "2"
elif c == "i":
do_dashes = "3"
elif c == "e":
do_ellipses = "1"
elif c == "w":
convert_quot = "1"
else: else:
pass pass
# ignore unknown option # ignore unknown option
@ -763,7 +771,6 @@ def educateDashesOldSchoolInverted(str):
return str return str
def educateEllipses(str): def educateEllipses(str):
""" """
Parameter: String. Parameter: String.
@ -870,7 +877,6 @@ def _tokenize(str):
return tokens return tokens
if __name__ == "__main__": if __name__ == "__main__":
import locale import locale
@ -885,7 +891,6 @@ if __name__ == "__main__":
print docstring_html print docstring_html
# Unit test output goes out stderr. No worries. # Unit test output goes out stderr. No worries.
import unittest import unittest
sp = smartyPants sp = smartyPants
@ -904,17 +909,16 @@ if __name__ == "__main__":
def test_skip_tags(self): def test_skip_tags(self):
self.assertEqual( self.assertEqual(
sp("""<script type="text/javascript">\n<!--\nvar href = "http://www.google.com";\nvar linktext = "google";\ndocument.write('<a href="' + href + '">' + linktext + "</a>");\n//-->\n</script>"""), sp("""<script type="text/javascript">\n<!--\nvar href = "http://www.google.com";\nvar linktext = "google";\ndocument.write('<a href="' + href + '">' + linktext + "</a>");\n//-->\n</script>"""), # noqa
"""<script type="text/javascript">\n<!--\nvar href = "http://www.google.com";\nvar linktext = "google";\ndocument.write('<a href="' + href + '">' + linktext + "</a>");\n//-->\n</script>""") """<script type="text/javascript">\n<!--\nvar href = "http://www.google.com";\nvar linktext = "google";\ndocument.write('<a href="' + href + '">' + linktext + "</a>");\n//-->\n</script>""") # noqa
self.assertEqual( self.assertEqual(
sp("""<p>He said &quot;Let's write some code.&quot; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>"""), sp("""<p>He said &quot;Let's write some code.&quot; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>"""),
"""<p>He said &#8220;Let&#8217;s write some code.&#8221; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>""") """<p>He said &#8220;Let&#8217;s write some code.&#8221; This code here <code>if True:\n\tprint &quot;Okay&quot;</code> is python code.</p>""") # noqa
self.assertEqual( self.assertEqual(
sp('''<script/><p>It's ok</p>'''), sp('''<script/><p>It's ok</p>'''),
'''<script/><p>It&#8217;s ok</p>''') '''<script/><p>It&#8217;s ok</p>''')
def test_ordinal_numbers(self): def test_ordinal_numbers(self):
self.assertEqual(sp("21st century"), "21st century") # no effect. self.assertEqual(sp("21st century"), "21st century") # no effect.
self.assertEqual(sp("3rd"), "3rd") # no effect. self.assertEqual(sp("3rd"), "3rd") # no effect.
@ -925,8 +929,6 @@ if __name__ == "__main__":
unittest.main() unittest.main()
__author__ = "Chad Miller <smartypantspy@chad.org>" __author__ = "Chad Miller <smartypantspy@chad.org>"
__version__ = "1.5_1.6: Fri, 27 Jul 2007 07:06:40 -0400" __version__ = "1.5_1.6: Fri, 27 Jul 2007 07:06:40 -0400"
__url__ = "http://wiki.chad.org/SmartyPantsPy" __url__ = "http://wiki.chad.org/SmartyPantsPy"