HTML reader: extract spaces inside links instead of trimming them

Fixes #4845
This commit is contained in:
Alexander Krotov 2018-08-22 12:16:57 +03:00
parent 3b5949e8f2
commit 937b92cd30
2 changed files with 9 additions and 3 deletions

View file

@ -745,18 +745,18 @@ pLink = try $ do
let uid = fromMaybe (T.unpack $ fromAttrib "name" tag) $
maybeFromAttrib "id" tag
let cls = words $ T.unpack $ fromAttrib "class" tag
lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
lab <- mconcat <$> manyTill inline (pCloses "a")
-- check for href; if href, then a link, otherwise a span
case maybeFromAttrib "href" tag of
Nothing ->
return $ B.spanWith (uid, cls, []) lab
return $ extractSpaces (B.spanWith (uid, cls, [])) lab
Just url' -> do
mbBaseHref <- baseHref <$> getState
let url = case (parseURIReference url', mbBaseHref) of
(Just rel, Just bs) ->
show (rel `nonStrictRelativeTo` bs)
_ -> url'
return $ B.linkWith (uid, cls, []) (escapeURI url) title lab
return $ extractSpaces (B.linkWith (uid, cls, []) (escapeURI url) title) lab
pImage :: PandocMonad m => TagParser m Inlines
pImage = do

6
test/command/4845.md Normal file
View file

@ -0,0 +1,6 @@
```
% pandoc -f html -t native
x<a href="/foo"> leading trailing space </a>x
^D
[Plain [Str "x",Space,Link ("",[],[]) [Str "leading",Space,Str "trailing",Space,Str "space"] ("/foo",""),Space,Str "x"]]
```