18 from urllib
import quote
20 from urllib.parse
import quote
23 from robot.utils import html_escape, html_format, NormalizedDict
31 _header_regexp = re.compile(
r'<h([234])>(.+?)</h\1>')
35 _name_regexp = re.compile(
'`(.+?)`')
37 def __init__(self, keywords, type_info, introduction, doc_format='ROBOT'):
40 robot_format=doc_format ==
'ROBOT')
45 'introduction':
'Introduction',
46 'library introduction':
'Introduction',
47 'importing':
'Importing',
48 'library importing':
'Importing',
49 'keywords':
'Keywords',
52 targets[kw.name] = kw.name
55 targets[header] = header
59 targets = {info.name: info.name
for info
in type_info}
64 for line
in introduction.splitlines():
65 match = headers.match(line.strip())
71 for key, value
in targets.items())
75 return quote(value.encode(
'UTF-8'), safe=
"-_.!~*'()")
77 def html(self, doc, intro=False):
80 doc = self.
_header_regexp_header_regexp.sub(
r'<h\1 id="\2">\2</h\1>', doc)
88 return f
'<a href="#{targets[name]}" class="name">{name}</a>'
90 return f
'<a href="#type-{types[name]}" class="name">{name}</a>'
91 return f
'<span class="name">{name}</span>'
101 return {
'ROBOT': html_format,
103 'HTML':
lambda doc: doc,
106 raise DataError(
"Invalid documentation format '%s'." % doc_format)
109 return '<p style="white-space: pre-wrap">%s</p>' %
html_escape(doc)
113 from docutils.core
import publish_parts
115 raise DataError(
"reST format requires 'docutils' module to be installed.")
116 parts = publish_parts(doc, writer_name=
'html',
117 settings_overrides={
'syntax_highlight':
'short'})
118 return parts[
'html_body']
143 match = re.search(
r'<p.*?>(.*?)</?p>', doc, re.DOTALL)
150 for tag, repl
in self.
html_tagshtml_tags.items():
151 doc = re.sub(
r'<%(tag)s>(.*?)</%(tag)s>' % {
'tag': tag},
152 r'%(repl)s\1%(repl)s' % {
'repl': repl}, doc,
154 for html, text
in self.
html_charshtml_chars.items():
155 doc = re.sub(html, text, doc)
def _get_formatter(self, doc_format)
def __init__(self, doc_format)
def _format_rest(self, doc)
def _format_text(self, doc)
def html_to_plain_text(self, doc)
def get_shortdoc_from_html(self, doc)
def html_escape(text, linkify=True)