on master help sign in
Merge branch 'markdown'
1eb7d2dEvan Czaplicki
Elm.cabal+4−2
@@ -106,15 +106,16 @@ Library
106 blaze-html >= 0.5 && < 0.8,
106 blaze-html >= 0.5 && < 0.8,
107 blaze-markup,
107 blaze-markup,
108 bytestring,
108 bytestring,
109+ cheapskate,
109 cmdargs,
110 cmdargs,
110 containers >= 0.3,
111 containers >= 0.3,
111 directory,
112 directory,
112 filepath,
113 filepath,
114+ highlighting-kate,
113 indents,
115 indents,
114 language-ecmascript >=0.15 && < 1.0,
116 language-ecmascript >=0.15 && < 1.0,
115 language-glsl >= 0.0.2,
117 language-glsl >= 0.0.2,
116 mtl >= 2,
118 mtl >= 2,
117− pandoc >= 1.10,
118 parsec >= 3.1.1,
119 parsec >= 3.1.1,
119 pretty,
120 pretty,
120 scientific,
121 scientific,
@@ -197,15 +198,16 @@ Executable elm
197 blaze-html >= 0.5 && < 0.8,
198 blaze-html >= 0.5 && < 0.8,
198 blaze-markup,
199 blaze-markup,
199 bytestring,
200 bytestring,
201+ cheapskate,
200 cmdargs,
202 cmdargs,
201 containers >= 0.3,
203 containers >= 0.3,
202 directory,
204 directory,
203 filepath,
205 filepath,
206+ highlighting-kate,
204 indents,
207 indents,
205 language-ecmascript >=0.15 && < 1.0,
208 language-ecmascript >=0.15 && < 1.0,
206 language-glsl >= 0.0.2,
209 language-glsl >= 0.0.2,
207 mtl >= 2,
210 mtl >= 2,
208− pandoc >= 1.10,
209 parsec >= 3.1.1,
211 parsec >= 3.1.1,
210 scientific,
212 scientific,
211 pretty,
213 pretty,
changelog.md+1
@@ -10,6 +10,7 @@
10 * Add Maybe.map
10 * Add Maybe.map
11 * Add --bundle-runtime flag which creates stand-alone Elm programs
11 * Add --bundle-runtime flag which creates stand-alone Elm programs
12 * Error on ambiguious use of imported variables
12 * Error on ambiguious use of imported variables
13+ * Replace dependency on Pandoc with cheapskate+kate
13 * Better architecture for compiler. Uses types to make compilation pipeline
14 * Better architecture for compiler. Uses types to make compilation pipeline
14 safer, setting things up for giving programmatic access to the AST to
15 safer, setting things up for giving programmatic access to the AST to
15 improve editor and IDE support.
16 improve editor and IDE support.
compiler/Generate/Markdown.hs+34−31
@@ -1,39 +1,42 @@
1module Generate.Markdown where
1module Generate.Markdown where
2
2
3−import Text.Pandoc
3+import qualified Cheapskate as CS
4+import qualified Cheapskate.Html as CS
4import qualified Data.Set as Set
5import 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
5
14
6toHtml :: String -> String
15toHtml :: 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
8
22
9−readOptions =
23+options :: CS.Options
10− def { readerExtensions = elmExtensions
24+options =
11− , readerApplyMacros = False
25+ CS.Options
26+ { CS.sanitize = False
27+ , CS.allowRawHtml = True
28+ , CS.preserveHardBreaks = False
29+ , CS.debug = False
12− }
30+ }
13
31
14−writeOptions =
32+highlightCode :: CS.Block -> CS.Block
15− def { writerExtensions = elmExtensions
33+highlightCode block =
16− , writerHighlight = True
34+ case block of
17− }
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
18
41
19−elmExtensions :: Set.Set Extension
42+ _ -> block
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− ]