本文整理匯總了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