Permalink
Browse files

When convertWebIntelligentPlainTextToHtml is called with an

explicit tab_width we try to make an integer of that ('2' -> 2).
When that fails we use the default of 4.

svn path=/plone.intelligenttext/trunk/; revision=21685
  • Loading branch information...
1 parent 298cea6 commit a6179eeaef854b42e815c4843b4f67685f2d474a @mauritsvanrees mauritsvanrees committed Jul 16, 2008
Showing with 38 additions and 1 deletion.
  1. +5 −0 docs/HISTORY.txt
  2. +28 −1 plone/intelligenttext/README.txt
  3. +5 −0 plone/intelligenttext/transforms.py
View
@@ -4,6 +4,11 @@ Changelog for plone.intelligenttext
plone.intelligenttext - 1.0.2 Unreleased
+ - When convertWebIntelligentPlainTextToHtml is called with an
+ explicit tab_width we try to make an integer of that ('2' -> 2).
+ When that fails we use the default of 4.
+ [maurits]
+
- Minor change in code path, really only to get 100 percent test
coverage.
[maurits]
@@ -147,13 +147,40 @@ https is accepted.
>>> convertWebIntelligentPlainTextToHtml("https://localhost")
'<a href="https://localhost" rel="nofollow">https://localhost</a>'
-
Unicode should be fine too.
>>> text = u"Línk tö http://foo.ni"
>>> convertWebIntelligentPlainTextToHtml(text)
'L&Atilde;&shy;nk t&Atilde;&para; <a href="http://foo.ni" rel="nofollow">http://foo.ni</a>'
+Leading whitespace is converted to non breaking spaces to preserve
+indentation:
+
+ >>> text = "Some text.\n And some indentation."
+ >>> convertWebIntelligentPlainTextToHtml(text)
+ 'Some text.<br />&nbsp;&nbsp;&nbsp;&nbsp;And some indentation.'
+
+Leading tabs are converted to spaces. The default is 4:
+
+ >>> text = "Before the tab:\n\tand after the tab."
+ >>> convertWebIntelligentPlainTextToHtml(text)
+ 'Before the tab:<br />&nbsp;&nbsp;&nbsp;&nbsp;and after the tab.'
+
+You can specify a different tab width:
+
+ >>> convertWebIntelligentPlainTextToHtml(text, tab_width=2)
+ 'Before the tab:<br />&nbsp;&nbsp;and after the tab.'
+
+In case the tab width is not an integer, we try to convert it:
+
+ >>> convertWebIntelligentPlainTextToHtml(text, tab_width='2')
+ 'Before the tab:<br />&nbsp;&nbsp;and after the tab.'
+
+When that fails we fall back to 4 spaces:
+
+ >>> convertWebIntelligentPlainTextToHtml(text, tab_width='1.5')
+ 'Before the tab:<br />&nbsp;&nbsp;&nbsp;&nbsp;and after the tab.'
+
Html to intelligent text
------------------------
@@ -4,6 +4,11 @@
def convertWebIntelligentPlainTextToHtml(orig, tab_width=4):
"""Converts text/x-web-intelligent to text/html
"""
+ try:
+ # tab_width could be a string like '4'
+ tab_width = int(tab_width)
+ except ValueError:
+ tab_width=4
# very long urls are abbreviated to allow nicer layout
def abbreviateUrl(url, max = 60, ellipsis = "[&hellip;]"):
if len(url) < max:

0 comments on commit a6179ee

Please sign in to comment.