Skip to content

Instantly share code, notes, and snippets.

@joar
Forked from phpnode/gist:3758590
Created September 21, 2012 05:45
Show Gist options
  • Save joar/3759922 to your computer and use it in GitHub Desktop.
Save joar/3759922 to your computer and use it in GitHub Desktop.
from pygments.formatter import Formatter
import json
class Formatter(Formatter):
name = 'JSON'
aliases = ['json']
filenames = []
def format(self, tokensource, outfile):
arr = []
for ttype, value in tokensource:
arr.append({"type": str(ttype), "value": value})
outfile.write(json.dumps(arr, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment