markdown 0.1.15 → 0.1.16
raw patch · 4 files changed
+34/−7 lines, 4 files
Files
- Text/Markdown.hs +20/−6
- Text/Markdown/Types.hs +2/−0
- markdown.cabal +1/−1
- test/main.hs +11/−0
Text/Markdown.hs view
@@ -15,6 +15,7 @@ , msBlankBeforeBlockquote , msBlockFilter , msAddHeadingId+ , setNoFollowExternal -- * Newtype , Markdown (..) -- * Fenced handlers@@ -33,7 +34,9 @@ import Data.Char (isAlphaNum) import Data.Default (Default (..)) import Data.List (intercalate, isInfixOf)+import Data.Maybe (isJust) import Data.Text (Text)+import qualified Data.Text as T import qualified Data.Text.Lazy as TL import Text.Blaze (toValue) import Text.Blaze.Html (ToMarkup (..), Html)@@ -170,12 +173,13 @@ go (InlineItalic is) = H.i $ gos is go (InlineBold is) = H.b $ gos is go (InlineCode t) = H.code $ toMarkup t- go (InlineLink url Nothing content)- | msLinkNewTab ms = H.a H.! HA.href (H.toValue url) H.! HA.target "_blank" $ gos content- | otherwise = H.a H.! HA.href (H.toValue url) $ gos content- go (InlineLink url (Just title) content)- | msLinkNewTab ms = H.a H.! HA.href (H.toValue url) H.! HA.title (H.toValue title) H.! HA.target "_blank" $ gos content- | otherwise = H.a H.! HA.href (H.toValue url) H.! HA.title (H.toValue title) $ gos content+ go (InlineLink url mtitle content) =+ H.a+ H.! HA.href (H.toValue url)+ H.!? (msLinkNewTab ms, HA.target "_blank")+ H.!? (msNoFollowExternal ms && isExternalLink url, HA.rel "nofollow")+ H.!? (isJust mtitle, HA.title $ maybe (error "impossible") H.toValue mtitle)+ $ gos content go (InlineImage url Nothing content) = H.img H.! HA.src (H.toValue url) H.! HA.alt (H.toValue content) go (InlineImage url (Just title) content) = H.img H.! HA.src (H.toValue url) H.! HA.alt (H.toValue content) H.! HA.title (H.toValue title) go (InlineHtml t) = escape t@@ -187,3 +191,13 @@ (<>) = mappend in H.a H.! HA.href (H.toValue $ "#ref-" <> ishown) H.! HA.id (H.toValue $ "footnote-" <> ishown) $ H.toHtml $ "[" <> ishown <> "]"++-- | For external links, add the rel="nofollow" attribute+--+-- @since 0.1.16+setNoFollowExternal :: MarkdownSettings -> MarkdownSettings+setNoFollowExternal ms = ms { msNoFollowExternal = True }++-- | Is the given URL an external link?+isExternalLink :: Text -> Bool+isExternalLink = T.isInfixOf "//"
Text/Markdown/Types.hs view
@@ -101,6 +101,7 @@ -- -- Since 0.1.13 + , msNoFollowExternal :: Bool } -- | See 'msFencedHandlers.@@ -125,6 +126,7 @@ , msBlankBeforeBlockquote = True , msBlockFilter = id , msAddHeadingId = False+ , msNoFollowExternal = False } instance Default MarkdownSettings where
markdown.cabal view
@@ -1,5 +1,5 @@ Name: markdown-Version: 0.1.15+Version: 0.1.16 Synopsis: Convert Markdown to HTML, with XSS protection Description: This library leverages existing high-performance libraries (attoparsec, blaze-html, text, and conduit), and should integrate well with existing codebases. Homepage: https://github.com/snoyberg/markdown
test/main.hs view
@@ -252,6 +252,17 @@ it "comments without spaces #22" $ check "<!--<>-->" "<!--<>-->" + describe "no follow" $ do+ it "external 1" $ checkSet (setNoFollowExternal def)+ "<p><a href=\"http://example.com\" rel=\"nofollow\">example</a></p>"+ "[example](http://example.com)"+ it "external 2" $ checkSet (setNoFollowExternal def)+ "<p><a href=\"//example.com\" rel=\"nofollow\">example</a></p>"+ "[example](//example.com)"+ it "internal" $ checkSet (setNoFollowExternal def)+ "<p><a href=\"/foo\">example</a></p>"+ "[example](/foo)"+ getExamples :: IO [Spec] getExamples = do files <- getDirectoryContents dir