Citeproc: apply fixLinks correctly.

This is code that incorporates a prefix like `https://doi.org/`
into a following link when appropriate.  But it didn't work because
we were walking with a `[Inline] -> [Inline]` function on an `Inlines`.
Changed the point of application of `fixLink` to resolve the issue.
Closes #7130.
This commit is contained in:
John MacFarlane 2021-03-12 11:57:31 -08:00
parent 92ffd37475
commit 894ed8ebb0

View file

@ -49,7 +49,6 @@ import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import System.FilePath (takeExtension) import System.FilePath (takeExtension)
import Safe (lastMay, initSafe) import Safe (lastMay, initSafe)
-- import Debug.Trace as Trace (trace, traceShowId)
processCitations :: PandocMonad m => Pandoc -> m Pandoc processCitations :: PandocMonad m => Pandoc -> m Pandoc
@ -91,11 +90,12 @@ processCitations (Pandoc meta bs) = do
_ -> id) $ [] _ -> id) $ []
let bibs = mconcat $ map (\(ident, out) -> let bibs = mconcat $ map (\(ident, out) ->
B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para . B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para .
walk (convertQuotes locale) . insertSpace $ out) walk (convertQuotes locale) .
insertSpace $ out)
(resultBibliography result) (resultBibliography result)
let moveNotes = maybe True truish $ let moveNotes = maybe True truish $
lookupMeta "notes-after-punctuation" meta lookupMeta "notes-after-punctuation" meta
let cits = map (walk fixLinks . walk (convertQuotes locale)) $ let cits = map (walk (convertQuotes locale)) $
resultCitations result resultCitations result
let fixQuotes = case localePunctuationInQuote locale of let fixQuotes = case localePunctuationInQuote locale of
@ -294,7 +294,7 @@ insertResolvedCitations (Cite cs ils) = do
[] -> return (Cite cs ils) [] -> return (Cite cs ils)
(x:xs) -> do (x:xs) -> do
put xs put xs
return $ Cite cs (B.toList x) return $ Cite cs (walk fixLinks $ B.toList x)
insertResolvedCitations x = return x insertResolvedCitations x = return x
getCitations :: Locale getCitations :: Locale
@ -431,7 +431,7 @@ mvPunct _ _ [] = []
-- move https://doi.org etc. prefix inside link text (#6723): -- move https://doi.org etc. prefix inside link text (#6723):
fixLinks :: [Inline] -> [Inline] fixLinks :: [Inline] -> [Inline]
fixLinks (Str t : Link attr [Str u1] (u2,tit) : xs) fixLinks (Str t : Link attr [Str u1] (u2,tit) : xs)
| t <> u1 == u2 | u2 == t <> u1
= Link attr [Str (t <> u1)] (u2,tit) : fixLinks xs = Link attr [Str (t <> u1)] (u2,tit) : fixLinks xs
fixLinks (x:xs) = x : fixLinks xs fixLinks (x:xs) = x : fixLinks xs
fixLinks [] = [] fixLinks [] = []