summaryrefslogtreecommitdiff
path: root/sandbox/code-block-directive/tools/makesty.py
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/code-block-directive/tools/makesty.py')
-rw-r--r--sandbox/code-block-directive/tools/makesty.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/sandbox/code-block-directive/tools/makesty.py b/sandbox/code-block-directive/tools/makesty.py
new file mode 100644
index 000000000..b1b0fe6f1
--- /dev/null
+++ b/sandbox/code-block-directive/tools/makesty.py
@@ -0,0 +1,53 @@
+#! /usr/bin/env python
+# Copyright: Raphael 'kena' Poss <r.c.poss@uva.nl>
+# this file is placed in the public domain.
+
+# Use with: pygmentize -S default -f html | python makesty.py >pygments-DUroles.sty
+
+import sys
+import re
+
+d = re.compile(r'.*[0-9]')
+
+print r'%% Stylesheet generated by %s' % sys.argv[0]
+print r'\usepackage{color}'
+
+cnt = 0
+for l in sys.stdin:
+
+ print "% " + l.split('*')[1]
+ key = l.split(' ', 1)[0][1:]
+
+ if d.match(key) is not None:
+ print "%% Can't generate style for '%s' because 'DUrole%s' is not a valid macro id." % (key,key)
+ continue
+
+ s = '#1'
+
+ if 'color:' in l:
+ col = l.split('#',1)[1][:6]
+ r = float(int(col[0:2], 16)) / 255.
+ g = float(int(col[2:4], 16)) / 255.
+ b = float(int(col[4:6], 16)) / 255.
+ s = r'\textcolor[rgb]{%.2f,%.2f,%.2f}{%s}' % (r, g, b, s)
+
+ if 'font-style: italic' in l:
+ s = r'\textit{%s}' % s
+ if 'font-weight: bold' in l:
+ s = r'\textbf{%s}' % s
+
+ if 'border:' in l:
+ col = l.split('#',1)[1][:6]
+ r = float(int(col[0:2], 16)) / 255.
+ g = float(int(col[2:4], 16)) / 255.
+ b = float(int(col[4:6], 16)) / 255.
+ cn = 'ducolor%d' % cnt
+ cnt += 1
+ print r'\definecolor{%s}{rgb}{%.2f,%.2f,%.2f}' % (cn, r, g, b)
+ s = r'\colorbox{%s}{%s}' % (cn, s)
+
+ print r'\newcommand\DUrole%s[1]{%s}' % (key, s)
+
+# These seem to be special
+print r'\newcommand\DUrolep[1]{#1}'
+