4ead8dfabcd4ff5a9dd4482f7e6577ddc097ad7d,src/sos/converter.py,,script_to_html,#Any#Any#Any#Any#,658
Before Change
to embed a URL to the raw sos file.
"""
import tempfile
transcript_file = transcribe_script(script_file)
no_output_file = not html_file
if not html_file:
html_file = tempfile.NamedTemporaryFile(mode="w+t", suffix=".html", delete=False).name
//
if unknown_args:
raise ValueError("Unrecognized parameter {}".format(unknown_args))
if args:
formatter = ContinuousHtmlFormatter(cssclass="source", full=False,
**{x:y for x,y in vars(args).items() if x != ("raw", "view")})
else:
formatter = ContinuousHtmlFormatter(cssclass="source", full=False)
with open(html_file, "w") as html:
html.write(template_pre_style % os.path.basename(script_file))
html.write(inline_css)
// remove background definition so that we can use our own
html.write("\n".join(x for x in formatter.get_style_defs().split("\n") if "background" not in x))
if args and args.raw:
raw_link = "<a href="{}" class="commit-tease-sha">{}</a>".format(args.raw, script_file)
script_link = "<a href="{}">{}</a>".format(args.raw, os.path.basename(script_file))
else:
raw_link = script_file
script_link = os.path.basename(script_file)
html.write(template_pre_table % (script_link, raw_link,
pretty_size(os.path.getsize(script_file))))
//
html.write("<table class="highlight tab-size js-file-line-container">")
with open(transcript_file) as script:
content = []
content_type = None
content_number = None
next_type = None
for line in script:
line_type, line_no, script_line = line.split("\t", 2)
// Does not follow section because it has to be one line
if line_type == "FOLLOW" and content_type in (None, "SECTION"):
line_type = "COMMENT"
if content_type == line_type or line_type == "FOLLOW":
if next_type is not None and not script_line.rstrip().endswith(","):
formatter.linenostart = content_number
write_html_content(content_type, content, formatter, html)
content = [script_line]
content_type = next_type
content_number = int(line_no)
next_type = None
else:
content.append(script_line)
else:
if content:
formatter.linenostart = content_number
write_html_content(content_type, content, formatter, html)
if line_type.startswith("SCRIPT_"):
content_type = "DIRECTIVE"
next_type = line_type[7:]
else:
content_type = line_type
content_number = int(line_no)
content = [script_line]
if content:
formatter.linenostart = content_number
write_html_content(content_type, content, formatter, html)
html.write("</table>")
html.write(template_post_table)
//
try:
os.remove(transcript_file)
except Exception:
pass
//
if no_output_file:
if args and not args.view:
with open(html_file) as html:
sys.stdout.write(html.read())
After Change
content_type = None
content_number = None
next_type = None
for line in transcribe_script(script_file) :
line_type, line_no, script_line = line.split("\t", 2)
// Does not follow section because it has to be one line
if line_type == "FOLLOW" and content_type in (None, "SECTION"):
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 9
Instances Project Name: vatlab/SoS
Commit Name: 4ead8dfabcd4ff5a9dd4482f7e6577ddc097ad7d
Time: 2017-07-13
Author: ben.bob@gmail.com
File Name: src/sos/converter.py
Class Name:
Method Name: script_to_html
Project Name: vatlab/SoS
Commit Name: 4ead8dfabcd4ff5a9dd4482f7e6577ddc097ad7d
Time: 2017-07-13
Author: ben.bob@gmail.com
File Name: src/sos/converter.py
Class Name:
Method Name: script_to_html
Project Name: vatlab/SoS
Commit Name: 4ead8dfabcd4ff5a9dd4482f7e6577ddc097ad7d
Time: 2017-07-13
Author: ben.bob@gmail.com
File Name: src/sos/converter.py
Class Name:
Method Name: script_to_markdown
Project Name: vatlab/SoS
Commit Name: 4ead8dfabcd4ff5a9dd4482f7e6577ddc097ad7d
Time: 2017-07-13
Author: ben.bob@gmail.com
File Name: src/sos/converter.py
Class Name:
Method Name: script_to_term