def __call__(self, obj): used_title_styles = self.context.state.memo.title_styles section_level = self.context.state.memo.section_level + 1 title_style = get_title_style(used_title_styles, section_level) title = obj.name + '\n' + title_style * len(obj.name) + '\n\n' documentation = obj.doc.value.replace('\\n', '\n') # fix linebreaks temp = nodes.Element() lines = statemachine.string2lines(title + documentation) self.context.content.data = lines self.context.state.nested_parse( self.context.content, self.context.content_offset, temp, match_titles=True ) node = temp.children.pop() if self.context.options.get('style', 'default') == 'minimal': return [node] tags_info = get_tags_information(obj, UserKeywordNode.TAGS_LIST) if self.context.options.get( 'style', 'default') == "expanded" else '' all_steps = filter(lambda x: not x.is_comment(), obj.steps) steps = u'***Keywords***\n\n%s\n' % obj.name steps += tags_info for step in flatten(map(Adapter(self.context), all_steps)): steps += ' ' * 4 + step.astext() + '\n' lexer = get_lexer_by_name('robotframework') formatter = HtmlFormatter(noclasses=False) parsed = highlight(steps, lexer, formatter) if self.context.options.get('style', 'default') == 'default': parsed = re.sub('<span class="gh">[^\n]+\n\n', '', parsed) parsed = re.sub('<span class="gu">[^<]+</span>', '', parsed) parsed = re.sub('<pre><span class="p"></span>', '<pre>', parsed) parsed = re.sub('<span class="p"> ', '<span class="p">', parsed) node.append(nodes.raw('', parsed, format='html')) formatter = LatexFormatter() parsed = highlight(steps, lexer, formatter) if self.context.options.get('style', 'default') == 'default': parsed = re.sub('\\\PY{g\+gh}{[^}]+}\n\n', '', parsed) parsed = re.sub('\\\PY{g\+gu}{[^}]+}\n', '', parsed) node.append(nodes.raw('', parsed, format='latex')) return [node]
def run(self): path = resolve_path(self.options.get('source', self.options.get('suite')), os.path.dirname(self.state.document.current_source) ) lexer = get_lexer_by_name('robotframework') with open(path, 'r') as source: formatter = HtmlFormatter(noclasses=False) parsed = highlight(source.read(), lexer, formatter) html_node = nodes.raw('', parsed, format='html') with open(path, 'r') as source: formatter = LatexFormatter() parsed = highlight(source.read(), lexer, formatter) latex_node = nodes.raw('', parsed, format='latex') return [html_node, latex_node]
def run(self): path = resolve_path(self.options.get('source', self.options.get('suite', self.options.get('resource')) ), os.path.dirname(self.state.document.current_source) ) with open(path, 'r') as source: lexer = get_lexer_by_name('robotframework') formatter = HtmlFormatter(noclasses=False) parsed = highlight(source.read(), lexer, formatter) # Remove everything but the variables table removable_sections = ['Test Cases', 'Keywords'] regex = re.compile( '(<pre>).*(<span class="gh">\*\*\* Variables \*\*\*</span>)', re.I + re.S + re.M ) parsed = regex.sub('\\1\\2', parsed) for section in removable_sections: regex = re.compile( '<span class="gh">\*\*\* %s \*\*\*</span>.*</pre>' % section, re.I + re.S + re.M ) parsed = regex.sub('</pre>', parsed) parsed = re.sub('<span class="p"></span>\n\n</pre>', '</pre>', parsed) # Remove heading from the variables table when required if self.options.get('style', 'default') == 'default': parsed = re.sub('<span class="gh">[^\n]+\n\n', '', parsed) html_variables_node = nodes.raw('', parsed, format='html') with open(path, 'r') as source: formatter = LatexFormatter() parsed = highlight(source.read(), lexer, formatter) # Remove everything but the variables table removable_sections = ['Test Cases', 'Keywords'] regex = re.compile( '(\\\\begin{Verbatim}\[[^\]]*\]\n).*' '(\\\\PY{g\+gh}{\*\*\*\sVariables\s\*\*\*})', re.I + re.S + re.M ) parsed = regex.sub('\\1\\2', parsed) for section in removable_sections: regex = re.compile( '\\\PY{g\+gh}{\*\*\* %s \*\*\*}.*\\\end{Verbatim}\n*$' % ( section), re.I + re.S + re.M ) parsed = regex.sub('\end{Verbatim}\n', parsed) # Remove heading from the settings table when required if self.options.get('style', 'default') == 'default': parsed = re.sub('\\\PY{g\+gh}{[^}]+}\n\n', '', parsed) parsed = re.sub('\\\PY{g\+gu}{[^}]+}\n', '', parsed) latex_variables_node = nodes.raw('', parsed, format='latex') return [html_variables_node, latex_variables_node]
def run(self): path = resolve_path(self.options.get('source', self.options.get('suite', self.options.get('resource')) ), os.path.dirname(self.state.document.current_source) ) try: resource = robot.parsing.TestData(source=path) except robot.errors.DataError: resource = robot.parsing.ResourceFile(source=path) resource.populate() obj = resource.setting_table documentation = obj.doc.value.replace('\\n', '\n') # fix linebreaks temp = nodes.Element() lines = statemachine.string2lines(documentation) self.content.data = lines self.state.nested_parse( self.content, self.content_offset, temp, match_titles=True ) if temp.children: doc_node_list = temp.children[:] else: doc_node_list = [] lexer = get_lexer_by_name('robotframework') with open(path, 'r') as source: formatter = HtmlFormatter(noclasses=False) parsed = highlight(source.read(), lexer, formatter) # Remove everything after the settings table removable_sections = ['Variables', 'Test Cases', 'Keywords'] for section in removable_sections: regex = re.compile( '<span class="gh">\*\*\* %s \*\*\*</span>.*</pre>' % section, re.I + re.S + re.M ) parsed = regex.sub('</pre>', parsed) parsed = re.sub('<span class="p"></span>\n\n</pre>', '</pre>', parsed) # Remove documentation from the settings table if parsed.find('<span class="kn">Documentation') >= 0: start = parsed.find('<span class="kn">Documentation') if parsed[start + 30:].find('<span class="kn">') >= 0: end = parsed[start + 30:].find('<span class="kn">') + 30 else: end = parsed[start:].find('</pre>') parsed = parsed[:start] + parsed[start + end:] # Remove heading from the settings table when required if self.options.get('style', 'default') == 'default': parsed = re.sub('<span class="gh">[^\n]+\n\n', '', parsed) html_settings_node = nodes.raw('', parsed, format='html') with open(path, 'r') as source: formatter = LatexFormatter() parsed = highlight(source.read(), lexer, formatter) # Remove everything after the settings table removable_sections = ['Variables', 'Test Cases', 'Keywords'] for section in removable_sections: regex = re.compile( '\\\PY{g\+gh}{\*\*\* %s \*\*\*}.*\\\end{Verbatim}\n*$' % ( section), re.I + re.S + re.M ) parsed = regex.sub('\end{Verbatim}\n', parsed) # Remove documentation from the settings table if parsed.find('\\PY{k+kn}{Documentation}') >= 0: start = parsed.find('\\PY{k+kn}{Documentation}') if parsed[start + 24:].find('\PY{k+kn}') >= 0: end = parsed[start + 24:].find('\PY{k+kn}') + 24 else: end = parsed[start:].find('\\end{Verbatim}') parsed = parsed[:start] + parsed[start + end:] # Remove heading from the settings table when required if self.options.get('style', 'default') == 'default': parsed = re.sub('\\\PY{g\+gh}{[^}]+}\n\n', '', parsed) parsed = re.sub('\\\PY{g\+gu}{[^}]+}\n', '', parsed) latex_settings_node = nodes.raw('', parsed, format='latex') if len(doc_node_list) > 0: out = [] for node in doc_node_list: out.append(node) out.append(html_settings_node) out.append(latex_settings_node) return out else: return [html_settings_node, latex_settings_node]