Created
January 11, 2014 05:17
-
-
Save mikofski/8367401 to your computer and use it in GitHub Desktop.
pygments JSONFormatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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