annotate scripts/fontaine @ 9:a5488b474c6b

Add HTML renderer.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Jan 2017 02:56:08 -0800
parents 9053902c750e
children 2cea36073188
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 #!/usr/bin/env python
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import sys
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import argparse
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 sys.path.append(os.path.dirname(os.path.dirname(__file__)))
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 def main():
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 parser = argparse.ArgumentParser(
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 description='Fontaine command line utility')
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 parser.add_argument('script')
9
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
14 parser.add_argument('out_file', nargs='?')
4
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 args = parser.parse_args()
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 from fontaine.parser import FontaineParser
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 p = FontaineParser()
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 doc = p.parse(args.script)
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
9
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
21 if not args.out_file:
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
22 from fontaine.console import ConsoleDocumentRenderer
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
23 rdr = ConsoleDocumentRenderer()
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
24 rdr.render_doc(doc, sys.stdout)
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
25 else:
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
26 from fontaine.html import HtmlDocumentRenderer
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
27 rdr = HtmlDocumentRenderer()
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
28 with open(args.out_file, 'w') as fp:
a5488b474c6b Add HTML renderer.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
29 rdr.render_doc(doc, fp)
4
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 if __name__ == '__main__':
9053902c750e Add a console renderer and a command line utility to use it.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 main()