From f8a68adfb0988ee659302e3134b46d2124a5585f Mon Sep 17 00:00:00 2001 From: Rahiel Kasim Date: Sat, 23 Apr 2016 14:12:15 +0200 Subject: [PATCH] add some code highlighting --- website/static/website/code.css | 72 ++++++++++++++++++++++++++++ website/static/website/example.py | 16 +++++++ website/templates/website/index.html | 34 ++++++++----- 3 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 website/static/website/code.css create mode 100644 website/static/website/example.py diff --git a/website/static/website/code.css b/website/static/website/code.css new file mode 100644 index 0000000..3c32114 --- /dev/null +++ b/website/static/website/code.css @@ -0,0 +1,72 @@ +.hll { background-color: #ffffcc } +.c { color: #8f5902; font-style: italic } /* Comment */ +.err { color: #a40000; border: 1px solid #ef2929 } /* Error */ +.g { color: #000000 } /* Generic */ +.k { color: #204a87; font-weight: bold } /* Keyword */ +.l { color: #000000 } /* Literal */ +.n { color: #000000 } /* Name */ +.o { color: #ce5c00; font-weight: bold } /* Operator */ +.x { color: #000000 } /* Other */ +.p { color: #000000; font-weight: bold } /* Punctuation */ +.ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */ +.cm { color: #8f5902; font-style: italic } /* Comment.Multiline */ +.cp { color: #8f5902; font-style: italic } /* Comment.Preproc */ +.cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */ +.c1 { color: #8f5902; font-style: italic } /* Comment.Single */ +.cs { color: #8f5902; font-style: italic } /* Comment.Special */ +.gd { color: #a40000 } /* Generic.Deleted */ +.ge { color: #000000; font-style: italic } /* Generic.Emph */ +.gr { color: #ef2929 } /* Generic.Error */ +.gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.gi { color: #00A000 } /* Generic.Inserted */ +.go { color: #000000; font-style: italic } /* Generic.Output */ +.gp { color: #8f5902 } /* Generic.Prompt */ +.gs { color: #000000; font-weight: bold } /* Generic.Strong */ +.gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.gt { color: #a40000; font-weight: bold } /* Generic.Traceback */ +.kc { color: #204a87; font-weight: bold } /* Keyword.Constant */ +.kd { color: #204a87; font-weight: bold } /* Keyword.Declaration */ +.kn { color: #204a87; font-weight: bold } /* Keyword.Namespace */ +.kp { color: #204a87; font-weight: bold } /* Keyword.Pseudo */ +.kr { color: #204a87; font-weight: bold } /* Keyword.Reserved */ +.kt { color: #204a87; font-weight: bold } /* Keyword.Type */ +.ld { color: #000000 } /* Literal.Date */ +.m { color: #0000cf; font-weight: bold } /* Literal.Number */ +.s { color: #4e9a06 } /* Literal.String */ +.na { color: #c4a000 } /* Name.Attribute */ +.nb { color: #204a87 } /* Name.Builtin */ +.nc { color: #000000 } /* Name.Class */ +.no { color: #000000 } /* Name.Constant */ +.nd { color: #5c35cc; font-weight: bold } /* Name.Decorator */ +.ni { color: #ce5c00 } /* Name.Entity */ +.ne { color: #cc0000; font-weight: bold } /* Name.Exception */ +.nf { color: #000000 } /* Name.Function */ +.nl { color: #f57900 } /* Name.Label */ +.nn { color: #000000 } /* Name.Namespace */ +.nx { color: #000000 } /* Name.Other */ +.py { color: #000000 } /* Name.Property */ +.nt { color: #204a87; font-weight: bold } /* Name.Tag */ +.nv { color: #000000 } /* Name.Variable */ +.ow { color: #204a87; font-weight: bold } /* Operator.Word */ +.w { color: #f8f8f8; text-decoration: underline } /* Text.Whitespace */ +.mb { color: #0000cf; font-weight: bold } /* Literal.Number.Bin */ +.mf { color: #0000cf; font-weight: bold } /* Literal.Number.Float */ +.mh { color: #0000cf; font-weight: bold } /* Literal.Number.Hex */ +.mi { color: #0000cf; font-weight: bold } /* Literal.Number.Integer */ +.mo { color: #0000cf; font-weight: bold } /* Literal.Number.Oct */ +.sb { color: #4e9a06 } /* Literal.String.Backtick */ +.sc { color: #4e9a06 } /* Literal.String.Char */ +.sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */ +.s2 { color: #4e9a06 } /* Literal.String.Double */ +.se { color: #4e9a06 } /* Literal.String.Escape */ +.sh { color: #4e9a06 } /* Literal.String.Heredoc */ +.si { color: #4e9a06 } /* Literal.String.Interpol */ +.sx { color: #4e9a06 } /* Literal.String.Other */ +.sr { color: #4e9a06 } /* Literal.String.Regex */ +.s1 { color: #4e9a06 } /* Literal.String.Single */ +.ss { color: #4e9a06 } /* Literal.String.Symbol */ +.bp { color: #3465a4 } /* Name.Builtin.Pseudo */ +.vc { color: #000000 } /* Name.Variable.Class */ +.vg { color: #000000 } /* Name.Variable.Global */ +.vi { color: #000000 } /* Name.Variable.Instance */ +.il { color: #0000cf; font-weight: bold } /* Literal.Number.Integer.Long */ diff --git a/website/static/website/example.py b/website/static/website/example.py new file mode 100644 index 0000000..2960011 --- /dev/null +++ b/website/static/website/example.py @@ -0,0 +1,16 @@ +from telegram.ext import Updater, CommandHandler + +def start(bot, update): + bot.sendMessage(update.message.chat_id, text='Hello World!') + +def hello(bot, update): + bot.sendMessage(update.message.chat_id, + text='Hello {0}'.format(update.message.from_user.name)) + +updater = Updater('YOUR TOKEN HERE') + +updater.dispatcher.addHandler(CommandHandler('start', start)) +updater.dispatcher.addHandler(CommandHandler('hello', hello)) + +updater.start_polling() +updater.idle() diff --git a/website/templates/website/index.html b/website/templates/website/index.html index 585c172..4110c0f 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -21,6 +21,7 @@ + @@ -59,26 +60,33 @@

Not just a Python wrapper around the

It's fun

-
from telegram.ext import Updater, CommandHandler
+        {% comment %}
+          The style sheet is generated with
+          pygmentize -f html -S tango > code.css
+          and the highlighted code underneath with
+          pygmentize -f html example.py
+        {% endcomment %}
+
from telegram.ext import Updater, CommandHandler
 
-def start(bot, update):
-    bot.sendMessage(update.message.chat_id, text='Hello World!')
+def start(bot, update):
+    bot.sendMessage(update.message.chat_id, text='Hello World!')
 
-def hello(bot, update):
-    bot.sendMessage(update.message.chat_id,
-                    text='Hello {0}'.format(update.message.from_user.name))
+def hello(bot, update):
+    bot.sendMessage(update.message.chat_id,
+                    text='Hello {0}'.format(update.message.from_user.name))
 
-updater = Updater('YOUR TOKEN HERE')
+updater = Updater('YOUR TOKEN HERE')
 
-updater.dispatcher.addHandler(CommandHandler('start', start))
-updater.dispatcher.addHandler(CommandHandler('hello', hello))
+updater.dispatcher.addHandler(CommandHandler('start', start))
+updater.dispatcher.addHandler(CommandHandler('hello', hello))
 
-updater.start_polling()
-updater.idle()
+updater.start_polling() +updater.idle() +

Easy to setup

-
$ pip install python-telegram-bot==4.0rc1
-$ python bot.py
+
$ pip install python-telegram-bot==4.0rc1
+$ python bot.py

And it is free

python-telegram-bot is distributed under a