@@ -684,19 +684,27 @@ pSelfClosing f g = do
684684 return open
685685
686686pQ :: PandocMonad m => TagParser m Inlines
687−pQ = do
688− context <- asks quoteContext
689− let quoteType = case context of
690− InDoubleQuote -> SingleQuote
691− _ -> DoubleQuote
692− let innerQuoteContext = if quoteType == SingleQuote
693− then InSingleQuote
694− else InDoubleQuote
695− let constructor = case quoteType of
696− SingleQuote -> B.singleQuoted
697− DoubleQuote -> B.doubleQuoted
698− withQuoteContext innerQuoteContext $
699− pInlinesInTags "q" constructor
687+pQ = choice $ map try [citedQuote, normalQuote]
688+ where citedQuote = do
689+ tag <- pSatisfy $ tagOpenLit "q" (any ((=="cite") . fst))
690+
691+ url <- canonicalizeUrl $ T.unpack $ fromAttrib "cite" tag
692+ let uid = fromMaybe (T.unpack $ fromAttrib "name" tag) $
693+ maybeFromAttrib "id" tag
694+ let cls = words $ T.unpack $ fromAttrib "class" tag
695+
696+ makeQuote $ B.spanWith (uid, cls, [("cite", escapeURI url)])
697+ normalQuote = do
698+ pSatisfy $ tagOpenLit "q" (const True)
699+ makeQuote id
700+ makeQuote wrapper = do
701+ ctx <- asks quoteContext
702+ let (constructor, innerContext) = case ctx of
703+ InDoubleQuote -> (B.singleQuoted, InSingleQuote)
704+ _ -> (B.doubleQuoted, InDoubleQuote)
705+
706+ content <- withQuoteContext innerContext (mconcat <$> manyTill inline (pCloses "q"))
707+ return $ extractSpaces (constructor . wrapper) content
700708
701709pEmph :: PandocMonad m => TagParser m Inlines
702710pEmph = pInlinesInTags "em" B.emph <|> pInlinesInTags "i" B.emph
@@ -757,21 +765,13 @@ pLink = try $ do
757765 Nothing ->
758766 return $ extractSpaces (B.spanWith (uid, cls, [])) lab
759767 Just url' -> do
760− mbBaseHref <- baseHref <$> getState
761− let url = case (parseURIReference url', mbBaseHref) of
762− (Just rel, Just bs) ->
763− show (rel `nonStrictRelativeTo` bs)
764− _ -> url'
768+ url <- canonicalizeUrl url'
765769 return $ extractSpaces (B.linkWith (uid, cls, []) (escapeURI url) title) lab
766770
767771pImage :: PandocMonad m => TagParser m Inlines
768772pImage = do
769773 tag <- pSelfClosing (=="img") (isJust . lookup "src")
770− mbBaseHref <- baseHref <$> getState
771− let url' = T.unpack $ fromAttrib "src" tag
772− let url = case (parseURIReference url', mbBaseHref) of
773− (Just rel, Just bs) -> show (rel `nonStrictRelativeTo` bs)
774− _ -> url'
774+ url <- canonicalizeUrl $ T.unpack $ fromAttrib "src" tag
775775 let title = T.unpack $ fromAttrib "title" tag
776776 let alt = T.unpack $ fromAttrib "alt" tag
777777 let uid = T.unpack $ fromAttrib "id" tag
@@ -1292,6 +1292,17 @@ isSpace '\n' = True
12921292isSpace '\r' = True
12931293isSpace _ = False
12941294
1295+-- Utilities
1296+
1297+-- | Adjusts a url according to the document's base URL.
1298+canonicalizeUrl :: PandocMonad m => String -> TagParser m String
1299+canonicalizeUrl url = do
1300+ mbBaseHref <- baseHref <$> getState
1301+ return $ case (parseURIReference url, mbBaseHref) of
1302+ (Just rel, Just bs) -> show (rel `nonStrictRelativeTo` bs)
1303+ _ -> url
1304+
1305+
12951306-- Instances
12961307
12971308instance HasMacros HTMLState where