Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(915)

Side by Side Diff: net/tools/net_docs/net_docs.py

Issue 868843002: net docs: Barebones doc renderer and net_docs target. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split install-build-deps.sh change into another CL; remove debugging print statement. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/net.gypi ('K') | « net/net.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
Randy Smith (Not in Mondays) 2015/01/23 15:04:18 I'm finding myself struck by two things about this
Deprecated (see juliatuttle) 2015/01/23 20:13:00 I haven't split it out entirely into separate file
Randy Smith (Not in Mondays) 2015/01/26 17:29:34 Hmmm. I wouldn't think that would argue against d
Deprecated (see juliatuttle) 2015/01/26 20:49:21 Eh, let's sit down in person for a couple of minut
7
Randy Smith (Not in Mondays) 2015/01/23 15:04:18 nit: extra blank line.
Deprecated (see juliatuttle) 2015/01/23 20:13:00 Done.
8 import sys
9
10
11 import argparse
12 import markdown
13 import os.path
14
15
16 def ReadFile(filename):
17 with open(filename, 'r') as file:
18 return file.read()
19
20
21 def WriteFile(filename, contents):
22 dir = os.path.dirname(filename)
23 if not os.path.isdir(dir):
24 os.mkdir(dir)
25 with open(filename, 'w') as file:
26 file.write(contents)
27
28
29 def FormatPage(markdown_html, title):
30 # TODO(ttuttle): Add navigation?
31 TEMPLATE = '<html><head><title>%s</title></head><body>%s</body></html>'
Randy Smith (Not in Mondays) 2015/01/23 15:04:18 Suggestion: Pull this out of the function and make
Deprecated (see juliatuttle) 2015/01/23 20:13:00 Done.
32 return TEMPLATE % (title, markdown_html)
33
34
35 def ProcessDocs(input_filenames, input_pathname, output_pathname):
36 outputting = (input_pathname is not None) and (output_pathname is not None)
37
38 markdown_parser = markdown.Markdown()
39
40 for input_filename in input_filenames:
41 markdown_text = ReadFile(input_filename)
42 markdown_html = markdown_parser.reset().convert(markdown_text)
43 if not outputting:
44 continue
45
46 # TODO(ttuttle): Sanitize HTML?
47 full_html = FormatPage(markdown_html, title=input_filename)
48 rel_filename = os.path.relpath(input_filename, start=input_pathname)
49 output_filename = os.path.join(output_pathname, rel_filename) + '.html'
50 print "%s -> %s -> %s" % (input_filename, rel_filename, output_filename)
51 WriteFile(output_filename, full_html)
52
53
54 def main():
55 parser = argparse.ArgumentParser(
56 description='Parse and render Markdown documentation')
57 parser.add_argument('--input_path', default=None,
58 help="Input path for Markdown; required only if output_path set")
59 parser.add_argument('--output_path', default=None,
60 help="Output path for rendered HTML; if unspecified, won't output")
61 parser.add_argument('filenames', nargs=argparse.REMAINDER)
62 args = parser.parse_args()
63
64 print args
65
66 ProcessDocs(args.filenames, args.input_path, args.output_path)
67
68 return 0
69
70
71 if __name__ == '__main__':
72 sys.exit(main())
OLDNEW
« net/net.gypi ('K') | « net/net.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698