Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Replaced marked with markdown-it
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcurry committed May 19, 2016
1 parent e835b98 commit d9c8693
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 65 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Markdown in Elm

This package is for markdown parsing and rendering. It is based on the [marked][] project
which focuses on speed.
This package is for markdown parsing and rendering. It is based on the
[markdown-it][] project which focuses on speed.

[marked]: https://github.com/chjj/marked
[markdown-it]: https://github.com/markdown-it/markdown-it

## Basic Usage

Expand Down Expand Up @@ -33,4 +33,3 @@ make sure that your page/app binds a version of that library
(supporting the languages you want to handle) to `window.hljs` in
Javascript. [This is how package.elm-lang.org does
that.](https://github.com/elm-lang/package.elm-lang.org/blob/e0b7aa4282038475612722ff7a57195866f8645b/backend/ServeFile.hs#L54)

4 changes: 2 additions & 2 deletions elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.0.0",
"version": "4.0.0",
"summary": "Fast markdown parsing and rendering",
"repository": "https://github.com/evancz/elm-markdown.git",
"license": "BSD3",
Expand All @@ -15,4 +15,4 @@
"elm-lang/html": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
}
}
76 changes: 50 additions & 26 deletions src/Markdown.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Markdown exposing
)

{-| A library for markdown parsing. This is just an Elm API built on top of the
[marked](https://github.com/chjj/marked) project which focuses on speed.
[markdown-it](https://github.com/markdown-it/markdown-it) project which focuses
on speed.
# Parsing Markdown
@docs toHtml
Expand Down Expand Up @@ -36,26 +37,38 @@ toHtml attrs string =

{-| Some parser options so you can tweak things for your particular case.
* `githubFlavored` &mdash; overall reasonable improvements on the original
* `full` &mdash; overall reasonable improvements on the original
markdown parser as described [here][gfm]. This includes stuff like [fenced
code blocks][fenced]. There are some odd parts though, such as [tables][]
and a setting to turn all newlines into newlines in the resulting output,
so there are settings to turn those on or off based on your preference.
code blocks][fenced] and [tables][].
* `html` &mdash; this determines if raw HTML should be allowed. If you
are parsing user markdown or user input can somehow reach the markdown
parser, you should almost certainly turn off HTML. If it is just you
writing markdown, turning HTML on is a nice way to do some tricks if
it is needed.
* `breaks` &mdash; This will automatically convert `\n` in paragraphs
to `<br>`.
* `langPrefix` &mdash; CSS language class prefix for fenced blocks. Can be
useful for external highlighters.
* `defaultHighlighting` &mdash; a default language to use for code blocks that do
not have a language tag. So setting this to `Just "elm"` will treat all
unlabeled code blocks as Elm code. (This relies on [highlight.js][highlight]
as explained in the README [here](../#code-blocks).)
* `sanitize` &mdash; this determines if all HTML should be escaped. If you
are parsing user markdown or user input can somehow reach the markdown
parser, you should almost certainly turn on sanitation. If it is just you
writing markdown, turning sanitation off is a nice way to do some HTML
tricks if it is needed.
* `linkify` &mdash; This will automatically convert URL-like text to links.
* `smartypants` &mdash; This will automatically upgrade quotes to the
* `typographer` &mdash; This will automatically upgrade quotes to the
prettier versions and turn dashes into [em dashes or en dashes][dash]
* `quotes` &mdash; replace the "smart" double/single quotes that typographer
adds when it is enabled. Examples:
- Russian &mdash; `{ dl = "«", dr = "»", sl = "„", sr = "“" }`
- German &mdash; `{ dl = "„", dr = "“", sl = "‚", sr = "‘" }`
- French &mdash; `{ dl = "«\xA0", dr = "\xA0»", sl = "‹\xA0", sr = "\xA0›" }`
[gfm]: https://help.github.com/articles/github-flavored-markdown/
[fenced]: https://help.github.com/articles/github-flavored-markdown/#fenced-code-blocks
Expand All @@ -64,36 +77,47 @@ toHtml attrs string =
[dash]: http://en.wikipedia.org/wiki/Dash
-}
type alias Options =
{ githubFlavored : Maybe { tables : Bool, breaks : Bool }
{ full : Bool
, html : Bool
, breaks : Bool
, langPrefix : Maybe String
, defaultHighlighting : Maybe String
, sanitize : Bool
, smartypants : Bool
, linkify : Bool
, typographer : Bool
, quotes : Maybe { dl : String, dr : String, sl : String, sr : String }
}

{-| The `Options` used by the `toHtml` function.
{-| The `Options` used by the `toElement` and `toHtml` functions.
{ githubFlavored = Just { tables = False, breaks = False }
, defaultHighlighting = Nothing
, sanitize = False
, smartypants = False
{ full = True
, html = True
, breaks = True
, langPrefix = Just "custom-class-"
, defaultHighlighting = Just "markdown"
, linkify = True
, typographer = True
, quotes = Just { dl = "«", dr = "»", sl = "„", sr = "“" }
}
-}
defaultOptions : Options
defaultOptions =
{ githubFlavored = Just { tables = False, breaks = False }
{ full = False
, html = False
, breaks = False
, langPrefix = Just "hljs "
, defaultHighlighting = Nothing
, sanitize = False
, smartypants = False
, linkify = False
, typographer = False
, quotes = Nothing
}


{-| Maybe you want to parse user input into markdown. To stop them from adding
`<script>` tags, you can use modified parsing options.
{-| Maybe you want to enable HTML input in your markdown. To accomplish this,
you can use modified parsing options.
options : Options
options =
{ defaultOptions | sanitize = True }
{ defaultOptions | html = True }
toMarkdown : String -> Html
toMarkdown userInput =
Expand Down
Loading

0 comments on commit d9c8693

Please sign in to comment.