@@ -35,7 +35,7 @@ import Text.Pandoc.Shared
3535import Text.Pandoc.Readers.TeXMath
3636import Text.Regex ( mkRegex, matchRegex )
3737import Numeric ( showHex )
38−import Data.Char ( ord, toLower )
38+import Data.Char ( ord, toLower, isAlpha )
3939import Data.List ( isPrefixOf, intersperse )
4040import qualified Data.Set as S
4141import Control.Monad.State
@@ -215,18 +215,20 @@ addToCSS item = do
215215
216216-- | Convert Pandoc inline list to plain text identifier.
217217inlineListToIdentifier :: [Inline] -> String
218−inlineListToIdentifier [] = ""
219−inlineListToIdentifier (x:xs) =
220− xAsText ++ inlineListToIdentifier xs
218+inlineListToIdentifier = dropWhile (not . isAlpha) . inlineListToIdentifier'
219+
220+inlineListToIdentifier' [] = ""
221+inlineListToIdentifier' (x:xs) =
222+ xAsText ++ inlineListToIdentifier' xs
221223 where xAsText = case x of
222224 Str s -> filter (\c -> c == '-' || not (isPunctuation c)) $
223225 concat $ intersperse "-" $ words $ map toLower s
224− Emph lst -> inlineListToIdentifier lst
225− Strikeout lst -> inlineListToIdentifier lst
226− Superscript lst -> inlineListToIdentifier lst
227− Subscript lst -> inlineListToIdentifier lst
228− Strong lst -> inlineListToIdentifier lst
229− Quoted _ lst -> inlineListToIdentifier lst
226+ Emph lst -> inlineListToIdentifier' lst
227+ Strikeout lst -> inlineListToIdentifier' lst
228+ Superscript lst -> inlineListToIdentifier' lst
229+ Subscript lst -> inlineListToIdentifier' lst
230+ Strong lst -> inlineListToIdentifier' lst
231+ Quoted _ lst -> inlineListToIdentifier' lst
230232 Code s -> s
231233 Space -> "-"
232234 EmDash -> "-"
@@ -237,8 +239,8 @@ inlineListToIdentifier (x:xs) =
237239 Math _ -> ""
238240 TeX _ -> ""
239241 HtmlInline _ -> ""
240− Link lst _ -> inlineListToIdentifier lst
241− Image lst _ -> inlineListToIdentifier lst
242+ Link lst _ -> inlineListToIdentifier' lst
243+ Image lst _ -> inlineListToIdentifier' lst
242244 Note _ -> ""
243245
244246-- | Return unique identifiers for list of inline lists.
@@ -247,7 +249,8 @@ uniqueIdentifiers ls =
247249 let addIdentifier (nonuniqueIds, uniqueIds) l =
248250 let new = inlineListToIdentifier l
249251 matches = length $ filter (== new) nonuniqueIds
250− new' = new ++ if matches > 0 then ("-" ++ show matches) else ""
252+ new' = (if null new then "section" else new) ++
253+ if matches > 0 then ("-" ++ show matches) else ""
251254 in (new:nonuniqueIds, new':uniqueIds)
252255 in reverse $ snd $ foldl addIdentifier ([],[]) ls
253256