git.fiddlerwoaroof.com
Browse code

initial commit

Ed L authored on 28/10/2014 20:09:42
Showing 12 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,61 @@
1
+# Byte-compiled / optimized / DLL files
2
+__pycache__/
3
+*.py[cod]
4
+
5
+# C extensions
6
+*.so
7
+
8
+# Distribution / packaging
9
+.Python
10
+env/
11
+build/
12
+develop-eggs/
13
+dist/
14
+downloads/
15
+eggs/
16
+lib/
17
+lib64/
18
+parts/
19
+sdist/
20
+var/
21
+*.egg-info/
22
+.installed.cfg
23
+*.egg
24
+
25
+# PyInstaller
26
+#  Usually these files are written by a python script from a template
27
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
28
+*.manifest
29
+*.spec
30
+
31
+# Installer logs
32
+pip-log.txt
33
+pip-delete-this-directory.txt
34
+
35
+# Unit test / coverage reports
36
+htmlcov/
37
+.tox/
38
+.coverage
39
+.cache
40
+nosetests.xml
41
+coverage.xml
42
+
43
+# Translations
44
+*.mo
45
+*.pot
46
+
47
+# Django stuff:
48
+*.log
49
+
50
+# Sphinx documentation
51
+docs/_build/
52
+
53
+# PyBuilder
54
+target/
55
+
56
+# my env
57
+*.swp
58
+bin/
59
+pyvenv.cfg
60
+tmp/
61
+include/
0 62
new file mode 100644
... ...
@@ -0,0 +1,29 @@
1
+Copyright (c) 2011 Edward Langley
2
+All rights reserved.
3
+
4
+Redistribution and use in source and binary forms, with or without
5
+modification, are permitted provided that the following conditions
6
+are met:
7
+
8
+Redistributions of source code must retain the above copyright notice,
9
+this list of conditions and the following disclaimer.
10
+
11
+Redistributions in binary form must reproduce the above copyright
12
+notice, this list of conditions and the following disclaimer in the
13
+documentation and/or other materials provided with the distribution.
14
+
15
+Neither the name of the project's author nor the names of its
16
+contributors may be used to endorse or promote products derived from
17
+this software without specific prior written permission.
18
+
19
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 33
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+from mako.template import Template
2
+from mako.lookup import TemplateLookup
3
+
4
+import argparse
5
+parser = argparse.ArgumentParser()
6
+parser.add_argument('infile')
7
+parser.add_argument('--base', '-b', default='base.html', nargs='?')
8
+args = parser.parse_args()
9
+
10
+mylookup = TemplateLookup(directories='templates')
11
+template = mylookup.get_template('from-markdown.html')
12
+
13
+with open(args.infile) as f:
14
+  print(template.render(content=f.read(), base=args.base))
0 15
new file mode 100755
... ...
@@ -0,0 +1,2 @@
1
+python3 -m venv --copies .
2
+pip install -r requirements.txt
0 3
new file mode 100644
... ...
@@ -0,0 +1,73 @@
1
+import subprocess
2
+
3
+try: from shutils import which
4
+except ImportError: from distutils.spawn import find_executable as which
5
+
6
+PANDOC_PATH = which('pandoc')
7
+
8
+
9
+class Document(object):
10
+   """A formatted document."""
11
+
12
+   INPUT_FORMATS = (
13
+      'native', 'markdown', 'markdown+lhs', 'rst',
14
+      'rst+lhs', 'html', 'latex', 'latex+lhs'
15
+   )
16
+
17
+   OUTPUT_FORMATS = (
18
+      'native', 'html', 'html+lhs', 's5', 'slidy',
19
+      'docbook', 'opendocument', 'odt', 'epub',
20
+      'latex', 'latex+lhs', 'context', 'texinfo',
21
+      'man', 'markdown', 'markdown+lhs', 'plain',
22
+      'rst', 'rst+lhs', 'mediawiki', 'rtf', 'html5'
23
+   )
24
+
25
+   SPECIAL_FORMATS = (
26
+       ('html+mathjax', 'html', 'mathjax'),
27
+       ('html5+mathjax', 'html5', 'mathjax'),
28
+   )
29
+
30
+   # TODO: Add odt, epub formats (requires file access, not stdout)
31
+
32
+   def __init__(self):
33
+      self._content = None
34
+      self._format = None
35
+      self._register_formats()
36
+
37
+   @classmethod
38
+   def _register_formats(cls):
39
+      """Adds format properties."""
40
+      for fmt in cls.OUTPUT_FORMATS:
41
+         clean_fmt = fmt.replace('+', '_')
42
+         setattr(cls, clean_fmt, property(
43
+            (lambda x, fmt=fmt: cls._output(x, fmt)), # fget
44
+            (lambda x, y, fmt=fmt: cls._input(x, y, fmt)))) # fset
45
+      for fmt in cls.SPECIAL_FORMATS:
46
+         clean_fmt = fmt[0].replace('+', '_')
47
+         setattr(cls, clean_fmt, property(
48
+            (lambda x, fmt=fmt: cls._output(x, fmt[1], fmt[2])), # fget
49
+            (lambda x, y, fmt=fmt: cls._input(x, y, fmt[1], fmt[2])))) # fset
50
+
51
+
52
+
53
+   def _input(self, value, format=None, modifiers=None):
54
+      # format = format.replace('_', '+')
55
+      self._content = value
56
+      self._format = format
57
+      self._modifiers = None
58
+
59
+   def _output(self, format, modifiers=None):
60
+      # print format
61
+      if modifiers is None:
62
+        cmdline = [PANDOC_PATH, '--from=%s' % self._format, '--to=%s' % format]
63
+      else:
64
+        cmdline = [PANDOC_PATH, '--from=%s' % self._format, '--to=%s' % format,
65
+                   '--%s' % modifiers]
66
+
67
+      p = subprocess.Popen(
68
+         cmdline,
69
+         stdin=subprocess.PIPE,
70
+         stdout=subprocess.PIPE
71
+      )
72
+
73
+      return p.communicate(self._content)[0]
0 74
new file mode 100644
... ...
@@ -0,0 +1,2 @@
1
+Mako==1.0.0
2
+MarkupSafe==0.23
0 3
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <meta charset="utf-8">
5
+  <meta name="generator" content="blog-gen">
6
+  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+  <%block name="header">
8
+    <title></title>
9
+    <style type="text/css">code{white-space: pre;}</style>
10
+  </%block>
11
+</head>
12
+<body>
13
+  <div class="container">
14
+    <%block name="content_block" />
15
+  </div>
16
+</body>
17
+</html>
0 18
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+<%inherit file="${context['base']}" />
2
+<%namespace file="pandoc.mako" name="pandoc" />
3
+
4
+<%block name="header">
5
+  ${parent.header()}
6
+  <!--[if lt IE 9]>
7
+  <style type="text/css">code{white-space: pre;}</style>
8
+  <!--[if lt IE 9]>
9
+    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
10
+  <![endif]-->
11
+  <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
12
+</%block>
13
+
14
+<%block name="content_block">
15
+  <%pandoc:markdown>
16
+    ${content}
17
+  </%pandoc:markdown>
18
+</%block>
0 19
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+<%def name="markdown()">
2
+<%
3
+  import pandoc
4
+  doc = pandoc.Document()
5
+  body = capture(caller.body)
6
+  doc.markdown = body.strip().encode('utf-8')
7
+%>
8
+${ doc.html5_mathjax.decode('utf-8') }
9
+</%def>