Closed konklone closed 11 years ago
This would best be done in the upstream underlying Pygments library, which is where our highlighting will come from.
All right, I migrated it over there: https://bitbucket.org/birkenfeld/pygments-main/issue/884/support-for-json-snippets
I found this in a README and left an issue on markup. It's really grating on READMEs. I think that when this gets done on pygments it will probably be something to configure, so there will still be action for this project to take. I think perhaps that being forgiving in JSON is desirable for READMEs but not for files, so perhaps linguist should have a way to have different rules for README code if it doesn't already.
BTW pygments doesn't seem to be as strict about other languages besides JSON.
The highlighting is apparently the same between JavaScript and JSON now. Way to go! So just use js
instead of json
if you don't want JSON validation.
I'd like to add support for a slight modification of the JSON lexer - that of JSON snippets, where surrounding braces or brackets are allowed to be missing.
This is a pattern I use in @sunlightlabs' API documentation, to document sections of response objects: http://sunlightlabs.github.io/congress/legislators.html#fields/names
Right now, this is accomplished through a hack - in the original markdown documents, there are surrounding braces, but the content they surround is not indented. After documents are run through the syntax highlighter, any unindented JSON blocks inside braces get their braces removed. Without this hack, simply excluding the braces in the original code means the syntax highlighting for JSON doesn't trigger.
I've been poking through this repository, and @tmm1's pygments.rb, and the underlying pygments library, and I can't figure out how to begin doing the work myself. In what repo would I put this code, and what's the easiest way to go about it? Is there a way to "subclass" the existing JSON lexer and tweak the rules?