git.iko.soy/typeable/pandoc
on master help sign in
Modify rebase_reference_links treatment of reference links/images.

The directory is based on the file containing the link reference, not the file containing the link, if these differ.

commit6972a7dc9158c1d56b2dc9a06f596386f6b30860 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 27 May 2021, 11:26 (5 years ago) parentcbe16b2
5 files changed+17−7
MANUAL.txt+5−1 src/Text/Pandoc/Readers/Markdown.hs+4−5 test/command/3752.md+4−1 test/command/chap1/text.md+2 test/command/chap2/text.md+2
MANUAL.txt+5−1
@@ -5080,7 +5080,11 @@ Without this extension, you would have to use
50805080`![image](chap1/spider.jpg)` in `chap1/text.md` and
50815081`![image](chap2/spider.jpg)` in `chap2/text.md`. Links with
50825082relative paths will be rewritten in the same way as images.
5083−*This option currently only affects Markdown input.*
5083+
5084+Note that relative paths in reference links and images will
5085+be rewritten relative to the file containing the link
5086+reference definition, not the file containing the reference link
5087+or image itself, if these differ.
50845088
50855089#### Extension: `attributes` ####
50865090
src/Text/Pandoc/Readers/Markdown.hs+4−5
@@ -336,7 +336,9 @@ referenceKey = try $ do
336336 notFollowedBy' (() <$ reference)
337337 many1Char $ notFollowedBy space >> litChar
338338 let betweenAngles = try $ char '<' >> manyTillChar litChar (char '>')
339− src <- try betweenAngles <|> sourceURL
339+ rebase <- option False (True <$ guardEnabled Ext_rebase_relative_paths)
340+ src <- (if rebase then rebasePath pos else id) <$>
341+ (try betweenAngles <|> sourceURL)
340342 tit <- option "" referenceTitle
341343 attr <- option nullAttr $ try $
342344 do guardEnabled Ext_link_attributes
@@ -1857,8 +1859,6 @@ referenceLink constructor (lab, raw) = do
18571859 return (mempty, "")))
18581860 <|>
18591861 try ((guardDisabled Ext_spaced_reference_links <|> spnl) >> reference)
1860− rebase <- option False (True <$ guardEnabled Ext_rebase_relative_paths)
1861− pos <- getPosition
18621862 when (raw' == "") $ guardEnabled Ext_shortcut_reference_links
18631863 let labIsRef = raw' == "" || raw' == "[]"
18641864 let key = toKey $ if labIsRef then raw else raw'
@@ -1884,8 +1884,7 @@ referenceLink constructor (lab, raw) = do
18841884 Nothing -> makeFallback
18851885 else makeFallback
18861886 Just ((src,tit), attr) ->
1887− let src' = if rebase then rebasePath pos src else src
1888− in constructor attr src' tit <$> lab
1887+ constructor attr src tit <$> lab
18891888
18901889dropBrackets :: Text -> Text
18911890dropBrackets = dropRB . dropLB
test/command/3752.md+4−1
@@ -2,12 +2,14 @@
22% pandoc command/chap1/text.md command/chap2/text.md -f markdown+rebase_relative_paths --verbose -t docx | pandoc -f docx -t plain
33^D
44[INFO] Loaded command/chap1/spider.png from ./command/chap1/spider.png
5−[INFO] Loaded command/chap1/../../lalune.jpg from ./command/chap1/../../lalune.jpg
65[INFO] Loaded command/chap2/spider.png from ./command/chap2/spider.png
6+[INFO] Loaded command/chap1/../../lalune.jpg from ./command/chap1/../../lalune.jpg
77Chapter one
88
99A spider: [spider]
1010
11+Another spider: [another spider]
12+
1113The moon: [moon]
1214
1315Link to spider picture.
@@ -26,6 +28,7 @@ A spider: [spider]
2628^D
2729<h1 id="chapter-one">Chapter one</h1>
2830<p>A spider: <img src="command/chap1/spider.png" alt="spider" /></p>
31+<p>Another spider: <img src="command/chap2/spider.png" alt="another spider" /></p>
2932<p>The moon: <img src="command/chap1/../../lalune.jpg" alt="moon" /></p>
3033<p>Link to <a href="command/chap1/spider.png">spider picture</a>.</p>
3134<p>URL left alone: <a href="https://pandoc.org/MANUAL.html">manual</a>.</p>
test/command/chap1/text.md+2
@@ -2,6 +2,8 @@
22
33A spider: ![spider](spider.png)
44
5+Another spider: ![another spider][refspider]
6+
57The moon: ![moon](../../lalune.jpg)
68
79Link to [spider picture](spider.png).
test/command/chap2/text.md+2
@@ -1,3 +1,5 @@
11# Chapter two
22
33A spider: ![spider](spider.png)
4+
5+[refspider]: spider.png