Skip to content

Commit

Permalink
When convertWebIntelligentPlainTextToHtml is called with an
Browse files Browse the repository at this point in the history
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
mauritsvanrees committed Jul 16, 2008
1 parent 298cea6 commit a6179ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/HISTORY.txt
Expand Up @@ -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]
Expand Down
29 changes: 28 additions & 1 deletion plone/intelligenttext/README.txt
Expand Up @@ -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
------------------------
Expand Down
5 changes: 5 additions & 0 deletions plone/intelligenttext/transforms.py
Expand Up @@ -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:
Expand Down

0 comments on commit a6179ee

Please sign in to comment.