Skip to content

Latest commit

 

History

History
94 lines (66 loc) · 2.55 KB

README.org

File metadata and controls

94 lines (66 loc) · 2.55 KB

html-to-hiccup

Emacs package that turns HTML into Hiccup syntax, a notation popular when doing Clojure/ClojureScript web development.

Installation

use-package (recommended)

If you’re using use-package then just drop this snippet in your .emacs.d/init.el. Change the keybinding to something more practical.

(use-package html-to-hiccup
  :bind (:map clojure-mode-map
         ("H-h" . html-to-hiccup-convert-region)
         ("H-y" . html-to-hiccup-yank))
  :config
  (setq html-to-hiccup-use-shorthand-p t))

MELPA

(package-initialize)           ;; you probably don't need to initialize + refresh
(package-refresh-contents)     ;; but it won't hurt
(package-install 'html-to-hiccup)

From Github

git clone https://github.com/plexus/html-to-hiccup.git
cd html-to-hiccup
cp html-to-hiccup.el ~/.emacs.d

Usage

Require html-to-hiccup, select a snippet of HTML, and do M-x html-to-hiccup-convert-region to replace the selected HTML with Hiccup. If you have a HTML snippet in your kill ring (e.g. copied from a website) you can paste it as Hiccup with M-x html-to-hiccup-yank.

This package does not come with a default keybinding, you’re free to bind it to whatever key combo you like.

(require 'html-to-hiccup)

(define-key clojure-mode-map (kbd "H-h") #'html-to-hiccup-convert-region)
(define-key clojure-mode-map (kbd "H-y") #'html-to-hiccup-yank)

If you’re using CIDER, a cool thing to do is to call `cider-format-edn-region` on the region after conversion.

Example

Turns this

<div id="thing">
  <span class="important">Enjoy your lemonade</span>
</div>

into this

[:div#thing [:span.important "Enjoy your lemonade"]]

Tests

You can either run the tests interactively by loading the test file in Emacs with M-x load-file and then M-x ert RET t (see ERT - running tests interactively), or from the command line by invoking Eldev as

eldev test

Attribution

I had an earlier, hacky version of this code lying around before. Jack Rusher was so kind to clean it up and give me feedback during EuroClojure 2016. Thanks, Jack! It seemed a waste not to put it on MELPA after that.

License

Mozilla Public License 2.0

© 2016 Arne Brasseur, Jack Rusher