summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2017-02-10 19:53:49 +0100
committerLars-Dominik Braun <lars@6xq.net>2017-02-10 19:53:49 +0100
commit18261c201b6ed3342d30271f8647be257e843acc (patch)
treefdee76b6ec3ec05fe49f4335fe680d351a081265
parentd568f2aff352201434f34e3594658ab79c9119ce (diff)
downloadeumel-src-18261c201b6ed3342d30271f8647be257e843acc.tar.gz
eumel-src-18261c201b6ed3342d30271f8647be257e843acc.tar.bz2
eumel-src-18261c201b6ed3342d30271f8647be257e843acc.zip
Add syntax highlighting toolsHEADmaster
Patched pygments is required
-rw-r--r--.gitignore2
-rw-r--r--Makefile14
-rw-r--r--README.rst8
-rwxr-xr-xtools/highlight.py56
-rwxr-xr-xtools/listdir.py34
5 files changed, 114 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e81d4a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+_build
+*.sw?
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f31f41c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+all: _build/index.html
+
+_build: tools/highlight.py
+ mkdir -p _build && \
+ find . -mindepth 2 -type f -not -path './.git/*' -not -path './doc/*' -not -path './_build/*' | cut -d / -f 2- | parallel 'tools/highlight.py {}'
+
+_build/index.html: tools/listdir.py | _build
+ pushd _build && find . -name '*.html' | cut -d / -f 2- | sort | ../tools/listdir.py src/ > index.html
+
+.PHONY: clean
+
+clean:
+ $(RM) -r _build
+
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..511d032
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,8 @@
+EUMEL source code
+=================
+
+Source code and documentation for the EUMEL operating system.
+
+Note: This repository will be rebased if older or newer versions of the files
+in it surface. This way EUMEL’s development history will be recreated.
+
diff --git a/tools/highlight.py b/tools/highlight.py
new file mode 100755
index 0000000..a5da820
--- /dev/null
+++ b/tools/highlight.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# vim: set fileencoding=utf8 :
+
+"""
+Highlight elan source file
+"""
+
+if __name__ == '__main__':
+ import sys, os, shutil
+ from pygments import highlight
+ from pygments.lexers import get_lexer_by_name
+ from pygments.formatters import HtmlFormatter
+ from jinja2 import Template
+
+ tpl = Template("""<!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
+ <link rel="stylesheet" href="/style.min.css" type="text/css" />
+ <title>{{ path }}</title>
+ <style>
+ body {
+ max-width: none;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>{{ path }}</h1>
+ <p><a href="{{ rawfile }}">Raw file</a><br><a href="{{ index }}">Back to index</a></p>
+ {{ code|safe }}
+ </body></html>""")
+
+ destdir = '_build'
+ f = sys.argv[1]
+ print (f)
+
+ basedir = os.path.dirname (f)
+ basedestdir = os.path.join (destdir, basedir)
+ if not os.path.isdir (basedestdir):
+ os.makedirs (basedestdir)
+ shutil.copy (f, os.path.join (destdir, f))
+ destf = os.path.join (destdir, f + '.html')
+
+ try:
+ with open (f, 'r') as srcfd:
+ code = srcfd.read ()
+ except UnicodeDecodeError:
+ # that’s fine
+ sys.exit (0)
+
+ lexer = get_lexer_by_name("elan", stripall=True)
+ formatter = HtmlFormatter (linenos=True, lineanchors='line', anchorlinenos=True)
+ with open (destf, 'w') as destfd:
+ tpl.stream(code=highlight(code, lexer, formatter), path=f, rawfile=os.path.basename (f), index=os.path.relpath ('.', os.path.dirname (f))).dump (destfd)
+
diff --git a/tools/listdir.py b/tools/listdir.py
new file mode 100755
index 0000000..58e0ced
--- /dev/null
+++ b/tools/listdir.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf8 :
+
+"""
+Create HTML directory index
+"""
+
+if __name__ == '__main__':
+ import sys, os
+ from jinja2 import Template
+
+ tpl = Template("""<!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
+ <link rel="stylesheet" href="/style.min.css" type="text/css" />
+ <title>Index of {{ name }}</title>
+ </head>
+ <body>
+ <h1>Index of {{ name }}</h1>
+ <p><a href="{{ root }}">Back</a>.</p>
+ <ul>
+ {% for f in files %}
+ <li><a href="{{ f }}">{{ f.rsplit('.',1)[0] }}</a></li>
+ {% endfor %}
+ </ul>
+ </body></html>""")
+
+ files = map (str.strip, sys.stdin.readlines ())
+ name = sys.argv[1]
+
+ tpl.stream(files=files, name=name, root=os.path.relpath('.', name)).dump (sys.stdout)
+