diff options
author | Jens Diemer <github.com@jensdiemer.de> | 2009-06-03 07:56:08 +0000 |
---|---|---|
committer | Jens Diemer <github.com@jensdiemer.de> | 2009-06-03 07:56:08 +0000 |
commit | 78d6872cb950fa2295d18ac07383df1b609a34d7 (patch) | |
tree | 19cd4a2d0dfe6999472893a12199cb7ac2b242ce | |
parent | 6905f018b06402cb1e17e618fe11e562714d1c44 (diff) | |
download | creole-78d6872cb950fa2295d18ac07383df1b609a34d7.tar.gz |
- v0.2.3
- html2creole bugfix/enhanced: convert image tag without alt attribute:
- see also: http://code.google.com/p/python-creole/issues/detail?id=6
- Thanks Betz Stefan alias 'encbladexp'
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | README | 7 | ||||
-rw-r--r-- | creole/__init__.py | 4 | ||||
-rw-r--r-- | creole/html2creole.py | 15 | ||||
-rw-r--r-- | tests/test_creole2html.py | 12 | ||||
-rw-r--r-- | tests/test_html2creole.py | 18 |
6 files changed, 54 insertions, 3 deletions
@@ -17,6 +17,7 @@ PRIMARY AUTHORS are and/or have been (alphabetic order): CONTRIBUTORS are and/or have been (alphabetic order): * Vitja.Makarov <http://code.google.com/u/Vitja.Makarov/> +* Betz Stefan alias 'encbladexp' <http://www.stefan-betz.net/> Special thanks to the python-forum.de guys, particularly (in alphabetic order): @@ -32,6 +32,13 @@ See also: http://code.google.com/p/python-creole/source/browse/trunk/demo.py history ========= +- v0.2.3 + + - html2creole bugfix/enhanced: convert image tag without alt attribute: + + - see also: http://code.google.com/p/python-creole/issues/detail?id=6 + - Thanks Betz Stefan alias 'encbladexp' + - v0.2.2 - html2creole bugfix: convert '''<a href="/url/">Search & Destroy</a>''' diff --git a/creole/__init__.py b/creole/__init__.py index 3e06000..e52aad9 100644 --- a/creole/__init__.py +++ b/creole/__init__.py @@ -10,8 +10,8 @@ from html2creole import Html2CreoleParser, Html2CreoleEmitter # - Only use . as a separator # - No spaces: "0.8.0 RC2" -> "0.8.0RC2" # http://peak.telecommunity.com/DevCenter/setuptools#specifying-your-project-s-version -__version__ = (0, 2, 2, "") -VERSION_STRING = "0.2.2" +__version__ = (0, 2, 3, "") +VERSION_STRING = "0.2.3" def creole2html(markup_string, debug=False, **kwargs): diff --git a/creole/html2creole.py b/creole/html2creole.py index 1901aca..c555303 100644 --- a/creole/html2creole.py +++ b/creole/html2creole.py @@ -19,6 +19,7 @@ import re import inspect import warnings +import posixpath import htmlentitydefs from HTMLParser import HTMLParser from xml.sax.saxutils import escape @@ -738,7 +739,19 @@ class Html2CreoleEmitter(object): return u"[[%s|%s]]" % (url, link_text) def img_emit(self, node): - return u"{{%(src)s|%(alt)s}}" % node.attrs + src = node.attrs["src"] + + title = node.attrs.get("title", "") + alt = node.attrs.get("alt", "") + if len(alt)>len(title): # Use the longest one + text = alt + else: + text = title + + if text=="": # Use filename as picture text + text = posixpath.basename(src) + + return u"{{%s|%s}}" % (src, text) #-------------------------------------------------------------------------- diff --git a/tests/test_creole2html.py b/tests/test_creole2html.py index eeaf907..cf152ed 100644 --- a/tests/test_creole2html.py +++ b/tests/test_creole2html.py @@ -349,6 +349,18 @@ class TestCreole2htmlMarkup(BaseCreoleTest): """, verbose=0 ) + + def test_image(self): + """ test image tag with different picture text """ + self.assertCreole(r""" + {{foobar1.jpg}} + {{/foobar2.jpg|foobar2.jpg}} + {{/path1/path2/foobar3.jpg|foobar3.jpg}} + """, """ + <p><img src="foobar1.jpg" alt="foobar1.jpg" /><br /> + <img src="/foobar2.jpg" alt="foobar2.jpg" /><br /> + <img src="/path1/path2/foobar3.jpg" alt="foobar3.jpg" /></p> + """) if __name__ == '__main__': diff --git a/tests/test_html2creole.py b/tests/test_html2creole.py index b71a7be..50e9cfc 100644 --- a/tests/test_html2creole.py +++ b/tests/test_html2creole.py @@ -176,6 +176,24 @@ class TestHtml2CreoleMarkup(BaseCreoleTest): </tr> </table> """) + + def test_image(self): + """ test image tag with different alt/title attribute """ + self.assertCreole(r""" + {{foobar1.jpg|foobar1.jpg}} + {{/foobar2.jpg|foobar2.jpg}} + {{/path1/path2/foobar3.jpg|foobar3.jpg}} + {{/foobar4.jpg|It's foobar 4}} + {{/foobar5.jpg|It's foobar 5}} + {{/foobar6.jpg|a long picture title}} + """, """ + <p><img src="foobar1.jpg" /><br /> + <img src="/foobar2.jpg" /><br /> + <img src="/path1/path2/foobar3.jpg" /><br /> + <img src="/foobar4.jpg" alt="It's foobar 4" /><br /> + <img src="/foobar5.jpg" title="It's foobar 5" /><br /> + <img src="/foobar6.jpg" alt="short name" title="a long picture title" /></p> + """) #-------------------------------------------------------------------------- # TODOs: |