The aim of this Markdown library is to provide a pure Elm implementation of Markdown which offers a small set of optional extensions:
This **is** a test: $a^2 + b^2 = c^2$
are properly rendered.For simple applications, use the Markdown.Elm and Markdown.Option modules,
as in this example:
sourceText = "This **is** a test."
Markdown.Render.toHtml Standard sourceText
|> Html.map MarkdownMsgTo render mathematical text, do something like this:
sourceText = "Use $a^2 + b^2 = c^2$."
Markdown.Render.toHtml ExtendedMath sourceText
|> Html.map MarkdownMsgThe Markdown.Option module exports ExtendedMath while Markdown.Render
exposes MarkdownMsg.
For the ExtendedMath option, take a look at ./Editor/simplest/ in the
source code to see what to do.
You will need some Javascript, incuding MathJax 3. Here is a
direct linkd .
There are three versions
of the demo: ./editor/simplest/,
./editor/simple/, and editor/fancy. The second and third
include extra bells, whistles and optimizations
that are useful for interactive editing environments
and documents with a lot of mathematics.
See markdown.minilatex.app for the latest version the fancy demo.
NOTE: This package is still evolving relatively rapidly. I regret publishing so many updates, but I am using it in several apps, and this is the only way I know how to encapsulate the complexity, work with the CI build systems, and keep my sanity
$ cd to ./app-demo-fancy
$ npm install
$ npm startThe style used by the library is entirely determined by the
definitions of the CSS classes that you refer to in your
index.html. The ones used for the demo app are found
in ./app-demo/assets/style.css and ./app-demo-fancy/assets/style.css
You can easily reconfigure the CSS to satsify your
own esthetics.
I am trying to be conservative about extensions to Markdown. However, there are two that I thought important enough to add: tables, poetry blocks and verbatim text. Poetry blocks are are like quotation blocks, except that they begin with ">>" instead of ">". Line endings are respected in poetry blocks. Verbatim blocks are like code blocks, except that they are set off by four backticks instead of three. No syntax coloring is applied to verbatim blocks.
The usual  does the usual thing, with the image
scaled to 100% of the width. You can
also say  or
 to float the image left or right at
40% width. The widths are defined in style.css.
If you wish to write your own renderer, or do other fancy things, you will want to produce and manpulate the AST:
Markdown.Parse.toMDBlockTree : Version
-> Option -> Document -> Tree MDBlockwhere Version is an integer and Document is a type alias for String.
This is also useful if you wish to transform the abstract syntax tree before
rendering it. The Version parameter may be set to zero if you do not
have to worry about updated thd ids of rendered elements in an interactive
editing environment.
The fancy demo app now uses pure Elm text editor. It is very much a work in progress.
Please write me at [email protected] or post an issue on the Github repository regarding bugs or anything else. I will steer this library towards the Commonmark spec to the greatest extent possible by the method of successive approximations
Greatly simplified the API. Now there are just three exported
modules, Markdown.Option, Markdown.Render, and Markdown.Parse.
The latter is needed only in advanced applications.
Changed the return type of the rendering functions, e.g.,
toHtml : Option -> String -> Html msg becomes
toHtml : Option -> String -> Html MarkdownMsg. This change
makes the rendered text "active," e.g., can respond to clicks.
See next item.
Added sourceMap : Tree MDBlockWithId -> BiDict String String in the
Markdown.Parse module as a hook for host programs to implement
bidrectional sync of source and rendered text.
Thanks to Folkert de Vries and Luke Westby. A shout-out to Folkert for an optimiztaion of the pure text rendering (10 x speedup).