Unexpected behavior in Compile Format Designer for EPUB3 and KF8/MOBI

User avatar
thomasalmy
Posts: 13
Joined: Tue Nov 21, 2017 11:50 pm
Platform: Mac
Location: Oregon, USA
Contact:

Wed Nov 29, 2017 2:37 am Post

I wanted to make the text in Code Blocks smaller. I created a new format based on E-book.
  1. If I go to Styles->Code Block and change the font to something smaller, what is displayed decreases in size, but there is no effect to the output.
  2. Instead, if I go to the CSS page, I can add

    Code: Select all

    code { font-size: 0.75rem; }
    to the custom stylesheet and get what I want, but I should be able to do this on the Styles page.
  3. I tried to add a second size of Code Block text by creating a new style based on Code Block. Now it obeys the decrease in size and used the correct font but is missing the <pre> tag so it doesn't work. I checked "Preserve Formatting" but that seems to be ignored.
  4. I got more adventurous and created a new character style called Tiny which should do nothing but make the font size small. However if I put that in a Code Block I get weird results as the span tags for tiny appear as literal text in the HTML: &lt;span class=&quot;tiny&quot;&gt; for example

None of this was ever an issue with the Scrivener 2 Compiler. (including using EPUB2 format in Scrivener 3)

User avatar
nontroppo
Posts: 755
Joined: Mon Mar 05, 2007 5:22 pm
Platform: Mac
Location: Airstrip One

Wed Nov 29, 2017 4:56 am Post

Scrivener 2 could not compile to EPub3 and did not have styles or the ability to customise the CSS, so it is hard to compare. You can still use EPub2 if you want, not sure if you are saying this also doesn't work? Anyway the output to EPub3 is much cleaner HTML and much more configurable, you just need to learn how to use it. Also it is worth emphasising that most EBook reader override the font styling anyway...

Now if you've read the User manual, I would agree the interactions of compile-styles and CSS for EPub3 are perhaps not clearly elaborated on ( EPub3 uses a Multimarkdown intermediate). Styles in the editor do not automatically convert to styles in the compiler, you must configure this manually. However if you use the default EBook compile format then the basic editor styles / compile styles and HTML element mapping is configured for you. See the "HTML elements" panel (§24.9 user manual) where you can assign which style gets linked to which special HTML element. By default this is mapped up to "Code Block", but if you import your special style you can map here.

Screen Shot 2017-11-29 at 11.48.42_SML.png
Screen Shot 2017-11-29 at 11.48.42_SML.png (14.2 KiB) Viewed 158 times


It is not clearly specified in the Styles compile settings section of the manual (§24.5), but the Styles Panel does not automatically edit the CSS as far as I can tell. So I would recommend you edit the CSS which should provide much more precise configuration, and is guaranteed to make it to the output.

There is another way to create code blocks (!), make a custom editor style (MMD Code Block), and in the editor you put the MMD prefix and suffix ```lang ... ``` (for lang you can select e.g. ruby) — in the compiler you import this style and click "Treat as raw markup", and this gets passed through to MMD and MMD creates the code block, though I'm not sure the syntax highlighting CSS gets through (Pandoc certainly can do this if you have it installed, Scrivener offers an EPub compile if you do)...

User avatar
thomasalmy
Posts: 13
Joined: Tue Nov 21, 2017 11:50 pm
Platform: Mac
Location: Oregon, USA
Contact:

Wed Nov 29, 2017 4:44 pm Post

nontroppo wrote:Scrivener 2 could not compile to EPub3 and did not have styles or the ability to customise the CSS, so it is hard to compare. You can still use EPub2 if you want, not sure if you are saying this also doesn't work? Anyway the output to EPub3 is much cleaner HTML and much more configurable, you just need to learn how to use it. Also it is worth emphasising that most EBook reader override the font styling anyway...


Admittedly so, but I seem to be getting more control with EPub2. I could stick with that, but I really want the advantages of the more recent standards. The only place I've been having problems is with monospaced fonts which I must be able to switch to and have had no problems (E-book or printed documents) until now.

Styles in the editor do not automatically convert to styles in the compiler, you must configure this manually. However if you use the default EBook compile format then the basic editor styles / compile styles and HTML element mapping is configured for you. See the "HTML elements" panel (§24.9 user manual) where you can assign which style gets linked to which special HTML element. By default this is mapped up to "Code Block", but if you import your special style you can map here.


This all I realize, which is why I'm talking about Compile Format Designer problems and not problems with styles per se. I hadn't paid attention to the HTML Elements panel, but now I have I see a problem with that. It allows setting each style to specific HTML. When I went to add a new style "Tiny Code Block" based on Code Block the <pre> and <code> were not added and there is no way on this panel to set Code blocks style to both Code Block and Tiny Code Block.

It is not clearly specified in the Styles compile settings section of the manual (§24.5), but the Styles Panel does not automatically edit the CSS as far as I can tell. So I would recommend you edit the CSS which should provide much more precise configuration, and is guaranteed to make it to the output.


When I add new styles, it does make additions to the CSS that show on the CSS panel Default Stylesheet. For instance the Tiny Code Block I added:
Screenshot_11_29_17__8_28_AM.jpg
Screenshot_11_29_17__8_28_AM.jpg (154.8 KiB) Viewed 128 times

gives me the CSS in the Default Stylesheet:

Code: Select all

.tiny-code-block { margin: 0rem 0% 0rem 3rem; text-indent: 0rem; font-family: monospace; font-size: 0.5rem; }

Carrying the correct font, font size, and indent. HOWEVER changes made to the Code Block style are not carried into the Default Stylesheet and must be added manually to the Custom Stylesheet. If these changes are not going to be carried over that should be either documented or, better yet, the controls to make the changes should be disabled. I'd certainly prefer that these these things be fixed rather than documented into a "works as intended".

There is another way to create code blocks (!), make a custom editor style (MMD Code Block), and in the editor you put the MMD prefix and suffix ```lang ... ``` (for lang you can select e.g. ruby) — in the compiler you import this style and click "Treat as raw markup", and this gets passed through to MMD and MMD creates the code block, though I'm not sure the syntax highlighting CSS gets through (Pandoc certainly can do this if you have it installed, Scrivener offers an EPub compile if you do)...


Please no! I'm just trying to do something that works for Epub2 and should for Epub3 and KF8. In Scrivener 2 I used Preserve Formatting which worked fine. In Scrivener 3 I can modify the Code Block style and those changes work for Epub2. I can add the Tiny Code Block style and that works as well for Epub2. I just expect that Scrivener 3 beta testers were not big users of code blocks and this feature of the new compiler was not sufficiently tested. All the bugs I've reported here are related to Code Blocks. Everything else has come across fine from Scrivener 2.

User avatar
KB
Site Admin
Posts: 19198
Joined: Tue Jun 13, 2006 11:23 pm
Platform: Mac
Location: Truro, Cornwall
Contact:

Mon Dec 04, 2017 11:37 am Post

The reason for this is that when a style is chosen as a code block, Scrivener just uses some default CSS for it that works well with code blocks - specifically:

Code: Select all

pre > code {  white-space: pre-wrap; -webkit-hyphens: none; hyphens: none; }


It thus ignores the other style settings for code blocks, otherwise code may not turn out so nicely.

For the next update, I have updated this code so that it does include the font size if specified, however.

All the best,
Keith
"You can't waltz in here, use my toaster, and start spouting universal truths without qualification."