From cde9991e43bdae6bb8510ec214a4374895a46b03 Mon Sep 17 00:00:00 2001 From: black-desk Date: Fri, 27 Sep 2024 12:10:48 +0800 Subject: [PATCH 1/4] include-files: update makefile and test data Signed-off-by: black-desk --- include-files/Makefile | 6 +++--- include-files/expected-auto.native | 15 ++++++++++----- include-files/expected.native | 15 ++++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include-files/Makefile b/include-files/Makefile index 61039b09..3bea887e 100644 --- a/include-files/Makefile +++ b/include-files/Makefile @@ -1,16 +1,16 @@ DIFF ?= diff --strip-trailing-cr -u PANDOC ?= pandoc -test: sample.md file-a.md file-b.md file-c.md include-files.lua +test: sample.md file-a.md file-b.md file-c.md subdir/file-g.md include-files.lua @$(PANDOC) --lua-filter=include-files.lua --to=native $< \ | $(DIFF) expected.native - @$(PANDOC) --lua-filter=include-files.lua -M include-auto --to=native $< \ | $(DIFF) expected-auto.native - -expected.native: sample.md file-a.md file-b.md file-c.md include-files.lua +expected.native: sample.md file-a.md file-b.md file-c.md subdir/file-g.md include-files.lua $(PANDOC) --lua-filter=include-files.lua --output $@ $< -expected-auto.native: sample.md file-a.md file-b.md file-c.md include-files.lua +expected-auto.native: sample.md file-a.md file-b.md file-c.md subdir/file-g.md include-files.lua $(PANDOC) --lua-filter=include-files.lua -M include-auto --output $@ $< .PHONY: test diff --git a/include-files/expected-auto.native b/include-files/expected-auto.native index 5536cbf6..1fe482fd 100644 --- a/include-files/expected-auto.native +++ b/include-files/expected-auto.native @@ -117,11 +117,16 @@ , Space , Str "updated." ] -, Para - [ Image - ( "" , [] , [] ) - [ Str "Image" , Space , Str "title" ] - ( "subdir/someimage.png" , "fig:" ) +, Figure + ( "" , [] , [] ) + (Caption + Nothing [ Plain [ Str "Image" , Space , Str "title" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "Image" , Space , Str "title" ] + ( "subdir/someimage.png" , "" ) + ] ] , Header 2 diff --git a/include-files/expected.native b/include-files/expected.native index e89a6ba8..78a94a2f 100644 --- a/include-files/expected.native +++ b/include-files/expected.native @@ -117,11 +117,16 @@ , Space , Str "updated." ] -, Para - [ Image - ( "" , [] , [] ) - [ Str "Image" , Space , Str "title" ] - ( "subdir/someimage.png" , "fig:" ) +, Figure + ( "" , [] , [] ) + (Caption + Nothing [ Plain [ Str "Image" , Space , Str "title" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "Image" , Space , Str "title" ] + ( "subdir/someimage.png" , "" ) + ] ] , Header 1 From a16d8ba69045944b47667960b122adcad3fea2e4 Mon Sep 17 00:00:00 2001 From: black-desk Date: Fri, 27 Sep 2024 12:03:01 +0800 Subject: [PATCH 2/4] include-files: use relative path for links See also https://github.com/pandoc-ext/include-files/pull/2 Signed-off-by: black-desk --- include-files/README.md | 4 ++-- include-files/expected-auto.native | 6 ++++++ include-files/expected.native | 6 ++++++ include-files/include-files.lua | 7 +++++++ include-files/subdir/file-g.md | 2 ++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include-files/README.md b/include-files/README.md index 050a94af..2d2197d7 100644 --- a/include-files/README.md +++ b/include-files/README.md @@ -69,8 +69,8 @@ relative to the directory from which they are included. I.e., if a file `a/b.md` is included in the main document, and another file `a/b/c.md` should be included from `a/b.md`, then the relative path from `a/b.md` must be used, in this case `b/c.md`. The full relative path will be automatically generated in the final -document. The same goes for image paths and codeblock file paths using the -`include-code-files` filter. +document. The same goes for image paths, link paths and codeblock file paths +using the `include-code-files` filter. ## Example diff --git a/include-files/expected-auto.native b/include-files/expected-auto.native index 1fe482fd..604cb865 100644 --- a/include-files/expected-auto.native +++ b/include-files/expected-auto.native @@ -128,6 +128,12 @@ ( "subdir/someimage.png" , "" ) ] ] +, Para + [ Link + ( "" , [] , [] ) + [ Str "Some" , Space , Str "link" ] + ( "subdir/someimage.png" , "" ) + ] , Header 2 ( "source-include" , [] , [] ) diff --git a/include-files/expected.native b/include-files/expected.native index 78a94a2f..4977f8da 100644 --- a/include-files/expected.native +++ b/include-files/expected.native @@ -128,6 +128,12 @@ ( "subdir/someimage.png" , "" ) ] ] +, Para + [ Link + ( "" , [] , [] ) + [ Str "Some" , Space , Str "link" ] + ( "subdir/someimage.png" , "" ) + ] , Header 1 ( "source-include" , [] , [] ) diff --git a/include-files/include-files.lua b/include-files/include-files.lua index 2499968c..b9aa6f74 100644 --- a/include-files/include-files.lua +++ b/include-files/include-files.lua @@ -39,6 +39,13 @@ local function update_contents(blocks, shift_by, include_path) end return header end, + -- If link paths are relative then prepend include file path + Link = function (link) + if path.is_relative(link.target) then + link.target = path.normalize(path.join({include_path, link.target})) + end + return link + end, -- If image paths are relative then prepend include file path Image = function (image) if path.is_relative(image.src) then diff --git a/include-files/subdir/file-g.md b/include-files/subdir/file-g.md index 1ce89a90..818cf272 100644 --- a/include-files/subdir/file-g.md +++ b/include-files/subdir/file-g.md @@ -4,6 +4,8 @@ Image relative path will be updated. ![Image title](someimage.png) +[Some link](someimage.png) + # Source include File inclusion codeblocks for use with include-code-files will be From f114a8a4f66981d242b9215ed4bf6cd9403e10bd Mon Sep 17 00:00:00 2001 From: black-desk Date: Fri, 27 Sep 2024 13:01:44 +0800 Subject: [PATCH 3/4] include-files: fix https:// like link --- include-files/include-files.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include-files/include-files.lua b/include-files/include-files.lua index b9aa6f74..c9a585a6 100644 --- a/include-files/include-files.lua +++ b/include-files/include-files.lua @@ -41,13 +41,22 @@ local function update_contents(blocks, shift_by, include_path) end, -- If link paths are relative then prepend include file path Link = function (link) - if path.is_relative(link.target) then - link.target = path.normalize(path.join({include_path, link.target})) - end + if string.match(link.target, "^%a+://") then return link + end + + if path.is_relative(link.target) then + link.target = path.normalize(path.join({include_path, link.target})) + end + + return link end, -- If image paths are relative then prepend include file path Image = function (image) + if string.match(image.src, "^%a+://") then + return image + end + if path.is_relative(image.src) then image.src = path.normalize(path.join({include_path, image.src})) end From 4a9fefba728308804af607f5824135c314963dc8 Mon Sep 17 00:00:00 2001 From: black-desk Date: Sat, 12 Oct 2024 10:14:30 +0800 Subject: [PATCH 4/4] include-files: update test --- include-files/expected-auto.native | 17 +++++++++++++++++ include-files/expected.native | 17 +++++++++++++++++ include-files/subdir/file-g.md | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/include-files/expected-auto.native b/include-files/expected-auto.native index 604cb865..144d73ff 100644 --- a/include-files/expected-auto.native +++ b/include-files/expected-auto.native @@ -128,12 +128,29 @@ ( "subdir/someimage.png" , "" ) ] ] +, Figure + ( "" , [] , [] ) + (Caption + Nothing [ Plain [ Str "Image" , Space , Str "title" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "Image" , Space , Str "title" ] + ( "https://example.com/someimage.png" , "" ) + ] + ] , Para [ Link ( "" , [] , [] ) [ Str "Some" , Space , Str "link" ] ( "subdir/someimage.png" , "" ) ] +, Para + [ Link + ( "" , [] , [] ) + [ Str "Some" , Space , Str "link" ] + ( "https://example.com/someimage.png" , "" ) + ] , Header 2 ( "source-include" , [] , [] ) diff --git a/include-files/expected.native b/include-files/expected.native index 4977f8da..c0889e75 100644 --- a/include-files/expected.native +++ b/include-files/expected.native @@ -128,12 +128,29 @@ ( "subdir/someimage.png" , "" ) ] ] +, Figure + ( "" , [] , [] ) + (Caption + Nothing [ Plain [ Str "Image" , Space , Str "title" ] ]) + [ Plain + [ Image + ( "" , [] , [] ) + [ Str "Image" , Space , Str "title" ] + ( "https://example.com/someimage.png" , "" ) + ] + ] , Para [ Link ( "" , [] , [] ) [ Str "Some" , Space , Str "link" ] ( "subdir/someimage.png" , "" ) ] +, Para + [ Link + ( "" , [] , [] ) + [ Str "Some" , Space , Str "link" ] + ( "https://example.com/someimage.png" , "" ) + ] , Header 1 ( "source-include" , [] , [] ) diff --git a/include-files/subdir/file-g.md b/include-files/subdir/file-g.md index 818cf272..cd97dcd9 100644 --- a/include-files/subdir/file-g.md +++ b/include-files/subdir/file-g.md @@ -4,8 +4,12 @@ Image relative path will be updated. ![Image title](someimage.png) +![Image title](https://example.com/someimage.png) + [Some link](someimage.png) +[Some link](https://example.com/someimage.png) + # Source include File inclusion codeblocks for use with include-code-files will be