|
| 1 | +import argparse |
| 2 | +import re |
| 3 | +import sys |
| 4 | + |
| 5 | +HEAD = """ |
| 6 | +<html> |
| 7 | +<head> |
| 8 | + <script type="text/x-mathjax-config"> |
| 9 | + MathJax.Hub.Config({ |
| 10 | + extensions: ["tex2jax.js", "TeX/AMSsymbols.js", "TeX/AMSmath.js"], |
| 11 | + jax: ["input/TeX", "output/HTML-CSS"], |
| 12 | + tex2jax: { |
| 13 | + inlineMath: [ ['$','$'] ], |
| 14 | + displayMath: [ ['$$','$$'] ], |
| 15 | + processEscapes: true |
| 16 | + }, |
| 17 | + "HTML-CSS": { availableFonts: ["TeX"] } |
| 18 | + }); |
| 19 | + </script> |
| 20 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js" async></script> |
| 21 | + <script type="text/javascript" src="../.tools/theme/marked.js"> |
| 22 | + </script> |
| 23 | + <link href="http://cdn.bootcss.com/highlight.js/9.9.0/styles/darcula.min.css" rel="stylesheet"> |
| 24 | + <script src="http://cdn.bootcss.com/highlight.js/9.9.0/highlight.min.js"></script> |
| 25 | + <link href="http://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"> |
| 26 | + <link href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" rel="stylesheet"> |
| 27 | + <link href="../.tools/theme/github-markdown.css" rel='stylesheet'> |
| 28 | +</head> |
| 29 | +<style type="text/css" > |
| 30 | +.markdown-body { |
| 31 | + box-sizing: border-box; |
| 32 | + min-width: 200px; |
| 33 | + max-width: 980px; |
| 34 | + margin: 0 auto; |
| 35 | + padding: 45px; |
| 36 | +} |
| 37 | +</style> |
| 38 | +
|
| 39 | +
|
| 40 | +<body> |
| 41 | +
|
| 42 | +<div id="context" class="container-fluid markdown-body"> |
| 43 | +</div> |
| 44 | +
|
| 45 | +<!-- This block will be replaced by each markdown file content. Please do not change lines below.--> |
| 46 | +<div id="markdown" style='display:none'> |
| 47 | +""" |
| 48 | + |
| 49 | +TAIL = """ |
| 50 | +</div> |
| 51 | +<!-- You can change the lines below now. --> |
| 52 | +
|
| 53 | +<script type="text/javascript"> |
| 54 | +marked.setOptions({ |
| 55 | + renderer: new marked.Renderer(), |
| 56 | + gfm: true, |
| 57 | + breaks: false, |
| 58 | + smartypants: true, |
| 59 | + highlight: function(code, lang) { |
| 60 | + code = code.replace(/&/g, "&") |
| 61 | + code = code.replace(/>/g, ">") |
| 62 | + code = code.replace(/</g, "<") |
| 63 | + code = code.replace(/ /g, " ") |
| 64 | + return hljs.highlightAuto(code, [lang]).value; |
| 65 | + } |
| 66 | +}); |
| 67 | +document.getElementById("context").innerHTML = marked( |
| 68 | + document.getElementById("markdown").innerHTML) |
| 69 | +</script> |
| 70 | +</body> |
| 71 | +""" |
| 72 | + |
| 73 | + |
| 74 | +def convert_markdown_into_html(argv=None): |
| 75 | + parser = argparse.ArgumentParser() |
| 76 | + parser.add_argument('filenames', nargs='*', help='Filenames to fix') |
| 77 | + args = parser.parse_args(argv) |
| 78 | + |
| 79 | + retv = 0 |
| 80 | + |
| 81 | + for filename in args.filenames: |
| 82 | + with open( |
| 83 | + re.sub(r"README", "index", re.sub(r"\.md$", ".html", filename)), |
| 84 | + "w") as output: |
| 85 | + output.write(HEAD) |
| 86 | + with open(filename) as input: |
| 87 | + for line in input: |
| 88 | + output.write(line) |
| 89 | + output.write(TAIL) |
| 90 | + |
| 91 | + return retv |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == '__main__': |
| 95 | + sys.exit(convert_markdown_into_html()) |
0 commit comments