diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-19 09:05:30 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-19 09:08:35 -0700 |
commit | b53ea23b3f56a120937922f88f5f1fc3244067d9 (patch) | |
tree | 6c6c6d69cb6c1d26dd747e7d9770c8e5e7056966 /src/Text/Pandoc/Readers | |
parent | 6c5ba22c96aacb49376dc18e82972c05b52ab416 (diff) | |
download | pandoc-b53ea23b3f56a120937922f88f5f1fc3244067d9.tar.gz |
Improved code readability.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 47b1cbbaa..58495d024 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1549,31 +1549,35 @@ referenceLink constructor (lab, raw) = do let labIsRef = raw' == "" || raw' == "[]" let key = toKey $ if labIsRef then raw else raw' parsedRaw <- parseFromString (mconcat <$> many inline) raw' - let dropRB (']':xs) = xs - dropRB xs = xs - let dropLB ('[':xs) = xs - dropLB xs = xs - let dropBrackets = reverse . dropRB . reverse . dropLB fallback <- parseFromString (mconcat <$> many inline) $ dropBrackets raw implicitHeaderRefs <- option False $ True <$ guardEnabled Ext_implicit_header_references + let makeFallback = do + parsedRaw' <- parsedRaw + fallback' <- fallback + return $ B.str "[" <> fallback' <> B.str "]" <> + (if sp && not (null raw) then B.space else mempty) <> + parsedRaw' return $ do keys <- asksF stateKeys case M.lookup key keys of Nothing -> do headers <- asksF stateHeaders ref' <- if labIsRef then lab else ref - parsedRaw' <- parsedRaw - fallback' <- fallback - let fallback'' = B.str "[" <> fallback' <> B.str "]" <> - (if sp && not (null raw) then B.space else mempty) <> parsedRaw' if implicitHeaderRefs then case M.lookup ref' headers of Just ident -> constructor ('#':ident) "" <$> lab - Nothing -> return fallback'' - else return fallback'' + Nothing -> makeFallback + else makeFallback Just (src,tit) -> constructor src tit <$> lab +dropBrackets :: String -> String +dropBrackets = reverse . dropRB . reverse . dropLB + where dropRB (']':xs) = xs + dropRB xs = xs + dropLB ('[':xs) = xs + dropLB xs = xs + bareURL :: MarkdownParser (F Inlines) bareURL = try $ do guardEnabled Ext_autolink_bare_uris |