Permalink
Browse files

add pygments syntax highlighting; some pylons slides

  • Loading branch information...
1 parent 9e03de2 commit aa2a4bf42362905c6409572c1c227e35a9b7c114 @mcdonc mcdonc committed Mar 10, 2011
Showing with 192 additions and 8 deletions.
  1. BIN bfgbook.png
  2. +1 −2 build.sh
  3. BIN pylons-positive-80.png
  4. +92 −0 rst-directive.py
  5. +25 −6 stateof.rst
  6. +1 −0 ui/pylons/pretty.css
  7. +70 −0 ui/pylons/pygments.css
  8. +3 −0 ui/pylons/slides.css
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,2 +1 @@
-rst2s5.py --theme-url=ui/pylons stateof.rst stateof.html
-
+python rst-directive.py --theme-url=ui/pylons stateof.rst stateof.html
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+"""
+ The Pygments reStructuredText directive
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ This fragment is a Docutils_ 0.5 directive that renders source code
+ (to HTML only, currently) via Pygments.
+
+ To use it, adjust the options below and copy the code into a module
+ that you import on initialization. The code then automatically
+ registers a ``sourcecode`` directive that you can use instead of
+ normal code blocks like this::
+
+ .. sourcecode:: python
+
+ My code goes here.
+
+ If you want to have different code styles, e.g. one with line numbers
+ and one without, add formatters with their names in the VARIANTS dict
+ below. You can invoke them instead of the DEFAULT one by using a
+ directive option::
+
+ .. sourcecode:: python
+ :linenos:
+
+ My code goes here.
+
+ Look at the `directive documentation`_ to get all the gory details.
+
+ .. _Docutils: http://docutils.sf.net/
+ .. _directive documentation:
+ http://docutils.sourceforge.net/docs/howto/rst-directives.html
+
+ :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+# Options
+# ~~~~~~~
+
+# Set to True if you want inline CSS styles instead of classes
+INLINESTYLES = False
+STYLE = "fruity"
+
+from pygments.formatters import HtmlFormatter
+
+# The default formatter
+DEFAULT = HtmlFormatter(noclasses=INLINESTYLES, style=STYLE)
+
+# Add name -> formatter pairs for every variant you want to use
+VARIANTS = {
+ # 'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),
+}
+
+
+from docutils import nodes
+from docutils.parsers.rst import directives, Directive
+
+from pygments import highlight
+from pygments.lexers import get_lexer_by_name, TextLexer
+
+class Pygments(Directive):
+ """ Source code syntax hightlighting.
+ """
+ required_arguments = 1
+ optional_arguments = 0
+ final_argument_whitespace = True
+ option_spec = dict([(key, directives.flag) for key in VARIANTS])
+ has_content = True
+
+ def run(self):
+ self.assert_has_content()
+ try:
+ lexer = get_lexer_by_name(self.arguments[0])
+ except ValueError:
+ # no lexer found - use the text one instead of an exception
+ lexer = TextLexer()
+ # take an arbitrary option if more than one is given
+ formatter = self.options and VARIANTS[self.options.keys()[0]] or DEFAULT
+
+ #print >>open('pygments.css', 'w'), formatter.get_style_defs('.highlight')
+ parsed = highlight(u'\n'.join(self.content), lexer, formatter)
+ return [nodes.raw('', parsed, format='html')]
+
+directives.register_directive('sourcecode', Pygments)
+
+from docutils.core import publish_cmdline, default_description
+
+description = ('Generates S5 (X)HTML slideshow documents from standalone '
+ 'reStructuredText sources. ' + default_description)
+
+publish_cmdline(writer_name='s5', description=description)
View
@@ -9,11 +9,8 @@ PyCon 2011: State of Pylons, Turbogears, and repoze.bfg
``repoze.bfg``
--------------
-- Web framework inspired by Pylons, Django and Zope.
-
-.. class:: center
-
- .. image:: bfgbook3d-front.png
+.. image:: bfgbook.png
+ :align: center
``repoze.bfg``
--------------
@@ -28,18 +25,40 @@ PyCon 2011: State of Pylons, Turbogears, and repoze.bfg
- ~28 PyPI packages which depend on repoze.bfg
+Pylons
+------
+
+Pylons Web Framework
+
+.. image:: pylons-positive-80.png
+ :align: center
+
+Pylons
+------
+
+- First released in 2006.
+
+- Latest release of Pylons: 1.0.
+
+- Since May 5, 2010, about 23K downloads.
+
+- ~2400 members of the pylons-discuss maillist as of Mar 5 2011.
+
+- ~60 PyPI packages which depend on Pylons
+
Pyramid
-------
October 2010, ``repoze.bfg`` was forked to become Pyramid, a Pylons Project
subproject.
.. image:: pyramid-positive-80.png
+ :align: center
Sample Application
-------------------
-::
+.. sourcecode:: python
# imports elided
@view_config(route_name='home')
View
@@ -131,3 +131,4 @@ pre.literal-block, pre.doctest-block {background-color: white;}
li:after {content: " [" attr(class) "]"; color: #F88;}
div:before {content: "[" attr(class) "]"; color: #F88;}
*/
+
View
@@ -0,0 +1,70 @@
+.highlight .hll { background-color: #FFFFFF }
+.highlight { background: #FFFFFF; color: #FFFFFF }
+.highlight .c { color: #008800; font-style: italic; background-color: #FFFFFF } /* Comment */
+.highlight .err { color: #000000 } /* Error */
+.highlight .g { color: #000000 } /* Generic */
+.highlight .k { color: #fb660a; font-weight: bold } /* Keyword */
+.highlight .l { color: #000000 } /* Literal */
+.highlight .n { color: #000000 } /* Name */
+.highlight .o { color: #000000 } /* Operator */
+.highlight .x { color: #000000 } /* Other */
+.highlight .p { color: #000000 } /* Punctuation */
+.highlight .cm { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Multiline */
+.highlight .cp { color: #ff0007; font-weight: bold; font-style: italic; background-color: #0f140f } /* Comment.Preproc */
+.highlight .c1 { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Single */
+.highlight .cs { color: #008800; font-style: italic; background-color: #0f140f } /* Comment.Special */
+.highlight .gd { color: #000000 } /* Generic.Deleted */
+.highlight .ge { color: #000000 } /* Generic.Emph */
+.highlight .gr { color: #000000 } /* Generic.Error */
+.highlight .gh { color: #000000; font-weight: bold } /* Generic.Heading */
+.highlight .gi { color: #000000 } /* Generic.Inserted */
+.highlight .go { color: #444444; background-color: #222222 } /* Generic.Output */
+.highlight .gp { color: #000000 } /* Generic.Prompt */
+.highlight .gs { color: #000000 } /* Generic.Strong */
+.highlight .gu { color: #000000; font-weight: bold } /* Generic.Subheading */
+.highlight .gt { color: #000000 } /* Generic.Traceback */
+.highlight .kc { color: #fb660a; font-weight: bold } /* Keyword.Constant */
+.highlight .kd { color: #fb660a; font-weight: bold } /* Keyword.Declaration */
+.highlight .kn { color: #fb660a; font-weight: bold } /* Keyword.Namespace */
+.highlight .kp { color: #fb660a } /* Keyword.Pseudo */
+.highlight .kr { color: #fb660a; font-weight: bold } /* Keyword.Reserved */
+.highlight .kt { color: #cdcaa9; font-weight: bold } /* Keyword.Type */
+.highlight .ld { color: #000000 } /* Literal.Date */
+.highlight .m { color: #0086f7; font-weight: bold } /* Literal.Number */
+.highlight .s { color: #0086d2 } /* Literal.String */
+.highlight .na { color: #ff0086; font-weight: bold } /* Name.Attribute */
+.highlight .nb { color: #000000 } /* Name.Builtin */
+.highlight .nc { color: #000000 } /* Name.Class */
+.highlight .no { color: #0086d2 } /* Name.Constant */
+.highlight .nd { color: #000000 } /* Name.Decorator */
+.highlight .ni { color: #000000 } /* Name.Entity */
+.highlight .ne { color: #000000 } /* Name.Exception */
+.highlight .nf { color: #ff0086; font-weight: bold } /* Name.Function */
+.highlight .nl { color: #000000 } /* Name.Label */
+.highlight .nn { color: #000000 } /* Name.Namespace */
+.highlight .nx { color: #000000 } /* Name.Other */
+.highlight .py { color: #000000 } /* Name.Property */
+.highlight .nt { color: #fb660a; font-weight: bold } /* Name.Tag */
+.highlight .nv { color: #fb660a } /* Name.Variable */
+.highlight .ow { color: #000000 } /* Operator.Word */
+.highlight .w { color: #888888 } /* Text.Whitespace */
+.highlight .mf { color: #0086f7; font-weight: bold } /* Literal.Number.Float */
+.highlight .mh { color: #0086f7; font-weight: bold } /* Literal.Number.Hex */
+.highlight .mi { color: #0086f7; font-weight: bold } /* Literal.Number.Integer */
+.highlight .mo { color: #0086f7; font-weight: bold } /* Literal.Number.Oct */
+.highlight .sb { color: #0086d2 } /* Literal.String.Backtick */
+.highlight .sc { color: #0086d2 } /* Literal.String.Char */
+.highlight .sd { color: #0086d2 } /* Literal.String.Doc */
+.highlight .s2 { color: #0086d2 } /* Literal.String.Double */
+.highlight .se { color: #0086d2 } /* Literal.String.Escape */
+.highlight .sh { color: #0086d2 } /* Literal.String.Heredoc */
+.highlight .si { color: #0086d2 } /* Literal.String.Interpol */
+.highlight .sx { color: #0086d2 } /* Literal.String.Other */
+.highlight .sr { color: #0086d2 } /* Literal.String.Regex */
+.highlight .s1 { color: #0086d2 } /* Literal.String.Single */
+.highlight .ss { color: #0086d2 } /* Literal.String.Symbol */
+.highlight .bp { color: #000000 } /* Name.Builtin.Pseudo */
+.highlight .vc { color: #fb660a } /* Name.Variable.Class */
+.highlight .vg { color: #fb660a } /* Name.Variable.Global */
+.highlight .vi { color: #fb660a } /* Name.Variable.Instance */
+.highlight .il { color: #0086f7; font-weight: bold } /* Literal.Number.Integer.Long */
View
@@ -8,3 +8,6 @@
/* styles that make the slides look good */
@import url(pretty.css);
+
+/* styles that make Pygments work */
+@import url(pygments.css);

0 comments on commit aa2a4bf

Please sign in to comment.