git.iko.soy/typeable/pandoc
on master help sign in
Regularized the scheme for unique header identifiers in HTML writer:

- punctuation is now all removed (except -) - spaces are turned into - - all lowercase This scheme should be fairly predictable. Updated tests accordingly. git-svn-id: https://pandoc.googlecode.com/svn/trunk@655 788f1e2b-df1e-0410-8736-df70ead52e1b

commit2d4a22d0be7e2da288c4af43250d6d3c607ccf8b authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 8 Jul 2007, 17:33 (19 years ago) parent497a1b7
4 files changed+21−11
src/Text/Pandoc/Writers/HTML.hs+14−4 tests/s5.basic.html+3−3 tests/s5.fancy.html+3−3 tests/writer.html+1−1
src/Text/Pandoc/Writers/HTML.hs+14−4
@@ -34,7 +34,7 @@ import Text.Pandoc.Entities (decodeEntities)
3434import Text.Regex ( mkRegex, matchRegex )
3535import Numeric ( showHex )
3636import Data.Char ( ord, toLower )
37−import Data.List ( isPrefixOf, partition )
37+import Data.List ( isPrefixOf, partition, intersperse )
3838import Control.Monad.State
3939import Text.XHtml.Strict
4040
@@ -169,22 +169,32 @@ obfuscateChar char =
169169obfuscateString :: String -> String
170170obfuscateString = (concatMap obfuscateChar) . decodeEntities
171171
172+-- | True if character is a punctuation character (unicode).
173+isPunctuation :: Char -> Bool
174+isPunctuation c =
175+ let c' = ord c in
176+ if (c `elem` "!\"'()*,-./:;<>?[\\]`{|}~") || (c' >= 0x2000 && c' <= 0x206F) ||
177+ (c' >= 0xE000 && c' <= 0xE0FF)
178+ then True
179+ else False
180+
172181-- | Convert Pandoc inline list to plain text identifier.
173182inlineListToIdentifier :: [Inline] -> String
174183inlineListToIdentifier [] = ""
175184inlineListToIdentifier (x:xs) =
176185 xAsText ++ inlineListToIdentifier xs
177186 where xAsText = case x of
178− Str s -> map toLower s
187+ Str s -> filter (\c -> (c == '-') || not (isPunctuation c)) $
188+ concat $ intersperse "-" $ words $ map toLower s
179189 Emph lst -> inlineListToIdentifier lst
180190 Strong lst -> inlineListToIdentifier lst
181191 Quoted _ lst -> inlineListToIdentifier lst
182192 Code s -> s
183193 Space -> "-"
184− EmDash -> "--"
194+ EmDash -> "-"
185195 EnDash -> "-"
186196 Apostrophe -> ""
187− Ellipses -> "..."
197+ Ellipses -> ""
188198 LineBreak -> "-"
189199 TeX _ -> ""
190200 HtmlInline _ -> ""
tests/s5.basic.html+3−3
@@ -749,7 +749,7 @@ window.onresize = function(){setTimeout('fontScale()', 50);}</script>
749749<div id="currentSlide"></div>
750750<div id="header"></div>
751751<div id="footer">
752−<h1 id="july 15, 2006"
752+<h1 id="july-15-2006"
753753 >July 15, 2006</h1
754754 ><h2 id="my-s5-document"
755755 >My S5 Document</h2
@@ -760,9 +760,9 @@ window.onresize = function(){setTimeout('fontScale()', 50);}</script>
760760<div class="slide">
761761<h1 id="my-s5-document-1"
762762 >My S5 Document</h1
763− ><h3 id="sam smith, jen jones"
763+ ><h3 id="sam-smith-jen-jones"
764764 >Sam Smith, Jen Jones</h3
765− ><h4 id="july 15, 2006-1"
765+ ><h4 id="july-15-2006-1"
766766 >July 15, 2006</h4
767767 ></div>
768768<div class="slide">
tests/s5.fancy.html+3−3
@@ -1661,7 +1661,7 @@ else
16611661<div id="currentSlide"></div>
16621662<div id="header"></div>
16631663<div id="footer">
1664−<h1 id="july 15, 2006"
1664+<h1 id="july-15-2006"
16651665 >July 15, 2006</h1
16661666 ><h2 id="my-s5-document"
16671667 >My S5 Document</h2
@@ -1672,9 +1672,9 @@ else
16721672<div class="slide">
16731673<h1 id="my-s5-document-1"
16741674 >My S5 Document</h1
1675− ><h3 id="sam smith, jen jones"
1675+ ><h3 id="sam-smith-jen-jones"
16761676 >Sam Smith, Jen Jones</h3
1677− ><h4 id="july 15, 2006-1"
1677+ ><h4 id="july-15-2006-1"
16781678 >July 15, 2006</h4
16791679 ></div>
16801680<div class="slide">
tests/writer.html+1−1
@@ -636,7 +636,7 @@ Blah
636636 >&lt;html&gt;</code
637637 >.</p
638638 ><hr
639− /><h1 id="smart-quotes,-ellipses,-dashes"
639+ /><h1 id="smart-quotes-ellipses-dashes"
640640 >Smart quotes, ellipses, dashes</h1
641641 ><p
642642 >&ldquo;Hello,&rdquo; said the spider. &ldquo;&lsquo;Shelob&rsquo; is my name.&rdquo;</p