on master help sign in
Stop using Pandoc, start using cheapskate+kate
commitabe81ea7f1805db802ac73a4c12b382213e8d637 authorEvan Czaplicki <info@elm-lang.org> dateMon 4 Aug 2014, 17:01 (12 years ago) parent55ee0a7
3 files changed+39−33
Elm.cabal+4−2 changelog.md+1 compiler/Generate/Markdown.hs+34−31
Elm.cabal+4−2
@@ -106,15 +106,16 @@ Library
106106 blaze-html >= 0.5 && < 0.8,
107107 blaze-markup,
108108 bytestring,
109+ cheapskate,
109110 cmdargs,
110111 containers >= 0.3,
111112 directory,
112113 filepath,
114+ highlighting-kate,
113115 indents,
114116 language-ecmascript >=0.15 && < 1.0,
115117 language-glsl >= 0.0.2,
116118 mtl >= 2,
117− pandoc >= 1.10,
118119 parsec >= 3.1.1,
119120 pretty,
120121 scientific,
@@ -197,15 +198,16 @@ Executable elm
197198 blaze-html >= 0.5 && < 0.8,
198199 blaze-markup,
199200 bytestring,
201+ cheapskate,
200202 cmdargs,
201203 containers >= 0.3,
202204 directory,
203205 filepath,
206+ highlighting-kate,
204207 indents,
205208 language-ecmascript >=0.15 && < 1.0,
206209 language-glsl >= 0.0.2,
207210 mtl >= 2,
208− pandoc >= 1.10,
209211 parsec >= 3.1.1,
210212 scientific,
211213 pretty,
changelog.md+1
@@ -10,6 +10,7 @@
1010 * Add Maybe.map
1111 * Add --bundle-runtime flag which creates stand-alone Elm programs
1212 * Error on ambiguious use of imported variables
13+ * Replace dependency on Pandoc with cheapskate+kate
1314 * Better architecture for compiler. Uses types to make compilation pipeline
1415 safer, setting things up for giving programmatic access to the AST to
1516 improve editor and IDE support.
compiler/Generate/Markdown.hs+34−31
@@ -1,39 +1,42 @@
11module Generate.Markdown where
22
3−import Text.Pandoc
3+import qualified Cheapskate as CS
4+import qualified Cheapskate.Html as CS
45import qualified Data.Set as Set
6+import qualified Data.Text as Text
7+import qualified Text.Blaze.Html.Renderer.String as Blaze
8+import qualified Text.Highlighting.Kate as Kate
9+
10+import Debug.Trace
11+
12+(|>) :: a -> (a -> b) -> b
13+x |> f = f x
514
615toHtml :: String -> String
7−toHtml = writeHtmlString writeOptions . readMarkdown readOptions
16+toHtml rawMarkdown =
17+ Text.pack rawMarkdown
18+ |> CS.markdown options
19+ |> CS.walk highlightCode
20+ |> CS.renderDoc
21+ |> Blaze.renderHtml
822
9−readOptions =
10− def { readerExtensions = elmExtensions
11− , readerApplyMacros = False
12− }
23+options :: CS.Options
24+options =
25+ CS.Options
26+ { CS.sanitize = False
27+ , CS.allowRawHtml = True
28+ , CS.preserveHardBreaks = False
29+ , CS.debug = False
30+ }
1331
14−writeOptions =
15− def { writerExtensions = elmExtensions
16− , writerHighlight = True
17− }
32+highlightCode :: CS.Block -> CS.Block
33+highlightCode block =
34+ case block of
35+ CS.CodeBlock (CS.CodeAttr lang _info) src ->
36+ Kate.highlightAs (Text.unpack lang) (Text.unpack src)
37+ |> Kate.formatHtmlBlock Kate.defaultFormatOpts
38+ |> Blaze.renderHtml
39+ |> Text.pack
40+ |> CS.HtmlBlock
1841
19−elmExtensions :: Set.Set Extension
20−elmExtensions = Set.fromList
21− [ Ext_raw_html
22− , Ext_fenced_code_blocks
23− , Ext_fenced_code_attributes
24− , Ext_backtick_code_blocks
25− , Ext_inline_code_attributes
26− , Ext_markdown_in_html_blocks
27− , Ext_escaped_line_breaks
28− , Ext_fancy_lists
29− , Ext_startnum
30− , Ext_definition_lists
31− , Ext_example_lists
32− , Ext_all_symbols_escapable
33− , Ext_intraword_underscores
34− , Ext_blank_before_blockquote
35− , Ext_blank_before_header
36− , Ext_auto_identifiers
37− , Ext_header_attributes
38− , Ext_implicit_header_references
39− ]
42+ _ -> block