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 ...@@ -11,6 +11,10 @@ Zope Changes
- Collector # 2396: StructuredText did not allow URLs containing "%" - 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 Zope 2.4 beta 2
......
...@@ -217,8 +217,8 @@ Evaluating expressions without rendering results ...@@ -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 $' __rcs_id__='$Id: DT_Var.py,v 1.42 2001/07/12 20:04:01 andreas Exp $'
__version__='$Revision: 1.41 $'[11:-2] __version__='$Revision: 1.42 $'[11:-2]
from DT_Util import parse_params, name_param, str from DT_Util import parse_params, name_param, str
import re, string, sys import re, string, sys
...@@ -410,8 +410,8 @@ def len_comma(v, name='(Unknown name)', md={}): ...@@ -410,8 +410,8 @@ def len_comma(v, name='(Unknown name)', md={}):
StructuredText=None StructuredText=None
def structured_text(v, name='(Unknown name)', md={}): def structured_text(v, name='(Unknown name)', md={}):
global StructuredText global StructuredText
if StructuredText is None: import StructuredText if StructuredText is None: from StructuredText import html_with_references
return str(StructuredText.html_with_references(str(v), 3)) return str(html_with_references(str(v),level=3,header=0))
def sql_quote(v, name='(Unknown name)', md={}): def sql_quote(v, name='(Unknown name)', md={}):
"""Quote single quotes in a string by doubling them. """Quote single quotes in a string by doubling them.
......
...@@ -628,10 +628,13 @@ class DocumentClass: ...@@ -628,10 +628,13 @@ class DocumentClass:
def doc_underline(self, def doc_underline(self,
s, s,
expr=re.compile("\_([%s0-9\s\.,\?\/]+)\_" % letters).search): expr=re.compile("_([%s0-9\s\.,\?\/]+)_" % letters).search):
print s
result = expr(s) result = expr(s)
if result: if result:
print "got it"
start,end = result.span(1) start,end = result.span(1)
st,e = result.span() st,e = result.span()
return (StructuredTextUnderline(s[start:end]),st,e) return (StructuredTextUnderline(s[start:end]),st,e)
......
...@@ -371,6 +371,7 @@ class DocumentClass: ...@@ -371,6 +371,7 @@ class DocumentClass:
'doc_href', 'doc_href',
'doc_strong', 'doc_strong',
'doc_emphasize', 'doc_emphasize',
'doc_underline',
'doc_literal', 'doc_literal',
'doc_sgml', 'doc_sgml',
'doc_xref', 'doc_xref',
...@@ -924,6 +925,7 @@ class DocumentClass: ...@@ -924,6 +925,7 @@ class DocumentClass:
s, s,
#expr=re.compile(r"\_([a-zA-Z0-9\s\.,\?]+)\_").search, # old expr, inconsistent punc, failed to cross newlines #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): expr=re.compile(r'_([%s%s%s\s]+)_' % (letters, digits, under_punc)).search):
result = expr(s) result = expr(s)
if result: if result:
if result.group(1)[:1] == '_': if result.group(1)[:1] == '_':
......
...@@ -113,11 +113,13 @@ class HTMLClass: ...@@ -113,11 +113,13 @@ class HTMLClass:
'StructuredTextSGML':'sgml', 'StructuredTextSGML':'sgml',
} }
def dispatch(self, doc, level, output): def dispatch(self, doc, level, output):
getattr(self, self.element_types[doc.getNodeName()])(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=[] r=[]
self.header = header
self.dispatch(doc, level-1, r.append) self.dispatch(doc, level-1, r.append)
return join(r,'') return join(r,'')
...@@ -125,15 +127,20 @@ class HTMLClass: ...@@ -125,15 +127,20 @@ class HTMLClass:
output(doc.getNodeValue()) output(doc.getNodeValue())
def document(self, doc, level, output): def document(self, doc, level, output):
output('<html>\n')
children=doc.getChildNodes() children=doc.getChildNodes()
if self.header==1:
output('<html>\n')
if (children and if (children and
children[0].getNodeName() == 'StructuredTextSection'): children[0].getNodeName() == 'StructuredTextSection'):
output('<head>\n<title>%s</title>\n</head>\n' % output('<head>\n<title>%s</title>\n</head>\n' %
children[0].getChildNodes()[0].getNodeValue()) children[0].getChildNodes()[0].getNodeValue())
output('<body>\n') output('<body>\n')
for c in children: for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level, output) getattr(self, self.element_types[c.getNodeName()])(c, level, output)
if self.header==1:
output('</body>\n') output('</body>\n')
output('</html>\n') output('</html>\n')
......
...@@ -96,15 +96,15 @@ from STletters import letters ...@@ -96,15 +96,15 @@ from STletters import letters
Document = DocumentClass.DocumentClass() Document = DocumentClass.DocumentClass()
HTMLNG = HTMLClass.HTMLClass() HTMLNG = HTMLClass.HTMLClass()
def HTML(aStructuredString, level=0): def HTML(aStructuredString, level=0, header=1):
st = Basic(aStructuredString) st = Basic(aStructuredString)
doc = Document(st) doc = Document(st)
return HTMLNG(doc) return HTMLNG(doc,header=header)
def StructuredText(aStructuredString, level=0): def StructuredText(aStructuredString, level=0):
return HTML(aStructuredString,level) return HTML(aStructuredString,level)
def html_with_references(text, level=1): def html_with_references(text, level=1, header=1):
text = re.sub( text = re.sub(
r'[\000\n]\.\. \[([0-9_%s-]+)\]' % letters, r'[\000\n]\.\. \[([0-9_%s-]+)\]' % letters,
r'\n <a name="\1">[\1]</a>', r'\n <a name="\1">[\1]</a>',
...@@ -120,7 +120,7 @@ def html_with_references(text, level=1): ...@@ -120,7 +120,7 @@ def html_with_references(text, level=1):
r'\1<a href="\2.html">[\2]</a>\3', r'\1<a href="\2.html">[\2]</a>\3',
text) text)
return HTML(text,level=level) return HTML(text,level=level,header=header)
def html_quote(v, def html_quote(v,
character_entities=( 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