Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~~~~ {#mycode .haskell .numberLines startFrom="100"}
- qsort [] = []
- qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
- qsort (filter (>= x) xs)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # My header
- ~~~ {.text}
- This is regular text. This is regular text.
- ~~~
- ~~~ {.quote}
- > This is the first level of quoting.
- >
- > > This is nested blockquote.
- >
- > Back to the first level.
- ~~~
- ~~~ {data-id=test-123}
- + Red
- + Green
- + Blue
- ~~~
- <h1 id="my-header">My header</h1>
- <p class="text">This is regular text. This is regular text.</p>
- <blockquote class="quote">
- <p>This is the first level of quoting.</p>
- <blockquote>
- <p>This is nested blockquote.</p>
- </blockquote>
- <p>Back to the first level.</p>
- </blockquote>
- <ul data-id="test-123">
- <li>Red</li>
- <li>Green</li>
- <li>Blue</li>
- </ul>
- # My header
- This is regular text. This is regular text.
- {: .text}
- > This is the first level of quoting.
- >
- > > This is nested blockquote.
- >
- > Back to the first level.
- {: .quote}
- + Red
- + Green
- + Blue
- {: data-id="test-123"}
- <h1 id="my-header">My header</h1>
- <p class="text">This is regular text. This is regular text.</p>
- <blockquote class="quote">
- <p>This is the first level of quoting.</p>
- <blockquote>
- <p>This is nested blockquote.</p>
- </blockquote>
- <p>Back to the first level.</p>
- </blockquote>
- <ul data-id="test-123">
- <li>Red</li>
- <li>Green</li>
- <li>Blue</li>
- </ul>
- # My header
- ~~~ {.as-markdown}
- This is regular text. This is regular text.
- ~~~
- ~~~ {.as-markdown}
- > This is the first level of quoting.
- >
- > > This is nested blockquote.
- >
- > Back to the first level.
- ~~~
- ~~~ {.as-markdown data-id=test-123}
- + Red
- + Green
- + Blue
- ~~~
- ~~~ haskell
- main :: IO ()
- ~~~
- #!/usr/bin/env runhaskell
- import Text.Pandoc.Definition (Pandoc(..), Block(..), Format(..))
- import Text.Pandoc.Error (handleError)
- import Text.Pandoc.JSON (toJSONFilter)
- import Text.Pandoc.Options (def)
- import Text.Pandoc.Readers.Markdown (readMarkdown)
- asMarkdown :: String -> [Block]
- asMarkdown contents =
- case handleError $ readMarkdown def contents of
- Pandoc _ blocks -> blocks
- -- | Unwrap each CodeBlock with the "as-markdown" class, interpreting
- -- its contents as Markdown.
- markdownCodeBlock :: Maybe Format -> Block -> IO [Block]
- markdownCodeBlock _ cb@(CodeBlock (_id, classes, _namevals) contents) =
- if "as-markdown" `elem` classes then
- return $ asMarkdown contents
- else
- return [cb]
- markdownCodeBlock _ x = return [x]
- main :: IO ()
- main = toJSONFilter markdownCodeBlock
- <h1 id="my-header">My header</h1>
- <p>This is regular text. This is regular text.</p>
- <blockquote>
- <p>This is the first level of quoting.</p>
- <blockquote>
- <p>This is nested blockquote.</p>
- </blockquote>
- <p>Back to the first level.</p>
- </blockquote>
- <ul>
- <li>Red</li>
- <li>Green</li>
- <li>Blue</li>
- </ul>
- <div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">main ::</span> <span class="dt">IO</span> ()</code></pre></div>
- #!/usr/bin/env runhaskell
- import Text.Pandoc.Builder
- import Text.Pandoc.JSON
- webFormats :: [String]
- webFormats =
- [ "html"
- , "html5"
- ]
- script :: String -> Block
- script src = Para $ toList $ rawInline "html" ("<script type='application/javascript'>" <> src <> "</script>")
- injectScript :: Maybe Format -> Block -> IO Block
- injectScript (Just (Format format)) cb@(CodeBlock (_id, classes, _namevals) contents) =
- if "web-script" `elem` classes then
- if format `elem` webFormats then
- return $ script contents
- else
- return Null
- else
- return cb
- injectScript _ x = return x
- main :: IO ()
- main = toJSONFilter injectScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement