I recently added FileMaker syntax highlighting to the Evernote package for Sublime Text 3. Here’s the quick version.
Write your lexer as a pygments plugin.
Don’t forget to include the
__all__variable in your lexer’s module scope.
Once you’ve got your pygments plugin put together you can use pygmentize generally. But it takes a little more work to get it into the Evernote Sublime Text 3 package.
Install the Evernote package from GitHub, not Package Control.
You need to patch the installation of pygments inside the Evernote package, which you shouldn’t try to do from the Package Control version.
- If you’ve already installed the plugin, use package control to remove it.
- Close Sublime Text.
On OS X Yosemite, open Terminal and run the following commands:
$ cd "~/Library/Application Support/Sublime Text 3/Packages" $ git clone https://github.com/bordaigorl/sublime-evernote.git Evernote
- Restart Sublime Text and confirm that the Evernote package is working.
pygmentsfrom source in the Evernote package.
pygmentsdistributed with the Evernote package isn’t the full repo that you need to add a new lexer. You’ll need some extras to install a new lexer.
Nuke the included
pygmentsmodule, download the current repo, and link the module subdirectory to where the Evernote package expects it.
$ cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Evernote/lib/ $ rm -r pygments $ hg clone https://bitbucket.org/birkenfeld/pygments-main pygments-main $ ln -s pygments-main/pygments pygments
Incorporate the plugin into the pygments module in the Evernote ST3 package.
Incorporating the plugin is technically a little tricky, but it’s very mechanical.
lexer.pyto pygments with an original name.
$ cd pygments-main/pygments/lexers/ $ cp ~/Source/FileMakerLexer/filemakerlexer/lexer.py fmcalc.py
Recreate the map files for
pygmentsto link your lexer.
$ cd ../.. $ make mapfiles
Copy an example file to
pygments-main/tests/examplefilesfor testing and run the pygments tests.
$ cp ~/Source/FileMakerLexer/test_data/#.fmfn tests/examplefiles/filemaker_calculation.fmfn $ make test
Close any tabs that use the Evernote package and then restart Sublime Text.
You should now be able to use your new lexer in fenced code blocks in the Evernote plugin. That means fenced code blocks using GitHub-flavored MarkDown will upload to Evernote with syntax highlighting. You won’t see the syntax highlighting in Sublimte itself.
For example, the following MarkDown:
```filemaker Let ( $error = ErrorFmpGetLast ( "" ) ; "" ) ```
now yields the following code block:
Let ( $error = ErrorFmpGetLast ( "" ) ; "" )