git.iko.soy/typeable/pandoc
on master help sign in
Modified rules for HTML header identifiers to ensure legal identifiers.

+ Modified htmlListToIdentifier and uniqueIdentifier in HTML writer to ensure that identifiers begin with an alphabetic character. + The new rules are described in README. + Resolves Issue #33. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1150 788f1e2b-df1e-0410-8736-df70ead52e1b

commit48f2cc5600bd26c60ffa1d5531ba2d9aeead129d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 21 Dec 2007, 19:25 (19 years ago) parent0681d1d
2 files changed+29−19
README+13−6 Text/Pandoc/Writers/HTML.hs+16−13
README+13−6
@@ -790,12 +790,19 @@ derive the identifier from the header text,
790790 - Remove all punctuation, except dashes and hyphens.
791791 - Replace all spaces, dashes, newlines, and hyphens with hyphens.
792792 - Convert all alphabetic characters to lowercase.
793−
794−Thus, for example, a heading 'Header identifiers in HTML' will get
795−the identifier `header-identifiers-in-html`, a heading
796−'*Dogs*?--in *my* house?' will get the identifier `dogs--in-my-house`,
797−and a heading '[HTML], [S5], or [RTF]?' will get the identifier
798−`html-s5-or-rtf`.
793+ - Remove everything up to the first letter (identifiers may
794+ not begin with a number or punctuation mark).
795+ - If nothing is left after this, use the identifier `section`.
796+
797+Thus, for example,
798+
799+ Header Identifier
800+ ------------------------------------- ---------------------------
801+ Header identifiers in HTML `header-identifiers-in-html`
802+ *Dogs*?--in *my* house? `dogs--in-my-house`
803+ [HTML], [S5], or [RTF]? `html-s5-or-rtf`
804+ 3. Applications `applications`
805+ 33 `section`
799806
800807These rules should, in most cases, allow one to determine the identifier
801808from the header text. The exception is when several headers have the
Text/Pandoc/Writers/HTML.hs+16−13
@@ -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