@@ -684,19 +684,27 @@ pSelfClosing f g = do
684 return open
684 return open
686pQ :: PandocMonad m => TagParser m Inlines
686pQ :: PandocMonad m => TagParser m Inlines
687−pQ = do
687+pQ = choice $ map try [citedQuote, normalQuote]
688+ where citedQuote = do
689+ tag <- pSatisfy $ tagOpenLit "q" (any ((=="cite") . fst))
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
696+ makeQuote $ B.spanWith (uid, cls, [("cite", escapeURI url)])
698+ pSatisfy $ tagOpenLit "q" (const True)
700+ makeQuote wrapper = do
688− context <- asks quoteContext
701+ ctx <- asks quoteContext
689− let quoteType = case context of
702+ let (constructor, innerContext) = case ctx of
690− InDoubleQuote -> SingleQuote
703+ InDoubleQuote -> (B.singleQuoted, InSingleQuote)
692− let innerQuoteContext = if quoteType == SingleQuote
695− let constructor = case quoteType of
696− SingleQuote -> B.singleQuoted
697− DoubleQuote -> B.doubleQuoted
704+ _ -> (B.doubleQuoted, InDoubleQuote)
698− withQuoteContext innerQuoteContext $
705+
699− pInlinesInTags "q" constructor
706+ content <- withQuoteContext innerContext (mconcat <$> manyTill inline (pCloses "q"))
707+ return $ extractSpaces (constructor . wrapper) content
701pEmph :: PandocMonad m => TagParser m Inlines
709pEmph :: PandocMonad m => TagParser m Inlines
702pEmph = pInlinesInTags "em" B.emph <|> pInlinesInTags "i" B.emph
710pEmph = pInlinesInTags "em" B.emph <|> pInlinesInTags "i" B.emph
@@ -757,21 +765,13 @@ pLink = try $ do
757 Nothing ->
765 Nothing ->
758 return $ extractSpaces (B.spanWith (uid, cls, [])) lab
766 return $ extractSpaces (B.spanWith (uid, cls, [])) lab
759 Just url' -> do
767 Just url' -> do
760− mbBaseHref <- baseHref <$> getState
768+ url <- canonicalizeUrl url'
761− let url = case (parseURIReference url', mbBaseHref) of
762− (Just rel, Just bs) ->
763− show (rel `nonStrictRelativeTo` bs)
765 return $ extractSpaces (B.linkWith (uid, cls, []) (escapeURI url) title) lab
769 return $ extractSpaces (B.linkWith (uid, cls, []) (escapeURI url) title) lab
767pImage :: PandocMonad m => TagParser m Inlines
771pImage :: PandocMonad m => TagParser m Inlines
768pImage = do
772pImage = do
769 tag <- pSelfClosing (=="img") (isJust . lookup "src")
773 tag <- pSelfClosing (=="img") (isJust . lookup "src")
770− mbBaseHref <- baseHref <$> getState
771− let url' = T.unpack $ fromAttrib "src" tag
774+ url <- canonicalizeUrl $ T.unpack $ fromAttrib "src" tag
772− let url = case (parseURIReference url', mbBaseHref) of
773− (Just rel, Just bs) -> show (rel `nonStrictRelativeTo` bs)
775 let title = T.unpack $ fromAttrib "title" tag
775 let title = T.unpack $ fromAttrib "title" tag
776 let alt = T.unpack $ fromAttrib "alt" tag
776 let alt = T.unpack $ fromAttrib "alt" tag
777 let uid = T.unpack $ fromAttrib "id" tag
777 let uid = T.unpack $ fromAttrib "id" tag
@@ -1292,6 +1292,17 @@ isSpace '\n' = True
1292isSpace '\r' = True
1292isSpace '\r' = True
1293isSpace _ = False
1293isSpace _ = False
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)
1295-- Instances
1306-- Instances
1297instance HasMacros HTMLState where
1308instance HasMacros HTMLState where