* Automatically generated a blog (inline) table of contents from Markdown
@ 2019-04-19 23:57 Patrick Kenny
[not found] ` <9183d4df-7db3-4867-88a3-9340b778932f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Kenny @ 2019-04-19 23:57 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1565 bytes --]
I have some blog posts written in Markdown that have a structure like this:
* H1 (post title)
* H2 - intro
* H2 - table of contents
* H2 - random content A
* H2 - random content B
* H2 - random content C
And so forth. In the table of contents, I want to automatically generate
an unordered list that has internal links to random content A, B, C, and so
on.
I see that in Pandoc itself, you can link to a title with the title as the
anchor:
# Random content A
[link](#Random content A)
But, in my case, these links need to ultimately be HTML instead of Markdown
because the blog posts are going to a website that can only process
Commonmark or PHP Markdown, neither of which (as far as I can tell) support
a Markdown version of internal links.
To summarize:
My goal is to automatically generate an unordered list that contains HTML
internal links to all the h2 elements that follow the second h2 element in
the document.
What approach would you suggest for implementing this?
--
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/9183d4df-7db3-4867-88a3-9340b778932f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2259 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Automatically generated a blog (inline) table of contents from Markdown
[not found] ` <9183d4df-7db3-4867-88a3-9340b778932f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-04-20 20:41 ` Kolen Cheung
[not found] ` <6e7c6cb0-76c8-4146-abc8-f6f921e05916-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Kolen Cheung @ 2019-04-20 20:41 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]
You could write a pandoc filter to get the links. If you use python then try looking at Panflute on GitHub for its user guide.
To generate the markdown in other markdowns, you can use pandoc -t ... option, both markdown you mentioned are supported. See pandoc Manual for details. It will try to represent feature not present in the target markdown by its closest representation (sometimes HTML, or in the case of footnote a “pseudo” footnote that looks like a footnote.) You should try to see if it works in your case though.
If it doesn’t work than in the filter you may add custom ID per header you need and then create links to those directly.
--
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/6e7c6cb0-76c8-4146-abc8-f6f921e05916%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Automatically generated a blog (inline) table of contents from Markdown
[not found] ` <6e7c6cb0-76c8-4146-abc8-f6f921e05916-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-04-23 1:23 ` Patrick Kenny
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Kenny @ 2019-04-23 1:23 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2310 bytes --]
Thanks to your suggestion, I set up Panflute and found an example in the
documentation for generating a table of contents:
http://scorreia.com/software/panflute/guide.html#globals-and-backmatter
Unfortunately, I don't know very much about Python, and I ran into some
trouble modifying the example. I was trying to add markdown to generate an
internal link.
item = ListItem(Plain(*elem.content))
doc.toc.content.append(item)
What I wanted to do is to modify elem.content (the heading that will be
displayed in the table of contents) by adding markdown so that it becomes
an internal link. I tried to treat it is a string, but that didn't work
because it is a list container.
How can I treat the list container into a string? I found that if I can
convert the list container into a string, I can modify it and send it back
like this:
item = ListItem(Plain(Str('[Introduction][#introduction]')))
On Sunday, April 21, 2019 at 5:41:16 AM UTC+9, Kolen Cheung wrote:
>
> You could write a pandoc filter to get the links. If you use python then
> try looking at Panflute on GitHub for its user guide.
>
> To generate the markdown in other markdowns, you can use pandoc -t ...
> option, both markdown you mentioned are supported. See pandoc Manual for
> details. It will try to represent feature not present in the target
> markdown by its closest representation (sometimes HTML, or in the case of
> footnote a “pseudo” footnote that looks like a footnote.) You should try to
> see if it works in your case though.
>
> If it doesn’t work than in the filter you may add custom ID per header you
> need and then create links to those directly.
--
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/4b52e6cb-df57-4436-97b3-49351cc1300d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 5486 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-23 1:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-19 23:57 Automatically generated a blog (inline) table of contents from Markdown Patrick Kenny
[not found] ` <9183d4df-7db3-4867-88a3-9340b778932f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-04-20 20:41 ` Kolen Cheung
[not found] ` <6e7c6cb0-76c8-4146-abc8-f6f921e05916-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-04-23 1:23 ` Patrick Kenny
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).