diff options
author | Logan McGrath <81108848+ThisFieldWasGreen@users.noreply.github.com> | 2021-06-06 10:50:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 20:50:44 +0300 |
commit | 6d9bc845d5233c67e5eba3f54dcc7772ca1d79e2 (patch) | |
tree | 5f1529b2f002b18e27335bd08d42e84d09a0009e /lib/Hakyll | |
parent | 591fbe693d87b84c73b1839acdd424cbc12da3b3 (diff) | |
download | hakyll-6d9bc845d5233c67e5eba3f54dcc7772ca1d79e2.tar.gz |
Allow demotion of headers by a given amount (#855)
Diffstat (limited to 'lib/Hakyll')
-rw-r--r-- | lib/Hakyll/Web/Html.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Hakyll/Web/Html.hs b/lib/Hakyll/Web/Html.hs index 8cbfaa3..7aa3804 100644 --- a/lib/Hakyll/Web/Html.hs +++ b/lib/Hakyll/Web/Html.hs @@ -7,6 +7,7 @@ module Hakyll.Web.Html -- * Headers , demoteHeaders + , demoteHeadersBy -- * Url manipulation , getUrls @@ -50,13 +51,20 @@ withTagList f = renderTags' . f . parseTags' -------------------------------------------------------------------------------- -- | Map every @h1@ to an @h2@, @h2@ to @h3@, etc. demoteHeaders :: String -> String -demoteHeaders = withTags $ \tag -> case tag of +demoteHeaders = demoteHeadersBy 1 + +-------------------------------------------------------------------------------- +-- | Maps any @hN@ to an @hN+amount@ for any @amount > 0 && 1 <= N+amount <= 6@. +demoteHeadersBy :: Int -> String -> String +demoteHeadersBy amount + | amount < 1 = id + | otherwise = withTags $ \tag -> case tag of TS.TagOpen t a -> TS.TagOpen (demote t) a TS.TagClose t -> TS.TagClose (demote t) t -> t where demote t@['h', n] - | isDigit n = ['h', intToDigit (min 6 $ digitToInt n + 1)] + | isDigit n = ['h', intToDigit (min 6 $ digitToInt n + amount)] | otherwise = t demote t = t |