Den 2019-02-07 kl. 07:26, skrev Alon Bar-Lev: > Thanks! > But then the markdown will not be able to process the files as separate files. > For example, I use markdown generation online on top of git, so > references should be between files and expose this to users. But when > I create a PDF or HTML out of all the files using pandoc, I expect the > generation to be aware of the files it reads and convert the links > that matches the files into inline references. I have attached a filter which hopefully solves your problems. It seems to me you actually got two problems here: 1. If you generate one big file with the whole text you want internal targets like `#title-b` but when you generate separate files from each source file containing a major section you want external targets like `b.html`, `b.pdf` or even `b.html#b-title`. 2. You probably want the file extensions in your external targets to be the one appropriate for each generated file format rather than the file extension of your source files. Luckily both problems are easy to solve with a filter or two: 1. Since Link elements take attributes in recent versions of Pandoc you can put the internal target in the target slot of your link elements and add the external target as a custom attribute, i.e. instead of `[here](b.html)` *or* `[here](#b-title)` you type `[here](#b-title){file=b.html}` and let a filter replace the internal target in the target slot with the external target in the attribute when generating multi-file output. (Theoretically you could do it the other way around, but its hard to come up with a good attribute name as short as `file` in that case! :-) 2. Here you can have a filter replace the `.md` extension --- or even a dummy extension like `.foo` --- with the appropriate extension for each output format. Ideally you want a configurable filter. Filters can be configured either through document metadata --- which can also be set on the command line with the `-M` option --- or with environment variables. I usually provide for both so that I can have the general case configured in the environment and then override it with metadata as needed. So in this filter you have the following configuration variables: | Metadata key | Purpose | Default | |:----------------|:----------------------------------------|:--------| | `file_urls` | Replace internal targets with external? | false | | `file_url_attr` | The attribute to use for file urls. | `file` | | `dummy_ext` | The extension which should be replaced. | `md` | | `real_ext` | The extension to replace it with. | `html` | All the environment variable names are derived from the metadata keys by capitalizing them and prepending the prefix `PANDOC_CROSSURLS_`, so `PANDOC_CROSSURLS_FILE_URLS` and so on. Since the `file_urls` variable is a boolean the environment variable value has to be converted to one: the value `false` (case insensitive) counts as false, all other defined values as true. Undefined/unset means that the metadata value wins. So when generating a single file (with internal links) you just say pandoc --lua-filter pandoc-crossurls.lua -M file_urls=false -o combined.pdf *.md and when generating a separate file you say pandoc --lua-filter pandoc-crossurls.lua -M file_urls -M real_ext=pdf -o a.pdf a.md -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a2366d6c-8f01-2119-1c93-30404f689d25%40gmail.com. For more options, visit https://groups.google.com/d/optout.