pandoc-emphasize-code 0.2.0 → 0.2.1
raw patch · 4 files changed
+68/−39 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Text.Pandoc.Filter.EmphasizeCode.Html: data Html
+ Text.Pandoc.Filter.EmphasizeCode.Html: Em :: EmphasisTag
+ Text.Pandoc.Filter.EmphasizeCode.Html: Mark :: EmphasisTag
+ Text.Pandoc.Filter.EmphasizeCode.Html: data EmphasisTag
+ Text.Pandoc.Filter.EmphasizeCode.Html: newtype Html
- Text.Pandoc.Filter.EmphasizeCode.Html: Html :: Html
+ Text.Pandoc.Filter.EmphasizeCode.Html: Html :: EmphasisTag -> Html
Files
- pandoc-emphasize-code.cabal +1/−1
- src/Text/Pandoc/Filter/EmphasizeCode.hs +2/−1
- src/Text/Pandoc/Filter/EmphasizeCode/Html.hs +27/−17
- test/Text/Pandoc/Filter/EmphasizeCodeTest.hs +38/−20
pandoc-emphasize-code.cabal view
@@ -5,7 +5,7 @@ author: Oskar Wickström maintainer: Oskar Wickström homepage: https://github.com/owickstrom/pandoc-emphasize-code-version: 0.2.0+version: 0.2.1 cabal-version: >= 1.8 build-type: Simple category: Documentation
src/Text/Pandoc/Filter/EmphasizeCode.hs view
@@ -22,7 +22,8 @@ toRenderer :: Pandoc.Format -> Maybe (Pandoc.Attr -> EmphasizedLines -> Pandoc.Block) toRenderer f- | f `elem` ["html", "html5", "markdown_github"] = Just (renderEmphasized Html)+ | f `elem` ["html", "markdown_github"] = Just (renderEmphasized (Html Em))+ | f `elem` ["html5", "revealjs"] = Just (renderEmphasized (Html Mark)) | f == "latex" = Just (renderEmphasized Latex) | f == "beamer" = Just (renderEmphasized Latex) | otherwise = Nothing
src/Text/Pandoc/Filter/EmphasizeCode/Html.hs view
@@ -1,27 +1,36 @@ module Text.Pandoc.Filter.EmphasizeCode.Html- ( Html(Html)+ ( EmphasisTag (..)+ , Html(Html) ) where -import Data.List (intersperse)-import qualified Data.Text as Text-import qualified Data.Text.Lazy as TextLazy-import qualified Lucid as Html-import qualified Text.Pandoc.Definition as Pandoc+import Data.List (intersperse)+import qualified Data.Text as Text+import qualified Data.Text.Lazy as TextLazy+import qualified Lucid as Html+import qualified Text.Pandoc.Definition as Pandoc -import Text.Pandoc.Filter.EmphasizeCode.Chunking-import Text.Pandoc.Filter.EmphasizeCode.Renderable+import Text.Pandoc.Filter.EmphasizeCode.Chunking+import Text.Pandoc.Filter.EmphasizeCode.Renderable -data Html =- Html+data EmphasisTag+ = Em+ | Mark -emphasizeChunkHtml :: LineChunk -> Html.Html ()-emphasizeChunkHtml chunk =+newtype Html =+ Html EmphasisTag++emphasisElement :: EmphasisTag -> Html.Html () -> Html.Html ()+emphasisElement Em = Html.em_+emphasisElement Mark = Html.mark_++emphasizeChunkHtml :: EmphasisTag -> LineChunk -> Html.Html ()+emphasizeChunkHtml tag chunk = case chunk of- Literal t -> Html.toHtml t- Emphasized t -> Html.em_ (Html.toHtml t)+ Literal t -> Html.toHtml t+ Emphasized t -> emphasisElement tag (Html.toHtml t) instance Renderable Html where- renderEmphasized _ (_, classes, _) lines' =+ renderEmphasized (Html tag) (_, classes, _) lines' = Pandoc.RawBlock (Pandoc.Format "html") (TextLazy.unpack (Html.renderText emphasized))@@ -34,5 +43,6 @@ Html.pre_ classAttrs $ Html.code_ $ mconcat- (intersperse (Html.br_ []) (map (foldMap emphasizeChunkHtml) lines'))-+ (intersperse+ (Html.br_ [])+ (map (foldMap (emphasizeChunkHtml tag)) lines'))
test/Text/Pandoc/Filter/EmphasizeCodeTest.hs view
@@ -8,9 +8,28 @@ import qualified Text.Pandoc.Filter.EmphasizeCode as Filter import Text.Pandoc.JSON -(@@?=) :: (Eq a, Show a) => IO a -> a -> IO ()-(@@?=) a b = a >>= (`shouldBe` b)+singleRangeHtmlMark :: Block+singleRangeHtmlMark =+ RawBlock+ "html"+ (mconcat+ [ "<pre class=\"my-lang\"><code>hello world<br>"+ , "hej <mark>världen</mark><br>"+ , "<mark>hallo</mark> welt<br>"+ , "hei verden</code></pre>"+ ]) +singleRangeHtmlEm :: Block+singleRangeHtmlEm =+ RawBlock+ "html"+ (mconcat+ [ "<pre class=\"my-lang\"><code>hello world<br>"+ , "hej <em>världen</em><br>"+ , "<em>hallo</em> welt<br>"+ , "hei verden</code></pre>"+ ])+ emphasizeCode :: Format -> String -> IO Block emphasizeCode format ranges = Filter.emphasizeCode@@ -21,37 +40,35 @@ spec_emphasizeCode = do it "emphasizes HTML and a single range" $- emphasizeCode "html5" "2:5-3:5" @@?=- RawBlock- "html"- (mconcat- [ "<pre class=\"my-lang\"><code>hello world<br>"- , "hej <em>världen</em><br>"- , "<em>hallo</em> welt<br>"- , "hei verden</code></pre>"- ])+ emphasizeCode "html5" "2:5-3:5" `shouldReturn` singleRangeHtmlMark it "emphasizes HTML and a single range over multiple lines" $- emphasizeCode "html5" "2:5-4:3" @@?=+ emphasizeCode "html5" "2:5-4:3" `shouldReturn` RawBlock "html" (mconcat [ "<pre class=\"my-lang\"><code>hello world<br>"- , "hej <em>världen</em><br>"- , "<em>hallo welt</em><br>"- , "<em>hei</em> verden</code></pre>"+ , "hej <mark>världen</mark><br>"+ , "<mark>hallo welt</mark><br>"+ , "<mark>hei</mark> verden</code></pre>" ]) it "emphasizes HTML and multiple ranges" $- emphasizeCode "html5" "1:1-1:5,2:5-3:5" @@?=+ emphasizeCode "html5" "1:1-1:5,2:5-3:5" `shouldReturn` RawBlock "html" (mconcat- [ "<pre class=\"my-lang\"><code><em>hello</em> world<br>"- , "hej <em>världen</em><br>"- , "<em>hallo</em> welt<br>"+ [ "<pre class=\"my-lang\"><code><mark>hello</mark> world<br>"+ , "hej <mark>världen</mark><br>"+ , "<mark>hallo</mark> welt<br>" , "hei verden</code></pre>" ])+ it "emphasizes RevealJS HTML using <mark>" $+ emphasizeCode "revealjs" "2:5-3:5" `shouldReturn` singleRangeHtmlMark+ it "emphasizes HTML4 using <em>" $+ emphasizeCode "html" "2:5-3:5" `shouldReturn` singleRangeHtmlEm+ it "emphasizes markdown_github using <em>" $+ emphasizeCode "markdown_github" "2:5-3:5" `shouldReturn` singleRangeHtmlEm it "emphasizes latex and multiple ranges" $- emphasizeCode "latex" "1:1-1:5,2:5-3:5" @@?=+ emphasizeCode "latex" "1:1-1:5,2:5-3:5" `shouldReturn` RawBlock "latex" (mconcat@@ -62,4 +79,5 @@ , "hei verden\n" , "\\end{lstlisting}\n" ])+ {-# ANN module ("HLint: ignore Use camelCase" :: String) #-}