[Zope] STX and images
Danny William Adair
danny@adair.net
Wed, 19 Sep 2001 02:10:49 -0400
Hi!
I want to be able to insert images in an stx document using the
"alttext":img:/path/to/image
input style of StructuredText.DocumentWithImages and then when needed render them to HTML using StructuredText.HTMLWithImages. For this purpose I tried to adopt code of the CMF that Tres Seaver posted to zope@zope.org (almost three months ago), to make it work as an external method that converts stx input (with the a/m image insertions) to html. I have the following code in my "Extensions" folder and the function stx_to_html (now available as an External Method) works _almost_ like a charm:
---------------------------------------------------------------------------------------------------
import StructuredText, re
from StructuredText.HTMLWithImages import HTMLWithImages
_STXDWI = StructuredText.DocumentWithImages.__class__
class DWIClass( StructuredText.DocumentWithImages.__class__ ):
_URL_AND_PUNC = r'([a-zA-Z0-9_\@\.\,\?\!\/\:\;\-\#\~]+)'
def doc_href( self, s, expr1 = re.compile( _STXDWI._DQUOTEDTEXT + "(:)" + _URL_AND_PUNC + _STXDWI._SPACES).search, expr2 = re.compile( _STXDWI._DQUOTEDTEXT + r'(\,\s+)' + _URL_AND_PUNC + _STXDWI._SPACES).search):
return _STXDWI.doc_href( self, s, expr1, expr2 )
DWIClass = DWIClass()
class HWIClass( HTMLWithImages ):
def document(self, doc, level, output):
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
HWIClass = HWIClass()
def stx_to_html( text, level=1 ):
st = StructuredText.Basic( text )
if not st:
return ""
doc = DWIClass( st )
html = HWIClass( doc, level )
return html
---------------------------------------------------------------------------------------------------
Problem is, as soon as I have an underscore in the image path, the rendering will stop at that point, and continue spitting out the rest of the URL as raw text. What am I doing wrong? Is it DocumentWithImages or HTMLWithImages themselves, or is it the above subclass (with _URL_AND_PUNC) that lead to this incorrect rendering?
(btw, Zope Version is 2.4.1b1)
Thank you very much in advance,
Danny