Mapping Text Style To Custom CSS for EPUB output

I’ve been adding custom css code to my general templates so my basic formatting can be edited in the EPUB after the fact. It would be a great feature if you could associate a text style to a custom css code to transfer into the EPUB on generation.

To explain it better it would go as this:

Text Style Body Text = p3
Chapter Title = p1
Poetry = p5

A map table of sorts could be defined so when the EPUB is generated it could look up a custom setting for text styles and substitute the css into the stylesheet.css file.

At this time a separate stylesheet[#].css is generated for nearly every chapter compiled. This is intern has to be hand modified in Calibre (or some such app) to only use the one and true stylesheet.css file.

Unfortunately none of this is possible using the current systems in place in Scrivener 1.x (Win) and Scrivener 2.x (macOS). This is because Scrivener does not currently have a styles system, only a formatting presets system. When you apply a formatting preset to a paragraph in Scrivener, it’s just like applying a bunch of formatting - there is no semantic information associated with the paragraph, so Scrivener does not see the paragraph as a “block quote” or “body” paragraph, just a regular, generic paragraph. It’s therefore not possible to apply any specifically-named CSS styles to paragraphs.

Also, Scrivener for macOS currently uses Apple’s standard HTML(4) generator for creating HTML files. Apple’s code is responsible for generating the CSS and HTML, and it does so per-file.

The good news is that all of this will change with our next major (paid) update. As part of the next update, I spent a couple of months implementing a true styles system into Scrivener. I also spent several months overhauling Compile and implementing ePub 3.0/Kindle KF8 support that generates HTML5 using MMD under the hood, giving me more control. So, in the next paid update, you can apply styles to the text in the editor, and in Compile you can override those styles and assign them CSS names. Not only that, but you can choose to override the CSS style sheet (only a single sheet is generated rather than one-per-file) right inside Scrivener’s Compile area.

In short, everything you are asking for is coming with the next major update.

All the best,

I am so pleased that you are implementing styles for paragraphs and character ranges. I have developed a semantic style naming convention so that content can be round-tripped between Word, FrameMaker, and LibreOffice (via exported *.doc, *.docx, or *rtf files). For example I might have

bF_Body-first First body text paragraph in a passage. It may be fully blocked (i.e. first line [i]not[/i] indented, extra space above) bM_Body-middle Body text paragraph preceded and followed by other Body para styles. Most frequently used Body style. bL_Body-last Last body text paragraph in a passage. It may have extra space below. bO_Body-only Standalone body text paragraph, consituting an entire passage on its own. It may be fully blocked and have extra space above and below. That is, it combines the style attributes of bF_ and bL_ styles.

All three word processors allow one to type a key combination, start to type the style name, and as soon as enough letters are typed to identify and select the style, apply it to the text range.

All three word processors allow styles to be imported from style sheets, templates, or other documents and then applied to the current document. Imported styles completely overwrite those with the same name in the importing document. This means that semantic styles can be used for all kinds of documents – fiction, instructional, biography, etc. – and the appropriate stylesheet can replace the placeholder styles in the working draft.

Clearly, if the writer can apply placeholder semantic styles while developing content in Scrivener it saves an lot of tedium laboriously applying styles in an external word processor or layout application.

May I suggest that, instead of mapping key shortcuts to presets (styles), that you press something like Ctrl-Alt-Shift, then start typing the style name, and then press Enter when it is highlighted in a drop-down list. This means that when new semantic styles are created you do not have to go through the tedium of mapping them to key shortcuts and learning them. If you semantic styles are cleverly named, they are easy to remember and only two keyboard shortcuts need to be learned – opening the style list, and applying the selected style.

Keith, I cannot wait. This will be an incredible addition, thanks for implementing it!

I like this idea. I’ve added a keyboard shortcut that brings up a contextual menu showing all styles. You can then start typing the style name (or just hit the up/down arrows) and hit return to enter the style.

All the best,

Oh this is just super!!! A great idea and so quickly implemented… 8) 8) 8) My future self thanks you!

Completely off-topic, this kind of quick-find panel is useful for lots of other things. For example a great text editor, Sublime Text, makes fuzzy find (goto anything and command palette) its core universal UI feature, which won it many users. Though I’m sure this is whimsy, I’d love Scrivener to have a fuzzy goto/command like Sublime text.


I’m not sure if I’m following you here, but just in case you’re not aware… under Help there’s a search field, available to all Mac apps. You have to know a word or part of a word that is found in a menu item, but with that, you can find and even execute any menu item, including the View->Go To-> menu, which includes every binder item as well as every command in the menu which might match.

I don’t know where half of the menu items in Scrivener are because I find the Help search tool so handy. I just have to be familiar with the words that make up menu item names.

OMG FAKE!!! Too good to be true!!! :stuck_out_tongue:

rdale: yes, I use ⌘⇧/ to access that help menu>search often (I switch binder affects… often). The Fuzzy find / Command systems are exactly like help menu>search except they also work with functions not found in any menu, and can contain document fragments and other niceties. The coolest of these tools also learn from what you access most and weight their responses accordingly. The pinnacle of these types of interfaces IMO is Quicksilver, which takes this idea to the whole OS and uses a very powerful grammar to accomplish complex tasks effortlessly.