Giter Club home page Giter Club logo

html-to-hiccup's Introduction

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

html-to-hiccup's People

Contributors

plexus avatar dotemacs avatar dakra avatar jackrusher avatar olymk2 avatar syohex avatar ikappaki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.