Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. ~~~~ {#mycode .haskell .numberLines startFrom="100"}
  2. qsort [] = []
  3. qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
  4. qsort (filter (>= x) xs)
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6.  
  7. # My header
  8.  
  9. ~~~ {.text}
  10. This is regular text. This is regular text.
  11. ~~~
  12.  
  13. ~~~ {.quote}
  14. > This is the first level of quoting.
  15. >
  16. > > This is nested blockquote.
  17. >
  18. > Back to the first level.
  19. ~~~
  20.  
  21. ~~~ {data-id=test-123}
  22. + Red
  23. + Green
  24. + Blue
  25. ~~~
  26.  
  27. <h1 id="my-header">My header</h1>
  28. <p class="text">This is regular text. This is regular text.</p>
  29. <blockquote class="quote">
  30. <p>This is the first level of quoting.</p>
  31. <blockquote>
  32. <p>This is nested blockquote.</p>
  33. </blockquote>
  34. <p>Back to the first level.</p>
  35. </blockquote>
  36. <ul data-id="test-123">
  37. <li>Red</li>
  38. <li>Green</li>
  39. <li>Blue</li>
  40. </ul>
  41.  
  42. # My header
  43.  
  44. This is regular text. This is regular text.
  45. {: .text}
  46.  
  47. > This is the first level of quoting.
  48. >
  49. > > This is nested blockquote.
  50. >
  51. > Back to the first level.
  52. {: .quote}
  53.  
  54. + Red
  55. + Green
  56. + Blue
  57. {: data-id="test-123"}
  58.  
  59. <h1 id="my-header">My header</h1>
  60.  
  61. <p class="text">This is regular text. This is regular text.</p>
  62.  
  63. <blockquote class="quote">
  64. <p>This is the first level of quoting.</p>
  65.  
  66. <blockquote>
  67. <p>This is nested blockquote.</p>
  68. </blockquote>
  69.  
  70. <p>Back to the first level.</p>
  71. </blockquote>
  72.  
  73. <ul data-id="test-123">
  74. <li>Red</li>
  75. <li>Green</li>
  76. <li>Blue</li>
  77. </ul>
  78.  
  79. # My header
  80.  
  81. ~~~ {.as-markdown}
  82. This is regular text. This is regular text.
  83. ~~~
  84.  
  85. ~~~ {.as-markdown}
  86. > This is the first level of quoting.
  87. >
  88. > > This is nested blockquote.
  89. >
  90. > Back to the first level.
  91. ~~~
  92.  
  93. ~~~ {.as-markdown data-id=test-123}
  94. + Red
  95. + Green
  96. + Blue
  97. ~~~
  98.  
  99. ~~~ haskell
  100. main :: IO ()
  101. ~~~
  102.  
  103. #!/usr/bin/env runhaskell
  104. import Text.Pandoc.Definition (Pandoc(..), Block(..), Format(..))
  105. import Text.Pandoc.Error (handleError)
  106. import Text.Pandoc.JSON (toJSONFilter)
  107. import Text.Pandoc.Options (def)
  108. import Text.Pandoc.Readers.Markdown (readMarkdown)
  109.  
  110. asMarkdown :: String -> [Block]
  111. asMarkdown contents =
  112. case handleError $ readMarkdown def contents of
  113. Pandoc _ blocks -> blocks
  114.  
  115. -- | Unwrap each CodeBlock with the "as-markdown" class, interpreting
  116. -- its contents as Markdown.
  117. markdownCodeBlock :: Maybe Format -> Block -> IO [Block]
  118. markdownCodeBlock _ cb@(CodeBlock (_id, classes, _namevals) contents) =
  119. if "as-markdown" `elem` classes then
  120. return $ asMarkdown contents
  121. else
  122. return [cb]
  123. markdownCodeBlock _ x = return [x]
  124.  
  125. main :: IO ()
  126. main = toJSONFilter markdownCodeBlock
  127.  
  128. <h1 id="my-header">My header</h1>
  129. <p>This is regular text. This is regular text.</p>
  130. <blockquote>
  131. <p>This is the first level of quoting.</p>
  132. <blockquote>
  133. <p>This is nested blockquote.</p>
  134. </blockquote>
  135. <p>Back to the first level.</p>
  136. </blockquote>
  137. <ul>
  138. <li>Red</li>
  139. <li>Green</li>
  140. <li>Blue</li>
  141. </ul>
  142. <div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">main ::</span> <span class="dt">IO</span> ()</code></pre></div>
  143.  
  144. #!/usr/bin/env runhaskell
  145. import Text.Pandoc.Builder
  146. import Text.Pandoc.JSON
  147.  
  148. webFormats :: [String]
  149. webFormats =
  150. [ "html"
  151. , "html5"
  152. ]
  153.  
  154. script :: String -> Block
  155. script src = Para $ toList $ rawInline "html" ("<script type='application/javascript'>" <> src <> "</script>")
  156.  
  157. injectScript :: Maybe Format -> Block -> IO Block
  158. injectScript (Just (Format format)) cb@(CodeBlock (_id, classes, _namevals) contents) =
  159. if "web-script" `elem` classes then
  160. if format `elem` webFormats then
  161. return $ script contents
  162. else
  163. return Null
  164. else
  165. return cb
  166. injectScript _ x = return x
  167.  
  168. main :: IO ()
  169. main = toJSONFilter injectScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement