Commit c9199c98 authored by Andreas Jung's avatar Andreas Jung

Collector # 2397: StructuredText could not handle underlined text

properly. Also <dtml-var stxdoc ftm=structured-text> will no longer
produce <html>..<body>  and </body>..</html>
parent 4c70d8c6
......@@ -11,6 +11,10 @@ Zope Changes
- Collector # 2396: StructuredText did not allow URLs containing "%"
- Collector # 2397: StructuredText could not handle underlined text
properly. Also <dtml-var stxdoc ftm=structured-text> will no longer
produce <html>..<body> and </body>..</html>
Zope 2.4 beta 2
......
......@@ -217,8 +217,8 @@ Evaluating expressions without rendering results
''' # '
__rcs_id__='$Id: DT_Var.py,v 1.41 2001/06/18 18:12:22 chrism Exp $'
__version__='$Revision: 1.41 $'[11:-2]
__rcs_id__='$Id: DT_Var.py,v 1.42 2001/07/12 20:04:01 andreas Exp $'
__version__='$Revision: 1.42 $'[11:-2]
from DT_Util import parse_params, name_param, str
import re, string, sys
......@@ -410,8 +410,8 @@ def len_comma(v, name='(Unknown name)', md={}):
StructuredText=None
def structured_text(v, name='(Unknown name)', md={}):
global StructuredText
if StructuredText is None: import StructuredText
return str(StructuredText.html_with_references(str(v), 3))
if StructuredText is None: from StructuredText import html_with_references
return str(html_with_references(str(v),level=3,header=0))
def sql_quote(v, name='(Unknown name)', md={}):
"""Quote single quotes in a string by doubling them.
......
......@@ -628,10 +628,13 @@ class DocumentClass:
def doc_underline(self,
s,
expr=re.compile("\_([%s0-9\s\.,\?\/]+)\_" % letters).search):
expr=re.compile("_([%s0-9\s\.,\?\/]+)_" % letters).search):
print s
result = expr(s)
if result:
print "got it"
start,end = result.span(1)
st,e = result.span()
return (StructuredTextUnderline(s[start:end]),st,e)
......
......@@ -371,6 +371,7 @@ class DocumentClass:
'doc_href',
'doc_strong',
'doc_emphasize',
'doc_underline',
'doc_literal',
'doc_sgml',
'doc_xref',
......@@ -924,6 +925,7 @@ class DocumentClass:
s,
#expr=re.compile(r"\_([a-zA-Z0-9\s\.,\?]+)\_").search, # old expr, inconsistent punc, failed to cross newlines
expr=re.compile(r'_([%s%s%s\s]+)_' % (letters, digits, under_punc)).search):
result = expr(s)
if result:
if result.group(1)[:1] == '_':
......
......@@ -113,11 +113,13 @@ class HTMLClass:
'StructuredTextSGML':'sgml',
}
def dispatch(self, doc, level, output):
getattr(self, self.element_types[doc.getNodeName()])(doc, level, output)
def __call__(self, doc, level=1):
def __call__(self, doc, level=1, header=1):
r=[]
self.header = header
self.dispatch(doc, level-1, r.append)
return join(r,'')
......@@ -125,17 +127,22 @@ class HTMLClass:
output(doc.getNodeValue())
def document(self, doc, level, output):
output('<html>\n')
children=doc.getChildNodes()
if (children and
children[0].getNodeName() == 'StructuredTextSection'):
output('<head>\n<title>%s</title>\n</head>\n' %
children[0].getChildNodes()[0].getNodeValue())
output('<body>\n')
if self.header==1:
output('<html>\n')
if (children and
children[0].getNodeName() == 'StructuredTextSection'):
output('<head>\n<title>%s</title>\n</head>\n' %
children[0].getChildNodes()[0].getNodeValue())
output('<body>\n')
for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output('</body>\n')
output('</html>\n')
if self.header==1:
output('</body>\n')
output('</html>\n')
def section(self, doc, level, output):
children=doc.getChildNodes()
......
......@@ -96,15 +96,15 @@ from STletters import letters
Document = DocumentClass.DocumentClass()
HTMLNG = HTMLClass.HTMLClass()
def HTML(aStructuredString, level=0):
def HTML(aStructuredString, level=0, header=1):
st = Basic(aStructuredString)
doc = Document(st)
return HTMLNG(doc)
return HTMLNG(doc,header=header)
def StructuredText(aStructuredString, level=0):
return HTML(aStructuredString,level)
def html_with_references(text, level=1):
def html_with_references(text, level=1, header=1):
text = re.sub(
r'[\000\n]\.\. \[([0-9_%s-]+)\]' % letters,
r'\n <a name="\1">[\1]</a>',
......@@ -120,7 +120,7 @@ def html_with_references(text, level=1):
r'\1<a href="\2.html">[\2]</a>\3',
text)
return HTML(text,level=level)
return HTML(text,level=level,header=header)
def html_quote(v,
character_entities=(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment