aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2010-06-29 08:11:53 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2010-06-29 08:12:40 -0700
commit8c243f31782ea3f4053d5a4a4f7a73f413b5d6ca (patch)
tree668850175d853bc0dd0c0419eeadeeff31e0b43f
parent90faaccdb98a7cfdcebc5d0a8101b664604acef0 (diff)
downloadpycco-8c243f31782ea3f4053d5a4a4f7a73f413b5d6ca.tar.gz
pycco-8c243f31782ea3f4053d5a4a4f7a73f413b5d6ca.zip
Using the actual pygments module rather than the command line utility
-rw-r--r--pocco.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/pocco.py b/pocco.py
index 0f12260..7a51c23 100644
--- a/pocco.py
+++ b/pocco.py
@@ -73,19 +73,10 @@ def parse(source, code):
# wherever our markers occur.
def highlight(source, sections):
language = get_language(source)
- pygments = Popen(["pygmentize", "-l", language["name"], "-f", "html"],
- stderr=PIPE,
- stdin=PIPE,
- stdout=PIPE)
-
- pygments.stdin.write(language["divider_text"].join(section["code_text"] for section in sections))
- output = ""
- while pygments.returncode is None:
- stdout, stderr = pygments.communicate()
- if stderr:
- print stderr
- if stdout:
- output += stdout
+
+ output = pygments.highlight(language["divider_text"].join(section["code_text"] for section in sections),
+ language["lexer"],
+ formatters.get_formatter_by_name("html"))
output = output.replace(highlight_start, "").replace(highlight_end, "")
fragments = re.split(language["divider_html"], output)
@@ -115,11 +106,13 @@ def generate_html(source, sections):
#### Helpers & Setup
# Import our external dependencies.
+import pygments
import pystache
import re
import sys
from markdown import markdown
from os import path
+from pygments import lexers, formatters
from subprocess import Popen, PIPE
# A list of the languages that Pocco supports, mapping the file extension to
@@ -145,6 +138,9 @@ for ext, l in languages.items():
# on this to recover the original sections.
l["divider_html"] = re.compile(r'\n*<span class="c">' + l["symbol"] + 'DIVIDER</span>\n*')
+ # Get the Pygments Lexer for this language.
+ l["lexer"] = lexers.get_lexer_by_name(l["name"])
+
# Get the current language we're documenting, based on the extension.
def get_language(source):
return languages[ source[source.rindex("."):] ]