summaryrefslogtreecommitdiff
path: root/sandbox/code-block-directive
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-05-09 10:32:30 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-05-09 10:32:30 +0000
commitb4b220d7d147022ef1d404742621d6b9e85e16ab (patch)
tree2c28509e46d73e8a3691c1fa5ec44c91cbebef57 /sandbox/code-block-directive
parent70d08a48eb71481f8ce0cff14b47f5c2775cb85b (diff)
downloaddocutils-b4b220d7d147022ef1d404742621d6b9e85e16ab.tar.gz
Update skript to convert Pygments styles from CSS to LaTeX.
Bugfix: do not fail at lines without comment. Support for digits in role names. ``\\\\providecommand`` instead of ``\\\\newcommand``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7428 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/code-block-directive')
-rw-r--r--sandbox/code-block-directive/tools/makesty.py49
1 files changed, 29 insertions, 20 deletions
diff --git a/sandbox/code-block-directive/tools/makesty.py b/sandbox/code-block-directive/tools/makesty.py
index b1b0fe6f1..27e17bb09 100644
--- a/sandbox/code-block-directive/tools/makesty.py
+++ b/sandbox/code-block-directive/tools/makesty.py
@@ -1,27 +1,37 @@
#! /usr/bin/env python
+# coding: utf8
# 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
+#
+# Convert a CSS stylesheet into one for Docutils' LaTeX output.
+#
+# Usage example::
+#
+# pygmentize -S default -f html | python makesty.py >pygments-default.sty
+#
+# Versions:
+#
+# 2012-05-09: Günter Milde <milde@users.sf.net>:
+# Bugfix: do not fail at lines without comment.
+# Support for digits in role names.
+# ``\providecommand`` instead of ``\newcommand``.
import sys
import re
-d = re.compile(r'.*[0-9]')
-
-print r'%% Stylesheet generated by %s' % sys.argv[0]
-print r'\usepackage{color}'
+print '% Stylesheet for syntax highlight with Docutils'
+print '% Generated by makesty.py from a Pygments CSS style'
+print '% (output of `pygmentize -S <style> -f html`).'
+print
+print r'\RequirePackage{color}'
cnt = 0
for l in sys.stdin:
- print "% " + l.split('*')[1]
+ if '/*' in l:
+ 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:
@@ -30,7 +40,7 @@ for l in sys.stdin:
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:
@@ -41,13 +51,12 @@ for l in sys.stdin:
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
+ cname = '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}'
+ print r'\definecolor{%s}{rgb}{%.2f,%.2f,%.2f}' % (cname, r, g, b)
+ s = r'\colorbox{%s}{%s}' % (cname, s)
+ if re.match(r'.*[0-9]', key) is None:
+ print r'\providecommand*\DUrole%s[1]{%s}' % (key, s)
+ else:
+ print r'\providecommand\csname DUrole%s\endcsname[1]{%s}' % (key, s)