[PATCH 2 of 2 v2] setup-frontend: generate pygments.css dynamically

Thomas De Schampheleire thomas.de_schampheleire at nokia.com
Sat Sep 15 20:04:16 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1537041136 -7200
#      Sat Sep 15 21:52:16 2018 +0200
# Node ID a73e2822dd99eb5bdc551174d9d4f9c76f8f1667
# Parent  6657e5d4ace2e2507568a3cdcac8c757ce27088b
setup-frontend: generate pygments.css dynamically

Rather than having pygments.css part of the Kallithea sources, generate it
on the fly via setup-frontend.

Idea comes from Dominik Ruf.

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -23,6 +23,7 @@ syntax: regexp
 ^\.pydevproject$
 ^\.coverage$
 ^kallithea/public/css/style\.css(\.map)?$
+^kallithea/public/css/pygments.css$
 ^theme\.less$
 ^kallithea\.db$
 ^test\.db$
diff --git a/kallithea/lib/paster_commands/setup_frontend.py b/kallithea/lib/paster_commands/setup_frontend.py
--- a/kallithea/lib/paster_commands/setup_frontend.py
+++ b/kallithea/lib/paster_commands/setup_frontend.py
@@ -30,6 +30,14 @@ class Command(BasePasterCommand):
         subprocess.check_call(['npm', 'install'], cwd=self.rootdir)
 
     def generate_css(self):
+        print "\nGenerating pygments.css"
+        with open(os.path.join(self.rootdir, 'kallithea', 'public', 'css', 'pygments.css'), 'w') as f:
+            subprocess.check_call(['pygmentize',
+                    '-S', 'default',
+                    '-f', 'html',
+                    '-a', '.code-highlight'],
+                    stdout=f)
+
         print "\nRunning 'npm run less' to generate CSS from LESS"
         subprocess.check_call(['npm', 'run', 'less'], cwd=self.rootdir)
 
diff --git a/kallithea/public/css/pygments.css b/kallithea/public/css/pygments.css
deleted file mode 100644
--- a/kallithea/public/css/pygments.css
+++ /dev/null
@@ -1,69 +0,0 @@
-.code-highlight .hll { background-color: #ffffcc }
-.code-highlight  { background: #f8f8f8; }
-.code-highlight .c { color: #408080; font-style: italic } /* Comment */
-.code-highlight .err { border: 1px solid #FF0000 } /* Error */
-.code-highlight .k { color: #008000; font-weight: bold } /* Keyword */
-.code-highlight .o { color: #666666 } /* Operator */
-.code-highlight .ch { color: #408080; font-style: italic } /* Comment.Hashbang */
-.code-highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
-.code-highlight .cp { color: #BC7A00 } /* Comment.Preproc */
-.code-highlight .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */
-.code-highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
-.code-highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
-.code-highlight .gd { color: #A00000 } /* Generic.Deleted */
-.code-highlight .ge { font-style: italic } /* Generic.Emph */
-.code-highlight .gr { color: #FF0000 } /* Generic.Error */
-.code-highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
-.code-highlight .gi { color: #00A000 } /* Generic.Inserted */
-.code-highlight .go { color: #888888 } /* Generic.Output */
-.code-highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
-.code-highlight .gs { font-weight: bold } /* Generic.Strong */
-.code-highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-.code-highlight .gt { color: #0044DD } /* Generic.Traceback */
-.code-highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
-.code-highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
-.code-highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
-.code-highlight .kp { color: #008000 } /* Keyword.Pseudo */
-.code-highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
-.code-highlight .kt { color: #B00040 } /* Keyword.Type */
-.code-highlight .m { color: #666666 } /* Literal.Number */
-.code-highlight .s { color: #BA2121 } /* Literal.String */
-.code-highlight .na { color: #7D9029 } /* Name.Attribute */
-.code-highlight .nb { color: #008000 } /* Name.Builtin */
-.code-highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
-.code-highlight .no { color: #880000 } /* Name.Constant */
-.code-highlight .nd { color: #AA22FF } /* Name.Decorator */
-.code-highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
-.code-highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
-.code-highlight .nf { color: #0000FF } /* Name.Function */
-.code-highlight .nl { color: #A0A000 } /* Name.Label */
-.code-highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
-.code-highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
-.code-highlight .nv { color: #19177C } /* Name.Variable */
-.code-highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
-.code-highlight .w { color: #bbbbbb } /* Text.Whitespace */
-.code-highlight .mb { color: #666666 } /* Literal.Number.Bin */
-.code-highlight .mf { color: #666666 } /* Literal.Number.Float */
-.code-highlight .mh { color: #666666 } /* Literal.Number.Hex */
-.code-highlight .mi { color: #666666 } /* Literal.Number.Integer */
-.code-highlight .mo { color: #666666 } /* Literal.Number.Oct */
-.code-highlight .sa { color: #BA2121 } /* Literal.String.Affix */
-.code-highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
-.code-highlight .sc { color: #BA2121 } /* Literal.String.Char */
-.code-highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */
-.code-highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
-.code-highlight .s2 { color: #BA2121 } /* Literal.String.Double */
-.code-highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
-.code-highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
-.code-highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
-.code-highlight .sx { color: #008000 } /* Literal.String.Other */
-.code-highlight .sr { color: #BB6688 } /* Literal.String.Regex */
-.code-highlight .s1 { color: #BA2121 } /* Literal.String.Single */
-.code-highlight .ss { color: #19177C } /* Literal.String.Symbol */
-.code-highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
-.code-highlight .fm { color: #0000FF } /* Name.Function.Magic */
-.code-highlight .vc { color: #19177C } /* Name.Variable.Class */
-.code-highlight .vg { color: #19177C } /* Name.Variable.Global */
-.code-highlight .vi { color: #19177C } /* Name.Variable.Instance */
-.code-highlight .vm { color: #19177C } /* Name.Variable.Magic */
-.code-highlight .il { color: #666666 } /* Literal.Number.Integer.Long */


More information about the kallithea-general mailing list