diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/build.sh | 2 | ||||
| -rwxr-xr-x | tools/md-wrapper.py | 32 | 
2 files changed, 21 insertions, 13 deletions
diff --git a/tools/build.sh b/tools/build.sh index 9d03479..94ff9e5 100755 --- a/tools/build.sh +++ b/tools/build.sh  | |||
| @@ -43,7 +43,7 @@ echo "Generating issue pages..." | |||
| 43 | for f in $SRCDIR/issues/*.md | 43 | for f in $SRCDIR/issues/*.md | 
| 44 | do | 44 | do | 
| 45 | b=$(basename "$f" ".md") | 45 | b=$(basename "$f" ".md") | 
| 46 | $TOOLSDIR/md-wrapper.py -r "$DESTDIR" -t "$ISSUE_TEMPLATE" "$f" "$DESTDIR/issues/$b.html" | 46 | $TOOLSDIR/md-wrapper.py -p -r "$DESTDIR" -t "$ISSUE_TEMPLATE" "$f" "$DESTDIR/issues/$b.html" | 
| 47 | done | 47 | done | 
| 48 | 48 | ||
| 49 | # Build the issue indexes | 49 | # Build the issue indexes | 
diff --git a/tools/md-wrapper.py b/tools/md-wrapper.py index b6ac3e5..1d07fbd 100755 --- a/tools/md-wrapper.py +++ b/tools/md-wrapper.py  | |||
| @@ -5,16 +5,20 @@ import sys | |||
| 5 | import re | 5 | import re | 
| 6 | import getopt | 6 | import getopt | 
| 7 | import markdown | 7 | import markdown | 
| 8 | import html | ||
| 8 | 9 | ||
| 10 | is_proposal = False | ||
| 9 | root_dir = "" | 11 | root_dir = "" | 
| 10 | template_file = "" | 12 | template_file = "" | 
| 11 | 13 | ||
| 12 | try: | 14 | try: | 
| 13 | opts, args = getopt.getopt(sys.argv[1:], "r:t:") | 15 | opts, args = getopt.getopt(sys.argv[1:], "pr:t:") | 
| 14 | except getopt.GetoptError as err: | 16 | except getopt.GetoptError as err: | 
| 15 | sys.stderr.write(err + "\n") | 17 | sys.stderr.write(err + "\n") | 
| 16 | sys.exit(2) | 18 | sys.exit(2) | 
| 17 | for o, a in opts: | 19 | for o, a in opts: | 
| 20 | if o == "-p": | ||
| 21 | is_proposal = True | ||
| 18 | if o == "-r": | 22 | if o == "-r": | 
| 19 | root_dir = a | 23 | root_dir = a | 
| 20 | elif o == "-t": | 24 | elif o == "-t": | 
| @@ -32,23 +36,27 @@ for f in [source_file, dest_dir, template_file]: | |||
| 32 | sys.stderr.write("error: %s does not exist\n" % f) | 36 | sys.stderr.write("error: %s does not exist\n" % f) | 
| 33 | sys.exit(1) | 37 | sys.exit(1) | 
| 34 | 38 | ||
| 39 | vars = { | ||
| 40 | 'root': os.path.relpath(root_dir, source_dir), | ||
| 41 | } | ||
| 42 | |||
| 35 | with open(source_file, 'r', encoding="utf-8") as f: | 43 | with open(source_file, 'r', encoding="utf-8") as f: | 
| 44 | while True: | ||
| 45 | l = f.readline().strip() | ||
| 46 | if not l: | ||
| 47 | break | ||
| 48 | m = re.match(r"([^:]+):\s*(.*)", l) | ||
| 49 | if m: | ||
| 50 | vars[m.group(1).lower()] = m.group(2) | ||
| 36 | text = f.read() | 51 | text = f.read() | 
| 37 | 52 | ||
| 38 | with open(template_file, 'r', encoding="utf-8") as f: | 53 | with open(template_file, 'r', encoding="utf-8") as f: | 
| 39 | tmpl = f.read() | 54 | tmpl = f.read() | 
| 40 | 55 | ||
| 41 | md = markdown.Markdown(extensions = ['tables', 'meta']) | 56 | if is_proposal and not "markdown" in vars: | 
| 42 | 57 | vars["content"] = '<pre class=\"proposal\">\n' + html.escape(text) + "</pre>\n" | |
| 43 | html = md.convert(text) | 58 | else: | 
| 44 | 59 | vars["content"] = markdown.markdown(text, extensions = ['tables']) | |
| 45 | vars = { | ||
| 46 | 'root': os.path.relpath(root_dir, source_dir), | ||
| 47 | 'content': html | ||
| 48 | } | ||
| 49 | |||
| 50 | for v in md.Meta: | ||
| 51 | vars[v] = md.Meta[v][0] | ||
| 52 | 60 | ||
| 53 | # Substitution function for replacing template variables. | 61 | # Substitution function for replacing template variables. | 
| 54 | # Treats "{{@filename}}" as an include. | 62 | # Treats "{{@filename}}" as an include. | 
