naturalcrit / homebrewery

Create authentic looking D&D homebrews using only markdown
https://homebrewery.naturalcrit.com
MIT License
1.09k stars 326 forks source link

insert page number snippet into every page #3060

Open ericscheid opened 1 year ago

ericscheid commented 1 year ago

Your idea:

Currently, an author needs to insert the page number snippet onto each page to have page numbers show up.

It would be cool if there was a snippet/command that would insert that snippet onto every page in one go (except any that already has it, and except any pages marked as cover pages or section pages).

A clever author could kinda do this with a find/replace for the text \page and a bit of manual cleanup

5e-Cleric commented 1 year ago

If every author came to a standard, we could have a simple input on the properties tab, and use that to know where to insert the auto page number snippet.

Ideally, we could have that, and people could still opt to use the manual snippet.

G-Ambatte commented 1 year ago

Possible solutions:

G-Ambatte commented 1 year ago

CSS for auto page numbers without having to {{pageNumber,auto}} every page using .page:before:

.page:before {
  content: counter(phb-page-numbers);
  position: absolute;
  right: 2px;
  bottom: 22px;
  width: 50px;
  font-size: .9em;
  color: var(--HB_Color_Footnotes);
  text-align: center;
  text-indent: 0;
}
.page:nth-child(even):before {
  left: 2px;
}

EDIT: Putting this in as a Style Editor snippet would have the widest possible compatibility.

G-Ambatte commented 1 year ago

Now that :has() is functional in Chrome, we could theoretically do things like this:

.pages:has(.autoNumberOn) .page:before {
  content: counter(phb-page-numbers);
  position: absolute;
  right: 2px;
  bottom: 22px;
  width: 50px;
  font-size: .9em;
  color: var(--HB_Color_Footnotes);
  text-align: center;
  text-indent: 0;
}
.pages:has(.autoNumberOn) .page:nth-child(even):before {
  left: 2px;
}

As long as there is an element within the .pages element somewhere that has the class autoNumberOn, then the automatic page numbering is applied.

Throwing CSS nesting into the mix:

.pages:has(.autoNumberOn) {
  .page {
    &:before {
      content: counter(phb-page-numbers);
      position: absolute;
      right: 2px;
      bottom: 22px;
      width: 50px;
      font-size: .9em;
      color: var(--HB_Color_Footnotes);
      text-align: center;
      text-indent: 0;
    }
    &:nth-child(even):before {
      left: 2px;
    }
  }
}

EDIT: These solutions have much narrower compatibility profiles.

ericscheid commented 1 year ago

Almost didn't notice you wrote .pages and not .page.

You'd still need a mechanism to turn off the page number for specific pages, such as any cover pages or section breaks, or any page set aside for full bleed images, etc.

So, maybe this?

.pages:has(.autoNumberOn) {
  .page:has(not.autoNumberOff) {
  ...
G-Ambatte commented 1 year ago
.page:has(.autoNumberOff):before {
   display: none;
}
G-Ambatte commented 1 year ago

Almost didn't notice you wrote .pages and not .page.

The nested CSS makes that kind of change a lot more obvious.

Gazook89 commented 1 year ago

In my opinion, the better solution is likely to create some sort of generator/js function to add the page numbers at a point-of-time when the user decides. Rather than rely on browser-limited CSS rules.

Some indicator on each page that you want a page number on them (or don't wnat a page number) which is then organized by a function and replaced with the correct markdown at the bottom of each page in the editor when the user clicks "create page numbers".

When we were setting up v3 we reserved the space on the \page lines so nothing could be on those lines. Now, we could we add new syntax for that line, like

\page #

Which would indicate a desired page number. The syntax could even be more robust. For example, the below syntax would indicate that the page should be numbered as page "1", and the numbering should continue from 1 on subsequent pages.

\page #1

As always, you can get more complicated. More syntax options:

\page # "Introduction | Setting"

// adds a page number and fills the Fancy Footer section with the quoted text.
\page # "$PART | $H2"

// adds a page number and fills the Fancy Footer with the text of the most recent Part snippet, followed by the most recent h2 element to the end of the page.

When a user wants to clear their page numbers to re-run the generation (or some other reason), another button can run a function that just clears everything on the new page lines after the \page.

ericscheid commented 1 year ago

For things that occur on multiple pages, repetitively, it might be prudent to consider using variables.

https://github.com/naturalcrit/homebrewery/discussions/1400

5e-Cleric commented 1 year ago

If i understand this correctly:

\page # would insert a page with auto numbering, \page # "Creating a character" would insert a page with auto numbering and that text as footer, \page #X would insert a page with manual number set of X, \page #X "Creating a character" would insert a page with manual number set of X and that text as footer.

Would that be correct?

Assuming i got that right, we might want to consider using #auto instead of #, to make it easier for users otherwise, this looks like a great idea, with no unnecesary syntax.