Syntax Highlighting for code regions
-
benny
- State changed from new to accepted
I've actually already played with syntax highlighting some time ago, but I didn't finish it. It's non-trivial to make it work well, but I think I was on the right track. If you want to try it out then this is how to enable it:
sudo easy_install pygments defaults write com.freron.MailMate MmCodeStylingEnabled -bool YESIt uses the
pygmentizecommand line tool with inlining of the styling. It is currently hardcoded to usestyle=colorful.Note: I'm pretty sure it's buggy and I don't have time to work on it right now. You are welcome to report issues (or tell me it doesn't work at all), but I cannot promise to fix it soon :-)
-
Tom Scogland
I happen to have pygments installed, for minted as one does, and with that defaults command written it works quite nicely. As far as I can tell from a quick test anyway.
Somehow I was under the impression you would prefer a fully native option integrated into the markdown system rather than another command line tool, hence the thought on GNU Highlight which recently added on a C++ library interface. Doing it with pygments is certainly good with me though. In fact, pulling in a python-based markdown pipeline would be pretty nice for extensibility (probably dreaming here, but still...).
I'm guessing when you say hardcoded, you mean hardcoded somewhere we outsiders can't really modify. Any chance of a hidden option to switch the style out, or maybe a pointer to how pygments/pygmentize is being invoked so I can interpose something?
-
Tom Scogland
Overall this is working great, but there does appear to be a bug in the formatting where the $ character is used. Since lighthouse eats the syntax for breakfast, and doesn't seem to have working verbatim support for backticks, the block bounds are removed below, but imagine the triple-backtick syntax before the language name.
In a bash block like this, the $ and the name after it simply disappear:
bash
echo $mehAdding a backslash lets it through, but highlights it oddly. Making it a language-free block restores the verbatim semantics to it. Switching it to a non-bash language makes life yet more interesting.
c
echo $meh
echo "$meh"Putting it in a C language context, as obviously incorrect as the syntax is for C, prints this:
echo $meh
echo ""So... somewhere there is an odd escaping problem between shell variable expansions and quotes.
-
benny
Thanks, that was a stupid bug.
I fixed it and it should work in the next update.
Now, I wonder what Lighthouse does with a code segment sent by email:
/bin/bash echo $meh <pre><code> And yes, the style is currently really hardcoded. I'm not sure how it is best made configurable. I guess it's yet another hidden preference. I'll think about it ;-)</code> </pre> -
benny
Hmm, didn't go to well with Lighthouse, but I cannot see that MailMate is to blame.
-
Tom Scogland
Thanks Benny!
I apologize if I gave the impression that MailMate was to blame for the Lighthouse issue I mentioned, it isn't. The issue I was running into was that even using the triple-at-sign syntax for verbatim blocks doesn't escape backticks in lighthouse's markup for some reason. As a result, I couldn't put in the exact syntax that was causing issues without spurious and rather odd piles of partially escaped HTML tags, rather like you ended up with. This was actually putting it in through the web form, where a properly escaped version of the bash block I had earlier comes out like this:
```bash echo $mehThanks again for the quick replies, and fixing up the quoting bug for that matter. -
benny
Ah, that looks a bit like what happened to my email reply. Maybe it's related.
-
benny
Testing again:
echo $mehMaybe it works better with
~~~. -
benny
Ok, seems we should use
~~~and the code styling done by MailMate is definitely lost. -
Dmitry
I've executed
Quit Mailmate, opened it again.sudo easy_install pygments defaults write com.freron.MailMate MmCodeStylingEnabled -bool YES
Tried to paste some Scala code into ``` block, it did not work. Neither did it work with java.
Are some additional actions required to make it work?Thanks
-
benny
@dmitry: Try providing the programming language explicitly:
```scala asasd ``` -
Felix S
Since rev 5141 this secret feature seems broken for me ...
-
benny
- State changed from accepted to fixcommitted
The (still experimental) code styling feature is now handled in a different way. There is a bit about it here.
I've also changed some things with respect to how it works such that installing
pygmentsis no longer necessary. It's also worth noting that alternative styles can be installed. For example, this should enable github-style styling:sudo easy_install pygments-style-github defaults write com.freron.MailMate MmDefaultPygmentsStyleName githubHopefully I'll soon add GUI settings for enabling code styling since it's almost a complete feature.
-
Tom Scogland
The new bundle for this does not appear to work. I have it installed, and the filter programs it installs work if invoked on the command line with appropriate environment variables, but mailmate never seems to invoke them, or install a command to let me invoke them. Is there a trick to making it work, or debug it?
-
benny
@Tom: Sorry, this functionality is broken until I've finished implementing various features related to handling HTML (including syntax highlighting). I'll have some kind of official beta release when that is complete.
-
Tom Scogland
@benny, any news here?
-
benny
@Tom: If you write me an email then I can point you to a private beta. I'm not quite ready to release it as a public beta/test version. Use “Help ▸ Send Feedback”.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.