public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* [markdown] links between documents
@ 2019-02-06 21:00 Alon Bar-Lev
       [not found] ` <CAOazyz04jcRfqkGEkpb2FcBmjVJ7C=7cvSf-Tm1wKBWeCKEuoQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Alon Bar-Lev @ 2019-02-06 21:00 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi All,

I need to find a solution of generate markdown to pdf.
pandoc looks promising, however, I must be missing something.

Let's take the following two files:

a.md
---
# Title A

A content.

See [this](b.md).
---

b.md
---
# Title B

B content.
---

Run:
$ pandoc -o a.html --reference-links a.md b.md
$ pandoc -o a.pdf --reference-links a.md b.md

In both cases the link to B actually goes to the filesystem b.md
instead of being a reference to the content of B within the document.

Can this be worked out somehow with parameters? I could not find
anything that made an impact.

Thanks,
Alon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [markdown] links between documents
       [not found] ` <CAOazyz04jcRfqkGEkpb2FcBmjVJ7C=7cvSf-Tm1wKBWeCKEuoQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-02-07  0:13   ` BPJ
       [not found]     ` <CADAJKhCnRDa+CWqntyPrvqfpSmO+Zakb8hj==C0XxPzBNeBJZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: BPJ @ 2019-02-07  0:13 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1992 bytes --]

You want  `[this](#title-b)`

Den ons 6 feb. 2019 22:01 skrev Alon Bar-Lev <alon.barlev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:

> Hi All,
>
> I need to find a solution of generate markdown to pdf.
> pandoc looks promising, however, I must be missing something.
>
> Let's take the following two files:
>
> a.md
> ---
> # Title A
>
> A content.
>
> See [this](b.md).
> ---
>
> b.md
> ---
> # Title B
>
> B content.
> ---
>
> Run:
> $ pandoc -o a.html --reference-links a.md b.md
> $ pandoc -o a.pdf --reference-links a.md b.md
>
> In both cases the link to B actually goes to the filesystem b.md
> instead of being a reference to the content of B within the document.
>
> Can this be worked out somehow with parameters? I could not find
> anything that made an impact.
>
> Thanks,
> Alon
>
> --
> 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/CAOazyz04jcRfqkGEkpb2FcBmjVJ7C%3D7cvSf-Tm1wKBWeCKEuoQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CADAJKhCnRDa%2BCWqntyPrvqfpSmO%2BZakb8hj%3D%3DC0XxPzBNeBJZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 3298 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [markdown] links between documents
       [not found]     ` <CADAJKhCnRDa+CWqntyPrvqfpSmO+Zakb8hj==C0XxPzBNeBJZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-02-07  6:26       ` Alon Bar-Lev
       [not found]         ` <CAOazyz2k3FYHaF4SjVX0agZDH=4ZSAKm6QYyTppVvaQymnbXJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Alon Bar-Lev @ 2019-02-07  6:26 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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.

On Thu, Feb 7, 2019 at 2:13 AM BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> You want  `[this](#title-b)`
>
> Den ons 6 feb. 2019 22:01 skrev Alon Bar-Lev <alon.barlev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
>>
>> Hi All,
>>
>> I need to find a solution of generate markdown to pdf.
>> pandoc looks promising, however, I must be missing something.
>>
>> Let's take the following two files:
>>
>> a.md
>> ---
>> # Title A
>>
>> A content.
>>
>> See [this](b.md).
>> ---
>>
>> b.md
>> ---
>> # Title B
>>
>> B content.
>> ---
>>
>> Run:
>> $ pandoc -o a.html --reference-links a.md b.md
>> $ pandoc -o a.pdf --reference-links a.md b.md
>>
>> In both cases the link to B actually goes to the filesystem b.md
>> instead of being a reference to the content of B within the document.
>>
>> Can this be worked out somehow with parameters? I could not find
>> anything that made an impact.
>>
>> Thanks,
>> Alon
>>
>> --
>> 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/CAOazyz04jcRfqkGEkpb2FcBmjVJ7C%3D7cvSf-Tm1wKBWeCKEuoQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/CADAJKhCnRDa%2BCWqntyPrvqfpSmO%2BZakb8hj%3D%3DC0XxPzBNeBJZQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [markdown] links between documents
       [not found]         ` <CAOazyz2k3FYHaF4SjVX0agZDH=4ZSAKm6QYyTppVvaQymnbXJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-02-07 20:18           ` BP Jonsson
       [not found]             ` <a2366d6c-8f01-2119-1c93-30404f689d25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: BP Jonsson @ 2019-02-07 20:18 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw, Alon Bar-Lev

[-- Attachment #1: Type: text/plain, Size: 4070 bytes --]

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.

[-- Attachment #2: pandoc-crossurls.lua.zip --]
[-- Type: application/zip, Size: 2607 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [markdown] links between documents
       [not found]             ` <a2366d6c-8f01-2119-1c93-30404f689d25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2019-02-08 16:35               ` Alon Bar-Lev
  0 siblings, 0 replies; 5+ messages in thread
From: Alon Bar-Lev @ 2019-02-08 16:35 UTC (permalink / raw)
  To: BP Jonsson; +Cc: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On Thu, Feb 7, 2019 at 10:18 PM BP Jonsson <bpjonsson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I have attached a filter which hopefully solves your problems.
>
> It seems to me you actually got two problems here:
>

Thank you so much! I thought that this kind of functionality should be
embedded in core, it is impressive that the filter mechanism supports
these activities.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-08 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 21:00 [markdown] links between documents Alon Bar-Lev
     [not found] ` <CAOazyz04jcRfqkGEkpb2FcBmjVJ7C=7cvSf-Tm1wKBWeCKEuoQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-07  0:13   ` BPJ
     [not found]     ` <CADAJKhCnRDa+CWqntyPrvqfpSmO+Zakb8hj==C0XxPzBNeBJZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-07  6:26       ` Alon Bar-Lev
     [not found]         ` <CAOazyz2k3FYHaF4SjVX0agZDH=4ZSAKm6QYyTppVvaQymnbXJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-07 20:18           ` BP Jonsson
     [not found]             ` <a2366d6c-8f01-2119-1c93-30404f689d25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-02-08 16:35               ` Alon Bar-Lev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).