@@ -599,19 +599,31 @@ pLineBreak = do
599599 pSelfClosing (=="br") (const True)
600600 return B.linebreak
601601
602+-- Unlike fromAttrib from tagsoup, this distinguishes
603+-- between a missing attribute and an attribute with empty content.
604+maybeFromAttrib :: String -> Tag String -> Maybe String
605+maybeFromAttrib name (TagOpen _ attrs) = lookup name attrs
606+maybeFromAttrib _ _ = Nothing
607+
602608pLink :: TagParser Inlines
603609pLink = try $ do
604610 tag <- pSatisfy $ tagOpenLit "a" (const True)
605− mbBaseHref <- baseHref <$> getState
606− let url' = fromAttrib "href" tag
607− let url = case (parseURIReference url', mbBaseHref) of
608− (Just rel, Just bs) -> show (rel `nonStrictRelativeTo` bs)
609− _ -> url'
610611 let title = fromAttrib "title" tag
611− let uid = fromAttrib "id" tag
612+ -- take id from id attribute if present, otherwise name
613+ let uid = maybe (fromAttrib "name" tag) id $ maybeFromAttrib "id" tag
612614 let cls = words $ fromAttrib "class" tag
613615 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
614− return $ B.linkWith (uid, cls, []) (escapeURI url) title lab
616+ -- check for href; if href, then a link, otherwise a span
617+ case maybeFromAttrib "href" tag of
618+ Nothing ->
619+ return $ B.spanWith (uid, cls, []) lab
620+ Just url' -> do
621+ mbBaseHref <- baseHref <$> getState
622+ let url = case (parseURIReference url', mbBaseHref) of
623+ (Just rel, Just bs) ->
624+ show (rel `nonStrictRelativeTo` bs)
625+ _ -> url'
626+ return $ B.linkWith (uid, cls, []) (escapeURI url) title lab
615627
616628pImage :: TagParser Inlines
617629pImage = do