jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.21k stars 3.36k forks source link

Mandatory `--section-divs` behaviour with revealjs #9592

Open multimeric opened 6 months ago

multimeric commented 6 months ago

Explain the problem. Consider the following markdown document. Here, we have an HTML class we want to apply to the title of the slide, but not to the content.

# Title {.my-title-class}

Here is some content

However, when running pandoc -i test.md --to revealjs on this document, we get the following. Note how my-title-class is attached to the <section> as well as the <h1>, which is not what we wanted:

<section id="title" class="slide level1 my-title-class">
<h1 class="my-title-class">Title</h1>
<p>Here is some content</p>
</section>

Compare this to the standard HTML behaviour. pandoc -i test.md --to html gives us the following, which is correct because only the <h1> has the class:

<h1 class="my-title-class" id="title">Title</h1>
<p>Here is some content</p>

But now, if we add --section-divs, we get something suspiciously similar to the revealjs result:

<section id="title" class="level1 my-title-class">
<h1 class="my-title-class">Title</h1>
<p>Here is some content</p>
</section>

Consequently, I wonder if there is a mandatory --section-divs behaviour with revealjs, which in my case is very irritating, because I don't want the class applied this way. It's possible that this is necessary because of how revealjs expects its HTML markup, and if that is the case, I would love to be able to have a flag that enables section-divs, but without copying the header classes onto the sections!

Pandoc version?

pandoc 3.1.12.1
Features: +server +lua
Scripting engine: Lua 5.4
macOS: 12.6
jgm commented 6 months ago

I wonder if there is a mandatory --section-divs behaviour with revealjs,

Yes, because revealjs requires these sections.

jgm commented 6 months ago

I do understand that this behavior is problematic for some uses (e.g. applying tailwind css classes). However, other people rely on it; when I reverted it at one point, it caused problems. See https://github.com/jgm/pandoc/issues/5975 and especially https://github.com/jgm/pandoc/issues/5965

multimeric commented 6 months ago

Thanks for the background.

Could we have a --copy-header-attribs false type flag to make this opt out without breaking existing behaviour?

jgm commented 6 months ago

In principle this is possible, but it's an ugly solution. This would mean you wouldn't get any attributes on the section, not even an identifier. In revealjs many features of slides are controlled by attributes on the section element, so you'd lose the ability to use any of these.

multimeric commented 6 months ago

Okay, how about a --manual-slides flag which disables all the automatic slide splitting (by headings, and by ---), and disables the --section-divs behaviour, and instead requires the user to use a ::: Slide class to distinguish each slide? Then they can add attributes to the heading using # Title {.my-title-class}, and attributes to the slide using ::: {.slide .my-section-class}.

As someone who wants control rather than convenience for this particular use case, I think this would be great.