Liking cljdoc? Tell your friends :D

Clojars Project GitHub issues License

Reagent wrapper for Highlight.js

A simple Reagent wrapper around the Highlight.js library, with no dependencies except Highlight.js itself via npm (for shadow-cljs).

Quick Start

Step 1. Add Dependency

Add the following project dependency: Clojars Project

Requires that you have reagent as a dependency of your project: Clojars Project

The highlight.js npm library dependency will be pulled in automatically by shadow-cljs via src/deps.cljs :npm-deps.

Step 2. Add Highlight.js Theme

Add a Highlight.js stylesheet to your index.html or equivalent; e.g.:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css" integrity="sha512-hasIneQUHlh06VNBe7f6ZcHmeRTLIaQWFd43YriJ0UND19bvYRauxthDg8E4eVNPm9bRUhr5JGeqH7FRFXQu5g==" crossorigin="anonymous" referrerpolicy="no-referrer" />

Step 3. Use

(ns my-app
  (:require
    [re-highlight.core :refer [highlight]]))
(defn panel
  []
  [highlight
    {:language "clojure"}
    "(defn fibo-recursive [n]\n         (if (or (= n 0) (= n 1))\n           n\n           (+ (fibo-recursive (- n 1)) (fibo-recursive (- n 2)))))"]]])

Step 4. Optional. Add non-Clojure Language Support

Only Clojure support is registered by default. If you are using any other language, you need to explicitly require and register it! E.g.

(require ["highlight.js/lib/languages/rust" :as rust])
(re-highlight/register-language "rust" rust)

License

The MIT License (MIT)

Copyright (c) 2019-2022 Isaac Johnston

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close