Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active June 1, 2019 06:47
Show Gist options
  • Save iporsut/e8f8ca88507e41a67cae5574ab0e4747 to your computer and use it in GitHub Desktop.
Save iporsut/e8f8ca88507e41a67cae5574ab0e4747 to your computer and use it in GitHub Desktop.
Elisp function calling to Ruby for escape and unescape HTML
(defun escape-html (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(delete-region start end)
(call-process-region regionp nil "ruby" nil t nil "-e" "# encoding: utf-8
require 'cgi'
print CGI.escapeHTML(ARGF.read)"))))
(defun unescape-html (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(delete-region start end)
(call-process-region regionp nil "ruby" nil t nil "-e" "# encoding: utf-8
require 'cgi'
print CGI.unescapeHTML(ARGF.read)"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment