public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* table of content with headers inside divs
@ 2022-02-02 13:47 christophe dervieux
       [not found] ` <a8b4c757-0182-473d-ae9b-e0ab2271b234n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: christophe dervieux @ 2022-02-02 13:47 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1342 bytes --]



Hello, 

I am trying to understand if this is a bug or not. 

I found several old issues on Github where it seems it was not possible at 
the time to have some headers inside Fenced Divs to be in the TOC. However, 
I seems to have been fixed. 

This is working for example 

# External 

::: custom
## Internal

content
:::

End of document

When rendered to HTML with Pandoc, H2 header “Internal” is inside the TOC. 

However, as long as there is other header of the same level inside the divs 
it won’t be in the TOC anymore

# External 

::: custom
## Internal

content
## Internal 2

content
:::

End of document

Is this not supported to have several headers like inside a divs ? Because 
of difficulty to know the hierarchy for sure ? 

Is the behavior behind the table-of-content document somewhere ? I can’t 
say if this is a bug or a feature. 

Thank you
​

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a8b4c757-0182-473d-ae9b-e0ab2271b234n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5903 bytes --]

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

* Re: table of content with headers inside divs
       [not found] ` <a8b4c757-0182-473d-ae9b-e0ab2271b234n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-02 18:25   ` John MacFarlane
       [not found]     ` <m2v8xxcei5.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2022-02-02 18:25 UTC (permalink / raw)
  To: christophe dervieux, pandoc-discuss


What target format?

With HTML, I don't see either header in the div becoming
part of the TOC.

```
% pandoc --toc -s
# External

::: custom
## Internal

content

## Internal 2

content
:::

end
^D
...snip...
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#external">External</a></li>
</ul>
</nav>
<h1 id="external">External</h1>
<div class="custom">
<h2 id="internal">Internal</h2>
<p>content</p>
<h2 id="internal-2">Internal 2</h2>
<p>content</p>
</div>
<p>end</p>
</body>
</html>
```



christophe dervieux <christophe.dervieux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Hello, 
>
> I am trying to understand if this is a bug or not. 
>
> I found several old issues on Github where it seems it was not possible at 
> the time to have some headers inside Fenced Divs to be in the TOC. However, 
> I seems to have been fixed. 
>
> This is working for example 
>
> # External 
>
> ::: custom
> ## Internal
>
> content
> :::
>
> End of document
>
> When rendered to HTML with Pandoc, H2 header “Internal” is inside the TOC. 
>
> However, as long as there is other header of the same level inside the divs 
> it won’t be in the TOC anymore
>
> # External 
>
> ::: custom
> ## Internal
>
> content
> ## Internal 2
>
> content
> :::
>
> End of document
>
> Is this not supported to have several headers like inside a divs ? Because 
> of difficulty to know the hierarchy for sure ? 
>
> Is the behavior behind the table-of-content document somewhere ? I can’t 
> say if this is a bug or a feature. 
>
> Thank you
> ​
>
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a8b4c757-0182-473d-ae9b-e0ab2271b234n%40googlegroups.com.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2v8xxcei5.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net.


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

* Re: table of content with headers inside divs
       [not found]     ` <m2v8xxcei5.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
@ 2022-02-02 18:44       ` BPJ
  2022-02-03  9:21       ` christophe dervieux
  1 sibling, 0 replies; 5+ messages in thread
From: BPJ @ 2022-02-02 18:44 UTC (permalink / raw)
  To: pandoc-discuss

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

I used to have a Perl filter which could build a (HTML) ToC even if the
headings were inside divs by simply ignoring the divs, and number the
headings both in the document and in the ToC.  Maybe now that Lua filters
can work top down it might be possible to create such a filter in Lua (or
in my case probably MoonScript which is then compiled to Lua).

Den ons 2 feb. 2022 19:26John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> skrev:

>
> What target format?
>
> With HTML, I don't see either header in the div becoming
> part of the TOC.
>
> ```
> % pandoc --toc -s
> # External
>
> ::: custom
> ## Internal
>
> content
>
> ## Internal 2
>
> content
> :::
>
> end
> ^D
> ...snip...
> <nav id="TOC" role="doc-toc">
> <ul>
> <li><a href="#external">External</a></li>
> </ul>
> </nav>
> <h1 id="external">External</h1>
> <div class="custom">
> <h2 id="internal">Internal</h2>
> <p>content</p>
> <h2 id="internal-2">Internal 2</h2>
> <p>content</p>
> </div>
> <p>end</p>
> </body>
> </html>
> ```
>
>
>
> christophe dervieux <christophe.dervieux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > Hello,
> >
> > I am trying to understand if this is a bug or not.
> >
> > I found several old issues on Github where it seems it was not possible
> at
> > the time to have some headers inside Fenced Divs to be in the TOC.
> However,
> > I seems to have been fixed.
> >
> > This is working for example
> >
> > # External
> >
> > ::: custom
> > ## Internal
> >
> > content
> > :::
> >
> > End of document
> >
> > When rendered to HTML with Pandoc, H2 header “Internal” is inside the
> TOC.
> >
> > However, as long as there is other header of the same level inside the
> divs
> > it won’t be in the TOC anymore
> >
> > # External
> >
> > ::: custom
> > ## Internal
> >
> > content
> > ## Internal 2
> >
> > content
> > :::
> >
> > End of document
> >
> > Is this not supported to have several headers like inside a divs ?
> Because
> > of difficulty to know the hierarchy for sure ?
> >
> > Is the behavior behind the table-of-content document somewhere ? I can’t
> > say if this is a bug or a feature.
> >
> > Thank you
> > ​
> >
> > --
> > 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/a8b4c757-0182-473d-ae9b-e0ab2271b234n%40googlegroups.com
> .
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/m2v8xxcei5.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net
> .
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhCUCNM5vK7aiWKbkLttweHa3tgLpgb%3DDbW4Tf_fEQ7upw%40mail.gmail.com.

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

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

* Re: table of content with headers inside divs
       [not found]     ` <m2v8xxcei5.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
  2022-02-02 18:44       ` BPJ
@ 2022-02-03  9:21       ` christophe dervieux
       [not found]         ` <f11c2921-244e-4833-a325-7a417c904853n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: christophe dervieux @ 2022-02-03  9:21 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3329 bytes --]

The output is HTML. You do see the header in the div if there is only one.
```powershell
❯ pandoc --toc -s
# External

::: custom

## Internal

content
:::

End of document
^Z
...snip...
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#external">External</a>
<ul>
<li><a href="#internal">Internal</a></li>
</ul></li>
</ul>
</nav>
<h1 id="external">External</h1>
<section id="internal" class="custom">
<h2>Internal</h2>
<p>content</p>
</section>
<p>End of document</p>
</body>
</html>
```

That is why I wonder why several create different behavior.

Le mercredi 2 février 2022 à 19:26:07 UTC+1, John MacFarlane a écrit :

>
> What target format?
>
> With HTML, I don't see either header in the div becoming
> part of the TOC.
>
> ```
> % pandoc --toc -s
> # External
>
> ::: custom
> ## Internal
>
> content
>
> ## Internal 2
>
> content
> :::
>
> end
> ^D
> ...snip...
> <nav id="TOC" role="doc-toc">
> <ul>
> <li><a href="#external">External</a></li>
> </ul>
> </nav>
> <h1 id="external">External</h1>
> <div class="custom">
> <h2 id="internal">Internal</h2>
> <p>content</p>
> <h2 id="internal-2">Internal 2</h2>
> <p>content</p>
> </div>
> <p>end</p>
> </body>
> </html>
> ```
>
>
>
> christophe dervieux <christoph...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > Hello, 
> >
> > I am trying to understand if this is a bug or not. 
> >
> > I found several old issues on Github where it seems it was not possible 
> at 
> > the time to have some headers inside Fenced Divs to be in the TOC. 
> However, 
> > I seems to have been fixed. 
> >
> > This is working for example 
> >
> > # External 
> >
> > ::: custom
> > ## Internal
> >
> > content
> > :::
> >
> > End of document
> >
> > When rendered to HTML with Pandoc, H2 header “Internal” is inside the 
> TOC. 
> >
> > However, as long as there is other header of the same level inside the 
> divs 
> > it won’t be in the TOC anymore
> >
> > # External 
> >
> > ::: custom
> > ## Internal
> >
> > content
> > ## Internal 2
> >
> > content
> > :::
> >
> > End of document
> >
> > Is this not supported to have several headers like inside a divs ? 
> Because 
> > of difficulty to know the hierarchy for sure ? 
> >
> > Is the behavior behind the table-of-content document somewhere ? I can’t 
> > say if this is a bug or a feature. 
> >
> > Thank you
> > ​
> >
> > -- 
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/a8b4c757-0182-473d-ae9b-e0ab2271b234n%40googlegroups.com
> .
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f11c2921-244e-4833-a325-7a417c904853n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5089 bytes --]

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

* Re: table of content with headers inside divs
       [not found]         ` <f11c2921-244e-4833-a325-7a417c904853n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-03  9:29           ` Albert Krewinkel
  0 siblings, 0 replies; 5+ messages in thread
From: Albert Krewinkel @ 2022-02-03  9:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: christophe dervieux

For what it's worth: I rewrote (most of) pandoc's TOC generator in Lua
for a different project. One can use this and unwrap the Divs before
generating the TOC, as done below. Not particularly efficient, but
should get the job done.

``` lua
_ENV = pandoc

local not_empty = function (x) return #x > 0 end
local section_to_toc_item

local function to_toc_item (number, text, id, subcontents)
  if number then
    text = Span({Str(number),Space()} .. text, {class='toc-section-number'})
  end
  local header_link = id == '' and text or Link(text, '#' .. id)
  local subitems = subcontents:map(section_to_toc_item):filter(not_empty)
  return List{Plain{header_link}} ..
      (#subitems == 0 and {} or {BulletList(subitems)})
end

section_to_toc_item = function (div)
  -- bail if this is not a section wrapper
  if div.t ~= 'Div' or not div.content[1] or div.content[1].t ~= 'Header' then
    return {}
  end
  local heading = div.content:remove(1)
  local number = heading.attributes.number
  -- bail if this is not supposed to be included in the toc
  if not number and heading.classes:includes 'unlisted' then
    return {}
  end

  return to_toc_item(number, heading.content, div.identifier, div.content)
end

-- return filter
return {
  { Pandoc = function (doc)
      -- avoid problems with headings nested below divs:
      local blocks_no_divs = doc.blocks:walk{
        Div = function (x) return x.content end
      }
      local sections = utils.make_sections(true, nil, blocks_no_divs)
      local toc_items = sections:map(section_to_toc_item):filter(not_empty)
      doc.meta['table-of-contents'] = {BulletList(toc_items)}
      doc.meta.toc = doc.meta['table-of-contents']
      return doc
    end
  },
}
```



-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

end of thread, other threads:[~2022-02-03  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 13:47 table of content with headers inside divs christophe dervieux
     [not found] ` <a8b4c757-0182-473d-ae9b-e0ab2271b234n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-02 18:25   ` John MacFarlane
     [not found]     ` <m2v8xxcei5.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
2022-02-02 18:44       ` BPJ
2022-02-03  9:21       ` christophe dervieux
     [not found]         ` <f11c2921-244e-4833-a325-7a417c904853n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-03  9:29           ` Albert Krewinkel

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).