Add support for `imenu` and `which-func-mode`. Remember setting
[docutils/kirr.git] / sandbox / stylesheets / pygments_css2sty.py
blobef079054c72472ac6d71acba94173d97af8c0ce0
1 #! /usr/bin/env python
2 # coding: utf8
3 # Copyright: Raphael 'kena' Poss <r.c.poss@uva.nl>
4 # this file is placed in the public domain.
6 # Convert a CSS stylesheet into one for Docutils' LaTeX output.
8 # Usage example::
10 # pygmentize -S default -f html | pygments_css2sty.py >pygments-default.sty
12 # Versions:
14 # 2012-05-09: Günter Milde <milde@users.sf.net>:
15 # Bugfix: do not fail at lines without comment.
16 # Support for digits in role names.
17 # ``\providecommand`` instead of ``\newcommand``.
18 # Renamed from makesty.py to pygments_css2sty.py.
20 import sys
21 import re
23 print '% Stylesheet for syntax highlight with Docutils'
24 print '% Generated by pygments_css2sty.py from a Pygments CSS style'
25 print '% (output of `pygmentize -S <style> -f html`).'
26 print
27 print r'\RequirePackage{color}'
29 cnt = 0
30 for l in sys.stdin:
32 if '/*' in l:
33 print "% " + l.split('*')[1]
34 key = l.split(' ', 1)[0][1:]
36 s = '#1'
38 if 'color:' in l:
39 col = l.split('#',1)[1][:6]
40 r = float(int(col[0:2], 16)) / 255.
41 g = float(int(col[2:4], 16)) / 255.
42 b = float(int(col[4:6], 16)) / 255.
43 s = r'\textcolor[rgb]{%.2f,%.2f,%.2f}{%s}' % (r, g, b, s)
45 if 'font-style: italic' in l:
46 s = r'\textit{%s}' % s
47 if 'font-weight: bold' in l:
48 s = r'\textbf{%s}' % s
50 if 'border:' in l:
51 col = l.split('#',1)[1][:6]
52 r = float(int(col[0:2], 16)) / 255.
53 g = float(int(col[2:4], 16)) / 255.
54 b = float(int(col[4:6], 16)) / 255.
55 cname = 'DUcolor%d' % cnt
56 cnt += 1
57 print r'\definecolor{%s}{rgb}{%.2f,%.2f,%.2f}' % (cname, r, g, b)
58 s = r'\colorbox{%s}{%s}' % (cname, s)
60 if re.match(r'.*[0-9]', key) is None:
61 print r'\providecommand*\DUrole%s[1]{%s}' % (key, s)
62 else:
63 print r'\providecommand\csname DUrole%s\endcsname[1]{%s}' % (key, s)