Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Relative file import in include-files filter #102

Closed
gabyx opened this issue Jul 16, 2020 · 11 comments
Closed

Feature request: Relative file import in include-files filter #102

gabyx opened this issue Jul 16, 2020 · 11 comments

Comments

@gabyx
Copy link

gabyx commented Jul 16, 2020

Would it make sense to add an attribute relative-to-current-dir=true or something such that, all paths or better all relative paths are resolved to the current file path we are currently at (maybe not so easy to distinguish platform independent, relative vs absolute paths).
Therefore maybe, just replace a variable "${current-dir}/b/c.md" in all paths, which would give a deterministic and consistent way of relative imports :)?

@tarleb: What do you think?

In a/b.md

``` { .include}
${current-dir}/b/c.md
```

or
In a/b.md

``` { .include relative-to-current-dir=true}
./b/c.md
```
@tarleb
Copy link
Member

tarleb commented Jul 16, 2020

This is a good idea, but poses some problems. Lua, by default does not include the tools to deal with path modifications. Paths are platform dependent, with path separators \ on Windows and / on Linux and Mac. There are two possibilities to support path modifying functions such as dirname or is_relative:

  1. Write a pure Lua implementation, or
  2. expose the path handling library used by pandoc.

Neither is especially difficult, but both options require more work than I'm willing/able to invest right now.

Patches would be most welcome.

@gabyx
Copy link
Author

gabyx commented Jul 17, 2020

I can certainly do a PR. What do you mean with pure Lua? Isn’t there a std lib for path modifications? The path handling library by pandoc is haskell, right? With a python filter this would be really easy to acomplish, but I dont know about the walk_**** functions...

@tarleb
Copy link
Member

tarleb commented Jul 17, 2020

Great!

Lua aims to run on any platform that can be targeted with ANSI C. The latter has no concept of paths, so neither has Lua. Path libraries for Lua exist, but are all written in C, and thereby not an option. The necessary path manipulations should still be doable by pure string manipulations.

The path library used in pandoc is filepath. If you are interested in how this can be exposed to Lua, check hslua-module-system, which exposes selected system and file related functions. Exposing filepath would best be done by adding the necessary bindings to that package.

@gabyx
Copy link
Author

gabyx commented Jul 17, 2020

Probably these functions are the only ones which give enough access to do almost if not all path handling issues in filters:

Any help and review is kindly welcome.
I will try next week what I can do, I think I can directly build and test the hslua module.

@gabyx
Copy link
Author

gabyx commented Jul 26, 2020

What would be the next step to test a merged PR: hslua/hslua-module-system#1
with this include-filter. How to we get these changes here?

Can we just version check the pandoc version in the include-files filter (is it possible?), such that we error out if somebody use a older pandoc version with no lua file manipulations functions...?

@gabyx
Copy link
Author

gabyx commented Jul 26, 2020

Got it: :-) See jgm/pandoc#6565

@lmunch
Copy link
Contributor

lmunch commented May 13, 2021

@gabyx I think latest changes to include-files will solve this issue. Please check.

@gabyx
Copy link
Author

gabyx commented May 14, 2021

@lmunch Thats really greate to hear: Is the doc already up to date, because I ve not seen any explanation on the feature?

@lmunch
Copy link
Contributor

lmunch commented May 14, 2021

@gabyx See the Recursive transclusion section. It's default behaviour now, so no feature flag.

@gabyx
Copy link
Author

gabyx commented May 14, 2021

@lmunch : Thanks for the effort! Its great! Sorry I was to impatient to read carefully!

@lmunch
Copy link
Contributor

lmunch commented May 19, 2021

Resolved with #173

@gabyx gabyx closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants