[Zope3-checkins] SVN: Zope3/trunk/src/zope/structuredtext/__init__.py Add convenience functions from Zope 2.

Philipp von Weitershausen philikon at philikon.de
Sun Jan 8 09:09:52 EST 2006


Log message for revision 41215:
  Add convenience functions from Zope 2.
  

Changed:
  U   Zope3/trunk/src/zope/structuredtext/__init__.py

-=-
Modified: Zope3/trunk/src/zope/structuredtext/__init__.py
===================================================================
--- Zope3/trunk/src/zope/structuredtext/__init__.py	2006-01-08 13:05:09 UTC (rev 41214)
+++ Zope3/trunk/src/zope/structuredtext/__init__.py	2006-01-08 14:09:52 UTC (rev 41215)
@@ -32,3 +32,29 @@
 $Id$
 """
 __docformat__ = 'restructuredtext'
+
+import re
+from zope.structuredtext import stng, document, html
+
+def stx2html(aStructuredString, level=1, header=1):
+    st = stng.structurize(aStructuredString)
+    doc = document.DocumentWithImages()(st)
+    return html.HTMLWithImages()(doc, header=header, level=level)
+
+def stx2htmlWithReferences(text, level=1, header=1):
+    text = re.sub(
+        r'[\000\n]\.\. \[([0-9_%s-]+)\]' % letters,
+        r'\n  <a name="\1">[\1]</a>',
+        text)
+
+    text = re.sub(
+        r'([\000- ,])\[(?P<ref>[0-9_%s-]+)\]([\000- ,.:])'   % letters,
+        r'\1<a href="#\2">[\2]</a>\3',
+        text)
+
+    text = re.sub(
+        r'([\000- ,])\[([^]]+)\.html\]([\000- ,.:])',
+        r'\1<a href="\2.html">[\2]</a>\3',
+        text)
+
+    return stx2html(text, level=level, header=header)



More information about the Zope3-Checkins mailing list