jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.45k stars 3.37k forks source link

Feature: secnumdepth support for ePub #3552

Open dbader opened 7 years ago

dbader commented 7 years ago

Thanks so much for the great tool. Pandoc is a core part of my ebook workflow now and it's absolutely fantastic. I've been recommending it left and right πŸ™‚

Here's a feature I'd like to suggest:

Currently, the secnumdepth variable for limiting the numbering depth on sections will only affect LaTeX and PDF output.

It would be great if the same (or a similar) setting was made available for ePub files.

Right now ePub files generated with Pandoc (1.19.2.1) include section numbers at least up to level 5.

For example, the following Markdown input:

## Heading 2

lorem ipsum

### Heading 3

lorem ipsum

#### Heading 4

lorem ipsum

##### Heading 5

lorem ipsum

...leads to this result in the ePub export (all section levels are numbered)

screenshot 2017-04-03 08 18 05

I'd love to be able to control section numbering in the ePub output as well.

For example, in my use case I'd like to hide section numbers past level 2. For my LaTeX and PDF exports I'm setting secnumdepth: 1 and that gets me the desired result. But this only works for LaTeX and PDF files.

Thanks for considering it!


jgm commented 7 years ago

Yes, I think we should make this more of a first-class citizen, with an option --secnum-depth that works in all writers, like --toc-depth.

jgm commented 7 years ago

As a workaround, just add this sort of thing to your CSS:

h3 > span.header-section-number { display: none; }
dbader commented 7 years ago

Thanks John, the workaround does exactly what I was looking for. I'll use that for now.

nybblr commented 5 years ago

Similar situation β€” I'm generating a PDF where only parts ("modules") and chapters are numbered, everything else isn't. Level 1 headers are part ("Module II"), Level 2 headers are chapters ("Chapter 5"). Now I'm trying to replicate the effect for the EPUB version.

The CSS workaround can hide the numbers on the headers, but doesn't help with the Table of Contents. The chapter numbering also starts off as "1.1" because of the module grouping, as opposed to the more bookish style of picking up numbering from the previous module.

I wrote a filter to throw the .unnumbered class on every heading below h2 which fixes the table of contents issue:

#!/usr/bin/env node
const pandoc = require('pandoc-filter');
const { Header } = pandoc;

const CHAPTER_LEVEL = 2;

let action = async (type, value, format, meta) => {
  if (type === 'Header') {
    let [level, [id, classes, keys], text] = value;

    if (level > CHAPTER_LEVEL) {
      classes = [...classes, 'unnumbered'];
    }

    return Header(level, [id, classes, keys], text);
  }
};

pandoc.stdioAsync(action);

But I'm not sure of a good way to tackle the custom numbering style of Roman numerals for modules and chapter numbering β€” if I curmudgeon it in a filter by modifying the actual header text, is that going to interfere with the internal numbering system and cross linking?

jgm commented 5 years ago

Have you tried suppressing the section numbers in the TOC using CSS, as well? It should be possible. E.g. to suppress level-3 numbers:

nav#TOC > ul > li > ul > li > ul > li > a > span.toc-section-number { display: none; }
jgm commented 5 years ago

In response to your other question: Changing the numbering should not affect internal cross-linking, since the identifiers don't include the numbers. Try it.

nybblr commented 5 years ago

@jgm ^^ Good point. I didn't, I went ahead and suppressed them with the filter β€” seemed less likely to break since the unnumbered class works magic.

Good to hear, fingers crossed! If it doesn't have weird side effects, it sounds like a good filter recipe ("Custom Numbering Schemes") β€” preferred place to submit those?

jgm commented 5 years ago

preferred place to submit those?

pandoc/lua-filters on github