Skip to content

Commit 99f5cd9

Browse files
committed
Split extensions into separate commonmark-extensions package.
1 parent 9a1d103 commit 99f5cd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+705
-104
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ haddock:
2323
stack haddock
2424

2525
prof:
26-
stack install --profile --ghc-options="-fno-prof-auto"
27-
# commonmark +RTS -pj -RTS benchmark.md >/dev/null
26+
cabal build --enable-profiling --verbose --ghc-options="-fno-prof-auto" commonmark-cli
27+
# bin/commonmark +RTS -pj -RTS benchmark.md >/dev/null
2828
# cat commonmark.prof | ghc-prof-aeson-flamegraph | flamegraph.pl > prof.svg
2929
# open -a Safari prof.svg
3030

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This repository contains three packages:
1212
- [`commonmark-pandoc`](commonmark-pandoc/):
1313
type instances for parsing commonmark as a Pandoc AST.
1414

15+
- [`commonmark-extensions`](commonmark-extensions/):
16+
a set of useful extensions to core commonmark syntax.
17+
1518
- [`commonmark-cli`](commonmark-cli/): a
1619
command-line program that uses this library to convert
1720
and syntax-highlight commonmark documents.

commonmark-cli/commonmark-cli.cabal

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage: https://github.com/jgm/commonmark-hs
77
bug-reports: https://github.com/jgm/commonmark-hs/issues
88
author: John MacFarlane
99
maintainer: [email protected]
10-
copyright: 2018 John MacFarlane
10+
copyright: 2018-2020 John MacFarlane
1111
license: BSD3
1212
license-file: LICENSE
1313
build-type: Simple
@@ -26,9 +26,9 @@ executable commonmark
2626
hs-source-dirs: src
2727
ghc-options: -threaded -rtsopts
2828
build-depends: base >=4.7 && <5
29-
, commonmark
30-
, commonmark-pandoc
31-
, lucid
29+
, commonmark >= 0.1 && < 0.2
30+
, commonmark-extensions >= 0.1 && < 0.2
31+
, commonmark-pandoc >= 0.1 && < 0.2
3232
, pandoc-types
3333
, aeson
3434
, bytestring

commonmark-cli/src/convert.hs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Main where
55

66
import Commonmark
77
import Commonmark.Html
8+
import Commonmark.Extensions
89
import Commonmark.Pandoc
910
import Data.Aeson (encode)
1011
import qualified Data.ByteString.Lazy as BL

commonmark-extensions/LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Author name here (c) 2018
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Author name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

commonmark-extensions/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# commonmark-extensions
2+
3+
This package provides some syntax extensions for the
4+
commonmark package:
5+
6+
- [`pipe_tables`] (pipe tables)
7+
- [`smart`] (smart quotes, dashes, and ellipses)
8+
- [`strikethrough`] (strikethrough)
9+
- [`superscript`] (superscript)
10+
- [`subscript`] (subscript)
11+
- [`math`] (LaTeX math)
12+
- [`emoji`] (emoji)
13+
- [`autolinks`] (autolink bare URLs and email addresses)
14+
- [`footnotes`] (footnotes)
15+
- [`definition_lists`] (definition lists)
16+
- [`fancy_lists`] (fancy ordered list markers (parentheses, alpha, roman)
17+
- [`attributes`] (attributes for all inline and block elements)
18+
- [`raw_attribute`] (special raw block and inline elements in any format)
19+
- [`bracketed_spans`] (spans of inline elements with attributes)
20+
- [`fenced_divs`] (groups of block elements with attributes)
21+
- [`auto_identifiers`] (automatic generation of identifiers for headings)
22+
- [`implicit_heading_references`] (headings implicitly define link references)
23+
24+
[`pipe_tables`]: test/pipe_tables.md
25+
[`smart`]: test/smart.md
26+
[`strikethrough`]: test/strikethrough.md
27+
[`superscript`]: test/superscript.md
28+
[`subscript`]: test/subscript.md
29+
[`math`]: test/math.md
30+
[`emoji`]: test/emoji.md
31+
[`autolinks`]: test/autolinks.md
32+
[`footnotes`]: test/footnotes.md
33+
[`definition_lists`]: test/definition_lists.md
34+
[`fancy_lists`]: test/fancy_lists.md
35+
[`attributes`]: test/attributes.md
36+
[`raw_attribute`]: test/raw_attribute.md
37+
[`bracketed_spans`]: test/bracketed_spans.md
38+
[`fenced_divs`]: test/fenced_divs.md
39+
[`auto_identifiers`]: test/auto_identifiers.md
40+
[`implicit_heading_references`]: test/implicit_heading_references.md
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
4+
import Criterion.Main
5+
import Data.Text (Text)
6+
import Data.Functor.Identity -- base >= 4.8
7+
import Commonmark
8+
import Commonmark.Extensions
9+
import Commonmark.Html
10+
import qualified Data.Text as T
11+
import qualified Data.Text.IO as TIO
12+
#if !MIN_VERSION_base(4,11,0)
13+
import Data.Monoid
14+
#endif
15+
16+
main :: IO ()
17+
main = do
18+
sample <- T.replicate 10 <$> TIO.readFile "benchmark/sample.md"
19+
defaultMainWith defaultConfig
20+
[ benchCommonmark (smartPunctuationSpec <> defaultSyntaxSpec)
21+
("commonmark +smart", sample)
22+
, benchCommonmark (autolinkSpec <> defaultSyntaxSpec)
23+
("commonmark +autolink", sample)
24+
, benchCommonmark (attributesSpec <> defaultSyntaxSpec)
25+
("commonmark +attributes", sample)
26+
, benchCommonmark (defaultSyntaxSpec <> pipeTableSpec)
27+
("commonmark +pipe_table", sample)
28+
]
29+
30+
benchCommonmark :: SyntaxSpec Identity (Html ()) (Html ())
31+
-> (String, Text)
32+
-> Benchmark
33+
benchCommonmark spec (name, contents) =
34+
bench name $
35+
nf (either (error . show) renderHtml
36+
. runIdentity . parseCommonmarkWith spec . tokenize name)
37+
contents
38+

0 commit comments

Comments
 (0)