Skip to content

Instantly share code, notes, and snippets.

@phpnode
Created September 20, 2012 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phpnode/3758590 to your computer and use it in GitHub Desktop.
Save phpnode/3758590 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