Live data from Hacker News

Add Syntax Highlighting To Your Blog With VIM

alexanderle.com

21–30 of 41 posts

Re: Add Syntax Highlighting To Your Blog With VIM

#21
post #3

This is an awesome feature. Naturally, Emacs also supports this, right out of the box. Just use M-x htmlfontify-buffer. Here's a sample of the output: http://inst.eecs.berkeley.edu/~tikhon/Interpreter.hs.html EDIT: Also, note that while the VIM one uses a bunch of tags, the Emacs one uses a bunch of span tags with reasonable class names like "function-name" or "string", so it produces much nicer code and is easy to u…

VIM too can be told use span tags and css rather than lots of messy font tags, relevant .vimrc goodness:

let html_use_css=1

let use_xhtml = 1

Re: Add Syntax Highlighting To Your Blog With VIM

#22
post #14

Earlier quoted context omitted.

M-x htmlize-buffer

Hmm, on mine (GNU Emacs 23.3.1 on Fedora) it's M-x htmlfontify-buffer. It came with the Emacs distribution as standard. I suspect htmlize-buffer is either from some external package or from a different version of Emacs.

It's from an external package called htmlize http://www.emacswiki.org/emacs/Htmlize

Re: Add Syntax Highlighting To Your Blog With VIM

#24
post #6

Probably a little too off-topic, but after years of using similar "custom" methods of doing syntax highlighting, trying several WordPress plugins to automatically highlight, and several other options, I have found embedding GitHub Gists in blog posts to be the most reliable and lowest maintenance approach. This probably won't matter to most people, but if you're the kind of person that has tutorials or examples or an…

The key is to store the original, and to display the tohtml output. I'm kinda skeptical about embedding stuff from external sites; the more external dependencies you have, the less reliable your own blog becomes.

I guess he estimates that is is more likely for him to loose the original than for gist to shutdown.

Re: Add Syntax Highlighting To Your Blog With VIM

#25
post #20
post #19

Earlier quoted context omitted.

Unfortunately Gists aren't very viewable on a mobile (certainly on an iPhone) as they're truncated and there's no way to scroll to the right. A number of times I've been disappointed to find articles (The Zen of R that's on the front page at the moment, for example) that I can't read. There's a button to view in raw but it's a bit of a shame that I can't view the content with highlighting and proper (non)wrapping.

> (...) and there's no way to scroll to the right Just swipe using two fingers, and everything works as intended.

Oh wow. Thanks!

Re: Add Syntax Highlighting To Your Blog With VIM

#26
post #19

Probably a little too off-topic, but after years of using similar "custom" methods of doing syntax highlighting, trying several WordPress plugins to automatically highlight, and several other options, I have found embedding GitHub Gists in blog posts to be the most reliable and lowest maintenance approach. This probably won't matter to most people, but if you're the kind of person that has tutorials or examples or an…

Unfortunately Gists aren't very viewable on a mobile (certainly on an iPhone) as they're truncated and there's no way to scroll to the right. A number of times I've been disappointed to find articles (The Zen of R that's on the front page at the moment, for example) that I can't read. There's a button to view in raw but it's a bit of a shame that I can't view the content with highlighting and proper (non)wrapping.

Gists also don't show up in some (most?) RSS readers.

Re: Add Syntax Highlighting To Your Blog With VIM

#27
post #15

I hoped for a command line option. Isn't there some plugin for sed maybe? Like sed something code.html

vim -f +'syn on' +'run! syntax/2html.vim' +'wq' +'q' [file]

produces file.html

Or, use perl's Text::VimColor http://search.cpan.org/~rwstauner/Text-VimColor-0.14/lib/Tex...

Re: Add Syntax Highlighting To Your Blog With VIM

#29

Doesn't basically every text editor support something like this? E.g. Notepad++ has NppExport->Export to HTML (Example output: https://gist.github.com/2056841 )

It surprisingly does a good job of mimicking the editor theme: http://jsfiddle.net/9f5PQ/

Although it creates some blank CSS.

Re: Add Syntax Highlighting To Your Blog With VIM

#30

Unfortunately, with the advent of TextMate/Sublime Text 2, I'm always disappointed when returning to VIM's syntax highlighting. It leaves a lot to be desired. I'd love a JavaScript plugin to parse TextMate theme files and highlight blocks of code.

I don't see why... I've been able to do almost any color scheme from textmate or other editors. I have my favorite color scheme from textmate in VIM (Sunburst). Just make sure you're either using gvim or your terminal has 256 colors turned on.
Post reply on HN