Skip to content

Instantly share code, notes, and snippets.

@mikofski
Created January 11, 2014 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikofski/8367401 to your computer and use it in GitHub Desktop.
Save mikofski/8367401 to your computer and use it in GitHub Desktop.
pygments JSONFormatter
from pygments.lexers import MatlabLexer
from pygments.formatter import Formatter
from pygments.token import STANDARD_TYPES
from pygments import highlight
class JSONFormatter(Formatter):
def format(self, tokensource, outfile):
tokensource = [{STANDARD_TYPES[k]: v} for k, v in tokensource]
json.dump(tokensource, outfile)
code = """function [outputs] = myfun(inputs)
% MYFUN a matlab function
% [OUTPUTS] = MYFUN(INPUTS)
outputs = inputs
end"""
print highlight(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment