GithubHelp home page GithubHelp logo

hilite's Introduction

Hilite 🎨

A small library that generates HTML ready for syntax-highlighting with CSS by parsing markdown documents.

Currently only some OCaml-related syntaxes are supported directly. For example the test.md file can be converted with:

# Cmarkit.Doc.of_string (read_file "test/test.md")
  |> Hilite_markdown.transform
  |> Cmarkit_html.of_doc ~safe:false;;
- : string =
"<p>&quot;Hello World!&quot; in OCaml looks like:</p>\n<pre><code><span class='ocaml-keyword-other'>let</span><span class='ocaml-source'> </span><span class='ocaml-constant-language-unit'>()</span><span class='ocaml-source'> </span><span class='ocaml-keyword-operator'>=</span><span class='ocaml-sourc"... (* string length 609; truncated *)

Customisation

Hilite supports users loading their own grammars so they can do custom, build-time syntax highlighting. Users most provided a collection of textmate grammars to the transformation function.

Here we will use a predefined grammar that comes along with the Hilite library.

# let tm =
    let t = TmLanguage.create () in
    let grammar = TmLanguage.of_yojson_exn Hilite.Grammars.diff in
    TmLanguage.add_grammar t grammar;
    t
val tm : TmLanguage.t = <abstr>

With this we can now highlight code blocks that start with diff.

# Cmarkit.Doc.of_string (read_file "test/test_diff.md")
  |> Hilite_markdown.transform ~lookup_method:`Filetype ~tm
  |> Cmarkit_html.of_doc ~safe:false;;
- : string =
"<p>A diff block!</p>\n<pre><code><span class='patch-punctuation-definition-deleted'>-</span><span class='patch-markup-deleted'>  module Sel = (val if is_osx () then (module Mac)\n</span><span class='patch-punctuation-definition-deleted'>-</span><span class='patch-markup-deleted'>                    e"... (* string length 1176; truncated *)

This example also shows a use off lookup_method to change how TmLanguage finds the grammar based on the code block infostring.

hilite's People

Contributors

patricoferris avatar tmattio avatar panglesd avatar

Stargazers

Andrei-Paul Ionescu avatar Xed avatar Xavier Van de Woestyne avatar Ryan Gibb avatar Bryan Bennett avatar David Sancho avatar  avatar Vincent Laporte avatar Masanori Ogino avatar ᴍᴜǫɪᴜ ʜᴀɴ (韩暮秋) avatar Tim ats avatar Puneeth Chaganti avatar Jeff Carpenter avatar David.Gao avatar Jules Aguillon avatar  avatar Marcello Seri avatar Seb Mondet avatar savi2w avatar Sora Morimoto avatar

Watchers

James Cloos avatar  avatar  avatar

hilite's Issues

Enabling external syntax support and maybe package splitting

Hello! This is a very interesting project, particularly in the world of static site generators, and it would make it easy to do without highlightjs to support the syntax highlighting. But at the moment, I find the package a little too opionated (to be easily usable generically). But I'm not sure what level of maintenance you assign to this package.

Would it be possible to:

  • Propose a core library without dependence on Cmarkit and a hilite_cmarkit library which would act as glue with cmarkit.
  • Allow, at the level of library use, a way to provision your own syntaxes (so as not to depend on hilite release for support of alternative syntaxes)?

Thank you in advance for your response and anyway, thank you very much for this superb library!

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.