02707: Add markup notes to html output
part 1: remove template from html output svn: r12631
This commit is contained in:
@@ -335,75 +335,3 @@ class DocBackend(object):
|
||||
otext += opentag[1]
|
||||
|
||||
return otext
|
||||
|
||||
def _add_markup_from_styled(self, text, s_tags, split=''):
|
||||
"""
|
||||
Input is plain text, output is text with markup added according to the
|
||||
s_tags which are assumed to be styledtexttags.
|
||||
When split is given the text will be split over the value given, and
|
||||
tags applied in such a way that it the text can be safely splitted in
|
||||
pieces along split
|
||||
|
||||
@param text : str, a piece of text
|
||||
@param s_tags : styledtexttags that must be applied to the text
|
||||
@param split : str, optional. A string along which the output can
|
||||
be safely split without breaking the styling.
|
||||
As adding markup means original text must be escaped, ESCAPE_FUNC is
|
||||
used
|
||||
This can be used to convert the text of a styledtext to the format
|
||||
needed for a document backend
|
||||
Do not call this method in a report, use the write_markup method
|
||||
|
||||
@note: the algorithm is complex as it assumes mixing of tags is not
|
||||
allowed: eg <b>text<i> here</b> not</i> is assumed invalid
|
||||
as markup. If the s_tags require such a setup, what is returned
|
||||
is <b>text</b><i><b> here</b> not</i>
|
||||
overwrite this method if this complexity is not needed.
|
||||
"""
|
||||
FIRST = 0
|
||||
LAST = 1
|
||||
tagspos = {}
|
||||
for s_tag in s_tags:
|
||||
tag = self.find_tag_by_stag(s_tag)
|
||||
if tag is not None:
|
||||
for (start, end) in s_tag.ranges:
|
||||
if start in tagspos:
|
||||
tagspos[start] += [(tag, FIRST)]
|
||||
else:
|
||||
tagspos[start] = [(tag, FIRST)]
|
||||
if end in tagspos:
|
||||
tagspos[end] += [(tag, LAST)]
|
||||
else:
|
||||
tagspos[end] = [(tag, LAST)]
|
||||
start = 0
|
||||
end = len(text)
|
||||
keylist = tagspos.keys()
|
||||
keylist.sort()
|
||||
keylist = [x for x in keylist if x<=len(text)]
|
||||
opentags = []
|
||||
otext = u"" #the output, text with markup
|
||||
lensplit = len(split)
|
||||
for pos in keylist:
|
||||
#write text up to tag
|
||||
if pos > start:
|
||||
if split:
|
||||
#make sure text can split
|
||||
splitpos = text[start:pos].find(split)
|
||||
while splitpos <> -1:
|
||||
otext += self.ESCAPE_FUNC()(text[start:start+splitpos])
|
||||
#close open tags
|
||||
for opentag in reversed(opentags):
|
||||
otext += opentag[1]
|
||||
#add split text
|
||||
otext += self.ESCAPE_FUNC()(split)
|
||||
#open the tags again
|
||||
for opentag in opentags:
|
||||
otext += opentag[0]
|
||||
#obtain new values
|
||||
start = start + splitpos + lensplit
|
||||
splitpos = text[start:pos].find(split)
|
||||
|
||||
otext += self.ESCAPE_FUNC()(text[start:pos])
|
||||
|
||||
|
||||
|
@@ -61,7 +61,7 @@ class BaseDoc(object):
|
||||
such as OpenOffice, AbiWord, and LaTeX are derived from this base
|
||||
class, providing a common interface to all document generators.
|
||||
"""
|
||||
def __init__(self, styles, paper_style, template):
|
||||
def __init__(self, styles, paper_style):
|
||||
"""
|
||||
Create a BaseDoc instance, which provides a document generation
|
||||
interface. This class should never be instantiated directly, but
|
||||
@@ -71,10 +71,7 @@ class BaseDoc(object):
|
||||
@param paper_style: PaperStyle instance containing information about
|
||||
the paper. If set to None, then the document is not a page
|
||||
oriented document (e.g. HTML)
|
||||
@param template: Format template for document generators that are
|
||||
not page oriented.
|
||||
"""
|
||||
self.template = template
|
||||
self.paper = paper_style
|
||||
self._style_sheet = styles
|
||||
self._creator = ""
|
||||
|
Reference in New Issue
Block a user