本文整理汇总了Python中ansi2html.Ansi2HTMLConverter方法的典型用法代码示例。如果您正苦于以下问题:Python ansi2html.Ansi2HTMLConverter方法的具体用法?Python ansi2html.Ansi2HTMLConverter怎么用?Python ansi2html.Ansi2HTMLConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ansi2html
的用法示例。
在下文中一共展示了ansi2html.Ansi2HTMLConverter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ansi2html
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def ansi2html(s):
return mark_safe(Ansi2HTMLConverter(inline=True).convert(s, full=False))
示例2: convert_file_contents_to_html2
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def convert_file_contents_to_html2(normalized_output_file):
#conv = Ansi2HTMLConverter()
with open(normalized_output_file, "rb") as scan_file:
test_data = "".join(read_to_unicode(scan_file))
#expected_data = [e.rstrip('\n') for e in read_to_unicode(scan_file)]
html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True)
return html
示例3: get
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def get(self, request, *args, **kwargs):
filename = self.request.query_params.get('std', None)
is_html = self.request.query_params.get('html', False)
if not filename:
return common.message(500, 'stdout not found')
options = dbutils.get_stateless_options()
wss = options.get('WORKSPACES')
filename = utils.clean_path(filename).strip('/')
p = pathlib.Path(filename)
# we don't want a LFI here even when we're admin
if p.parts[0] not in os.listdir(wss):
return common.message(500, 'Workspace not found ')
stdout = utils.join_path(wss, filename)
content = utils.just_read(stdout)
if not content:
return HttpResponse("No result found")
if filename.endswith('.html') or is_html:
return HttpResponse(content)
try:
# convert console output to html
conv = Ansi2HTMLConverter(scheme='mint-terminal')
html = conv.convert(content)
return HttpResponse(html)
# return Response(html)
except:
return HttpResponse(content)
示例4: terminalize_output
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def terminalize_output(output):
# Replace "<,&,>" signs
output = output.replace("&", "&")
output = output.replace("<", "<")
output = output.replace(">", ">")
output = output.replace("\n", "<br/>")
'''
Substitute terminal color codes for CSS tags.
The bold tag can be a modifier on another tag
and thus sometimes doesn't have its own
closing tag. Just ignore it in that case.
'''
conv = ansi2html.Ansi2HTMLConverter(escaped=False, scheme="xterm")
return conv.convert(output, full=False)
示例5: ansi_to_html
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def ansi_to_html(ansi_text):
return Ansi2HTMLConverter(inline=True).convert(wrangle_to_unicode(ansi_text), full=False)
示例6: gen_ansi_output
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def gen_ansi_output():
conv = Ansi2HTMLConverter()
input_file = EXAMPLES_DIR / 'devtools_main.py'
os.environ['PY_DEVTOOLS_HIGHLIGHT'] = 'true'
p = subprocess.run((sys.executable, str(input_file)), stdout=subprocess.PIPE, check=True, encoding='utf8')
html = conv.convert(p.stdout, full=False).strip('\r\n')
full_html = f'<div class="terminal">\n<pre class="terminal-content">\n{html}\n</pre>\n</div>'
path = TMP_EXAMPLES_DIR / f'{input_file.stem}.html'
path.write_text(full_html)
print(f'generated ansi output to {path}')
示例7: format_log
# 需要导入模块: import ansi2html [as 别名]
# 或者: from ansi2html import Ansi2HTMLConverter [as 别名]
def format_log(log):
conv = Ansi2HTMLConverter(dark_bg=False, scheme="solarized", markup_lines=True)
headers = conv.produce_headers()
content = conv.convert(log, full=False)
content = '<pre class="ansi2html-content">{}</pre>'.format(content)
return headers + content