aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-10-24 20:25:09 -0700
committerJohn MacFarlane <[email protected]>2022-10-24 20:25:09 -0700
commit4696af3125fb3af21026477fecd7845800dff764 (patch)
tree44207a9f4365ff87f7a9b56f5938994d2cfd1814
parent8b0519bd3ea618fabfa4349ee78c36e6b5efb76b (diff)
ODT reader: fix relative links.
ODT adds a `../` to relative links (see #3524); this needs to be removed when converting from ODT.
-rw-r--r--src/Text/Pandoc/Readers/Odt/ContentReader.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
index 25573549e..77324ac2f 100644
--- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs
+++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
@@ -56,6 +56,7 @@ import Text.Pandoc.Readers.Odt.Generic.Fallible
import Text.Pandoc.Readers.Odt.Generic.Utils
import Text.Pandoc.Readers.Odt.Generic.XMLConverter
+import Network.URI (parseRelativeReference, URI(uriPath))
import qualified Data.Set as Set
--------------------------------------------------------------------------------
@@ -688,7 +689,8 @@ read_list_element listElement = matchingElement NsText listElement
read_link :: InlineMatcher
read_link = matchingElement NsText "a"
$ liftA3 link
- ( findAttrTextWithDefault NsXLink "href" "" )
+ ( findAttrTextWithDefault NsXLink "href" ""
+ >>> arr fixRelativeLink )
( findAttrTextWithDefault NsOffice "title" "" )
( matchChildContent [ read_span
, read_note
@@ -700,6 +702,14 @@ read_link = matchingElement NsText "a"
, read_reference_ref
] read_plain_text )
+fixRelativeLink :: T.Text -> T.Text
+fixRelativeLink uri =
+ case parseRelativeReference (T.unpack uri) of
+ Nothing -> uri
+ Just u ->
+ case uriPath u of
+ '.':'.':'/':xs -> tshow $ u{ uriPath = xs }
+ _ -> uri
-------------------------
-- Footnotes