Skip to content

Commit f671f7e

Browse files
committed
Fix URL
`path.is_relative` return true for links like https://example.com. So we have to check if the target of link and image is a path to local file before we update them.
1 parent 364394e commit f671f7e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

expected-auto.native

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,29 @@
128128
( "subdir/someimage.png" , "" )
129129
]
130130
]
131+
, Figure
132+
( "" , [] , [] )
133+
(Caption
134+
Nothing [ Plain [ Str "Image" , Space , Str "title" ] ])
135+
[ Plain
136+
[ Image
137+
( "" , [] , [] )
138+
[ Str "Image" , Space , Str "title" ]
139+
( "https://example.com/someimage.png" , "" )
140+
]
141+
]
131142
, Para
132143
[ Link
133144
( "" , [] , [] )
134145
[ Str "Some" , Space , Str "link" ]
135146
( "subdir/someimage.png" , "" )
136147
]
148+
, Para
149+
[ Link
150+
( "" , [] , [] )
151+
[ Str "Some" , Space , Str "link" ]
152+
( "https://example.com/someimage.png" , "" )
153+
]
137154
, Header
138155
2
139156
( "source-include" , [] , [] )

expected.native

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,29 @@
128128
( "subdir/someimage.png" , "" )
129129
]
130130
]
131+
, Figure
132+
( "" , [] , [] )
133+
(Caption
134+
Nothing [ Plain [ Str "Image" , Space , Str "title" ] ])
135+
[ Plain
136+
[ Image
137+
( "" , [] , [] )
138+
[ Str "Image" , Space , Str "title" ]
139+
( "https://example.com/someimage.png" , "" )
140+
]
141+
]
131142
, Para
132143
[ Link
133144
( "" , [] , [] )
134145
[ Str "Some" , Space , Str "link" ]
135146
( "subdir/someimage.png" , "" )
136147
]
148+
, Para
149+
[ Link
150+
( "" , [] , [] )
151+
[ Str "Some" , Space , Str "link" ]
152+
( "https://example.com/someimage.png" , "" )
153+
]
137154
, Header
138155
1
139156
( "source-include" , [] , [] )

include-files.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ local function update_contents(blocks, shift_by, include_path)
3636
end,
3737
-- If link paths are relative then prepend include file path
3838
Link = function (link)
39+
if string.match(link.target, "^%a+://") then
40+
return link
41+
end
3942
if path.is_relative(link.target) then
4043
link.target = path.normalize(path.join({include_path, link.target}))
4144
end
4245
return link
4346
end,
4447
-- If image paths are relative then prepend include file path
4548
Image = function (image)
49+
if string.match(image.src, "^%a+://") then
50+
return image
51+
end
4652
if path.is_relative(image.src) then
4753
image.src = path.normalize(path.join({include_path, image.src}))
4854
end

subdir/file-g.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ Image relative path will be updated.
44

55
![Image title](someimage.png)
66

7+
![Image title](https://example.com/someimage.png)
8+
79
[Some link](someimage.png)
810

11+
[Some link](https://example.com/someimage.png)
12+
913
# Source include
1014

1115
File inclusion codeblocks for use with include-code-files will be

0 commit comments

Comments
 (0)