def __str__(self, extra_dl=regex.compile("</dl>\n<dl>"), extra_ul=regex.compile("</ul>\n<ul>"), extra_ol=regex.compile("</ol>\n<ol>"), ): '''\ Return an HTML string representation of the structured text data. ''' s=self._str(self.structure,self.level) s=gsub(extra_dl,'\n',s) s=gsub(extra_ul,'\n',s) s=gsub(extra_ol,'\n',s) return s
def ctag(s, em=regex.compile( ctag_prefix+(ctag_middle % (("*",)*6) )+ctag_suffix), strong=regex.compile( ctag_prefix+(ctag_middl2 % (("*",)*8))+ctag_suffix), under=regex.compile( ctag_prefix+(ctag_middle % (("_",)*6) )+ctag_suffix), code=regex.compile( ctag_prefix+(ctag_middle % (("\'",)*6))+ctag_suffix), ): if s is None: s='' s=gsub(strong,'\\1<strong>\\2</strong>\\3',s) s=gsub(under, '\\1<u>\\2</u>\\3',s) s=gsub(code, '\\1<code>\\2</code>\\3',s) s=gsub(em, '\\1<em>\\2</em>\\3',s) return s
def html_with_references(text, level=1): text = gsub( '[\0\n].. \[\([-_0-9_a-zA-Z-]+\)\]', '\n <a name="\\1">[\\1]</a>', text) text = gsub( '\([\0- ,]\)\[\([0-9_a-zA-Z-]+\)\]\([\0- ,.:]\)', '\\1<a href="#\\2">[\\2]</a>\\3', text) text = gsub( '\([\0- ,]\)\[\([^]]+\)\.html\]\([\0- ,.:]\)', '\\1<a href="\\2.html">[\\2]</a>\\3', text) return HTML(text,level=level)
def html_quote(v, character_entities=( (regex.compile('&'), '&'), (regex.compile("<"), '<' ), (regex.compile(">"), '>' ), (regex.compile('"'), '"') )): #" text=str(v) for re,name in character_entities: text=gsub(re,name,text) return text
def __init__(self, aStructuredString, level=0, paragraph_divider=regex.compile('\(\n *\)+\n'), ): '''Convert a structured text string into a structured text object. Aguments: aStructuredString -- The string to be parsed. level -- The level of top level headings to be created. ''' aStructuredString = gsub( '\"\([^\"\0]+\)\":' # title: <"text":> + ('\([-:a-zA-Z0-9_,./?=@#~]+%s\)' % not_punctuation_or_whitespace) + optional_trailing_punctuation + trailing_space, '<a href="\\2">\\1</a>\\4\\5\\6', aStructuredString) aStructuredString = gsub( '\"\([^\"\0]+\)\",[\0- ]+' # title: <"text", > + ('\([a-zA-Z]*:[-:a-zA-Z0-9_,./?=@#~]*%s\)' % not_punctuation_or_whitespace) + optional_trailing_punctuation + trailing_space, '<a href="\\2">\\1</a>\\4\\5\\6', aStructuredString) protoless = find(aStructuredString, '<a href=":') if protoless != -1: aStructuredString = gsub('<a href=":', '<a href="', aStructuredString) self.level=level paragraphs=ts_regex.split(untabify(aStructuredString), paragraph_divider) paragraphs=map(indent_level,paragraphs) self.structure=structure(paragraphs)