Created
August 24, 2012 13:57
-
-
Save gimenete/3450829 to your computer and use it in GitHub Desktop.
SublimeText2 plugin that translates the selected code to HTML
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
Show hidden characters
[ | |
{ | |
"keys": ["command+ctrl+h"], "command": "highlight_code" | |
} | |
] |
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
import sublime, sublime_plugin | |
from subprocess import Popen, PIPE, STDOUT | |
# Transforms the selected code to HTML | |
class HighlightCodeCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
for region in self.view.sel(): | |
content = self.view.substr(region) | |
p = Popen(["/usr/local/bin/node", "/path/to/highlighter.js"], stdout=PIPE, stdin=PIPE, stderr=STDOUT) | |
out = p.communicate(input=content)[0] | |
self.view.replace(edit, region, out) |
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
var hljs = require('highlight.js') | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
var code = '' | |
process.stdin.on('data', function (chunk) { | |
code += chunk | |
}) | |
process.stdin.on('end', function () { | |
console.log('<pre><code>'+hljs.highlightAuto(code).value+'</code></pre>') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment