Last active
December 10, 2015 05:18
-
-
Save tormaroe/4386546 to your computer and use it in GitHub Desktop.
Small script that modifies the content of the clipboard by HTML encoding dangerous characters and wraps i in a <pre>-tag. Used when blogging source code.
This file contains hidden or 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
| =begin | |
| TO INSTALL DEPENDENCIES | |
| ----------------------- | |
| gem install ffi <-- For Windows users | |
| gem install clipboard | |
| =end | |
| HTML_CODES = { | |
| "&" => "&", | |
| ">" => ">", | |
| "<" => "<", | |
| "\\" => "\", | |
| "\t" => " " | |
| } | |
| def html_wrap tag, content | |
| "<#{tag}>#{content}</#{tag}>" | |
| end | |
| require "clipboard" | |
| source = Clipboard.paste | |
| HTML_CODES.each {|c,s| source.gsub! c,s } | |
| Clipboard.copy html_wrap("pre", source) | |
| hr = "-" * 60 | |
| puts "Copied to clipboard:" | |
| puts hr | |
| puts Clipboard.paste | |
| puts hr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment