Skip to content

Commit 900c85d

Browse files
committed
Add reference ids to titles inserted as headers
1 parent d093a9f commit 900c85d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

IncludeFilter.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ example, if the header is incremented by 1, the title is inserted as a level 1 h
6969

7070
import Control.Monad
7171
import Data.List
72+
import qualified Data.Char as C
7273
import qualified Data.Map as Map
7374
import Control.Error (readMay, fromMaybe)
7475
import System.Directory
7576

7677
import Text.Pandoc
7778
import Text.Pandoc.Error
79+
import Text.Pandoc.Shared
7880
import Text.Pandoc.JSON
7981
import Text.Pandoc.Walk
8082

@@ -85,8 +87,13 @@ stripPandoc changeInHeaderLevel (Right (Pandoc meta blocks)) = maybe id (:) (tit
8587
modBlocks = modifyHeaderLevelBlockWith changeInHeaderLevel <$> blocks
8688
title (Meta (Map.lookup "title" -> Just (MetaInlines inls))) = do
8789
guard $ changeInHeaderLevel > 0
88-
Just $ Header changeInHeaderLevel ("",["section-title"],[]) inls
90+
Just $ Header changeInHeaderLevel (titleRef inls,["section-title"],[]) inls
8991
title _ = Nothing
92+
titleRef = stringify . fmap (lowerCase . dashFromSpace)
93+
dashFromSpace Space = Str "-"
94+
dashFromSpace x = x
95+
lowerCase (Str x) = Str (fmap C.toLower x)
96+
lowerCase x = x
9097

9198
modifyHeaderLevelBlockWith :: Int -> Block -> Block
9299
modifyHeaderLevelBlockWith n (Header int att inls) = Header (int + n) att inls

0 commit comments

Comments
 (0)