aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-11 10:33:04 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-11-11 10:33:04 -0800
commit6b4b7a4ba3fc07036185c08c1f3cc8c3ca30c456 (patch)
tree2cde662100d842c64b261db955f8983b77f88756 /src/Text/Pandoc
parent73ccc7f3d086d2f854bba249231991aeb6cf6101 (diff)
downloadpandoc-6b4b7a4ba3fc07036185c08c1f3cc8c3ca30c456.tar.gz
Clean up toIdent in CommonMark reader.
This partially addresses #5057, fixing a bad interaction between the `ascii_identifiers` extension and the `gfm_auto_identifiers` extension, and creating identifiers that match the ones GitHub produces. This code still needs to be put somewhere common, so the `gfm_auto_identifiers` extension will work with other formats.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/CommonMark.hs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs
index 9c4f7a8ac..5a2e5784a 100644
--- a/src/Text/Pandoc/Readers/CommonMark.hs
+++ b/src/Text/Pandoc/Readers/CommonMark.hs
@@ -36,7 +36,7 @@ where
import Prelude
import CMarkGFM
import Control.Monad.State
-import Data.Char (isAlphaNum, isLetter, isSpace, toLower)
+import Data.Char (isAlphaNum, isSpace, toLower)
import Data.List (groupBy)
import qualified Data.Map as Map
import Data.Maybe (mapMaybe)
@@ -93,13 +93,14 @@ addHeaderId opts (Header lev (_,classes,kvs) ils) = do
addHeaderId _ x = return x
toIdent :: ReaderOptions -> [Inline] -> String
-toIdent opts = map (\c -> if isSpace c then '-' else c)
- . filterer
- . map toLower . stringify
- where filterer = if isEnabled Ext_ascii_identifiers opts
- then mapMaybe toAsciiChar
- else filter (\c -> isLetter c || isAlphaNum c || isSpace c ||
- c == '_' || c == '-')
+toIdent opts =
+ filterAscii . filterPunct . spaceToDash . map toLower. stringify
+ where
+ filterAscii = if isEnabled Ext_ascii_identifiers opts
+ then mapMaybe toAsciiChar
+ else id
+ filterPunct = filter (\c -> isAlphaNum c || c == '_' || c == '-')
+ spaceToDash = map (\c -> if isSpace c then '-' else c)
nodeToPandoc :: ReaderOptions -> Node -> Pandoc
nodeToPandoc opts (Node _ DOCUMENT nodes) =