How do I compile epub without any tag-level styling?

When I compile epubs and then open it in Sigil, every paragraph is full of tag-level <p style="margin-right:3rem; text-indent: ridiculous; over-head:stupid"> stuff.

I end up overriding with the master css file and have to make sure I do it for every single combo/tag and have to use !important far more than I’d like. How do I compile so it’s not adding in all this extra formatting garbage at the local level? I just want clean html in the bulk of the files so I can control it all globally from the main css file instead of at tag-level. (I imagine this is inflating the file too).

This can happen under some specific conditions:

  • The Create styles for paragraphs using custom formatting setting is disabled. You actually do want that disabled, but it’s a necessary ingredient for it working the way you described, instead of putting these attributes into the CSS file, and then linking it to a serialised class name. You want neither, though, so I suppose it doesn’t matter too much which way this checkbox is set, since ideally you’ll want to avoid triggering the conditions it modifies.
  • Whether a paragraph ends up getting clobbered with inline formatting depends on the Section Layout settings, and whether they generate formatting that differs from the Default paragraph formatting you see in the top half of this pane, or whether they pass-thru formatting from the editor. So switch over to Section Layouts and go through all the boldface entries that generate text, making sure they are set to Text and notes use default paragraph formatting.

If they are supposed to use different formatting, I would recommend making sure the Layout has a unique CSS class name, over in the Settings tab. Then you can very simply and cleanly hierarchically establish the formatting for this based off the classed div that will be placed around the content, like: div.interlude p { font-style: italic; }.

Note for Windows users:
I’ll leave this in the Mac-only section, even though none of this is specific to how one uses a Mac. Mainly though, everything talked about above is sufficiently buggy or incomplete in Windows that there actually is no way to get clean output, and divs don’t wrap around sections you tell them to. If a Windows user comes across this need clean HTML, I just recommend installing Pandoc and using Scrivener’s integrated Pandoc → ePub compile type instead, with the rich text to Markdown conversion setting enabled in the compile settings.

That’s not a bad option for Mac users either, looking for something super clean and more modern/semantic in its internal architecture.

2 Likes

I found this plugin for Sigil that seems to work pretty fast to strip all the inline styles… one more step in the (already) long process from page to press though.

Sigil app for stripping style tags

I’m not sure what this means, that the settings did not work? If not, could you provide a short run-down on what conditions & settings it takes to see inline attributes being added to the HTML output?

As noted it can be clean, and even should be by default, unless you change how the starter “Ebook” compile format works (or I guess, not use it or assign types to the layouts it provides).

No, the settings did not work. I’d have to select everything apply “no style” to them in the editor… and even then, things like images would have styles applied to them. It was too much canceling out when this sigil add-on seems to more or less do the trick.

Hmm, something still does not sound right. If you apply an arbitrary style to text, then the expected result will be <p class="name-of-style">...</p> with .name-of-style { ... } added to the stylesheet.css file (and then that only happens if the checkbox I mentioned before is ticked, it is possible to reduce Scrivener’s output to the point where all you get is semantic classing and a completely empty .css file, if you want total control). I can’t think of any way for styled text to forget that it is styled, completely, and reduce to dumping raw inline CSS into the HTML element.

That aside, you wouldn’t be doing yourself much harm by cleaning out the unnecessary body paragraph styles from your source material anyway, since Scrivener’s “no style” is equivalent to using the “Normal” or “Body” paragraph style in a word processor. Using an actual style on the text just makes everything more difficult and complicated, with very few actual reasons to do it (since Section Layouts can apply styles to all unstyled text during compile).

The easiest way to nuke unnecessary body paragraph formatting is to simply delete it from the project though. One would not have to go through each item in the editor and apply no style by hand.

At any rate, I don’t know what your setup is like, and do not have nearly enough data to speculate. My only guess at the moment is you’ve hit some kind of bug, but I have no way of knowing where or how, either.

I would suggest creating a very small sample project that demonstrates the result. This could be done by using Save As to create a disposable copy, nuke everything in the binder except for one binder item in the Draft folder, nuke everything in there except for one paragraph (and maybe an image, since you describe very weird behaviour there as well that matches no intentional design path in the software I can think of). Feel free to send it in a DM to me, or to tech support.