Strange Code Block formatting and character problem upgrading to Scrivener 3, EPUB and MOBI

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

Mon Nov 27, 2017 9:28 pm Post

First, let me show what the output should look like and does in Scrivener 2. As shown in Kindle Previewer 3:
50_image.jpg
50_image.jpg (42.54 KiB) Viewed 211 times

This was with Monaco 10pt and "Keep Formatting".
In Scrivener 3, I made a test project with the same text + formatting as in Scrivener 2, a second copy using the Code Span style, and a third using the Code Block Style:
47_image.jpg
47_image.jpg (114.89 KiB) Viewed 211 times

If I compile to EPUB 3, I get the following (viewed in iBooks):
48_image.jpg
48_image.jpg (159.6 KiB) Viewed 211 times

Note that in the embedded case that Monaco 10pt was not used (easy to see not fixed width font), first line of underscores becomes a solid line, some lines have been unexpectedly indented, and multiple spaces have been collapsed into single spaces, So I fail to get portability from Scrivener 2. For the Code Span and Code Block case I get the correct font but backslashes have been inserted before most underscores. Note that Code Span inserts one more backslash than Code Block does. Code Span removes consecutive spaces and does an unexpected indent. Code block, which should indent, doesn't.

If I compile to MOBI (Kindle KF8) and view in Kindle Previewer I get (continued in next post, there seems to be a three image limit.)...

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

Mon Nov 27, 2017 9:33 pm Post

Compiling to Kindle KF8 MOBI I get:
49_image.jpg
49_image.jpg (165.05 KiB) Viewed 208 times


In this case the fixed width font isn't used at all, even for the Code Span and Block.

I'm running on macOS Sierra 10.12.6 with the latest (downloaded today) Kindlegen, Kindle Previewer 3, and iBooks.

User avatar
Bridey
Posts: 173
Joined: Wed Nov 22, 2017 2:24 pm
Platform: Mac

Mon Nov 27, 2017 9:45 pm Post

Have you styled the text as required by ePub3 and KF8?

ePub3%20HTML%20Styles.png
ePub3%20HTML%20Styles.png (114.74 KiB) Viewed 204 times

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

Mon Nov 27, 2017 11:58 pm Post

I used the "E-Book" format. But upon further investigation I determined there are several sources of the problems I'm seeing:
  • My fault - I can't do this with the code span style because I lose the extra space characters. I'll accept this. It is interesting that if I Compile to HTML, proper spacing is maintained, but that seems to be a feature in the HTML generator which is different (Scrivener) code than for generating E-Books.
  • Kindle Previewer fault and perhaps Scrivener fault as well -- doesn't display monospaced fonts processed from Scrivener 3 (it does from Scrivener 2). If I view the output in the Kindle application (for Mac) the monospace font is used. Also works on a Kindle paperwhite.
  • Scrivener fault -- the horizontal rule and inserted backslashes. These show up in the HTML source output

Here's the pertinent part of the generated xhtml file:

Code: Select all

<div class="section">
<p style="text-indent: 0em">EMBEDDED MONACO 10PT:</p>

<hr />

<p>|_|_|_|_|_|_|_|_|_|_|_|_|</p>

<p>| | | | |</p>

<p>| op |i|z| addr |</p>
<p class="br"><br /></p>
<p style="text-indent: 0em">As Code Span:</p>

<p><code>_ _ _ _ _ _ _ _ _ _ _ \_</code></p>

<p><code>|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|</code></p>

<p><code>|     | | |             |</code></p>

<p><code>|  op |i|z|    addr     |</code></p>
<p class="br"><br /></p>
<p style="text-indent: 0em">As Code Block:</p>

<pre><code> _ _ _ _ _ _ _ _ _ _ _ _
|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|\_|
|     | | |             |
|  op |i|z|    addr     |
</code></pre>
<p style="text-indent: 0em">No style.</p>
<p class="br"><br /></p>
</div>


Scrivener 2 generated this for the Preserve Formatting:

Code: Select all

<p class="p6"><span class="s2"><span class="Apple-converted-space"> </span>_ _ _ _ _ _ _ _ _ _ _ _</span></p>
<p class="p6"><span class="s2">|_|_|_|_|_|_|_|_|_|_|_|_|</span></p>
<p class="p6"><span class="s2">| <span class="Apple-converted-space">    </span>| | | <span class="Apple-converted-space">            </span>|</span></p>
<p class="p6"><span class="s2">|<span class="Apple-converted-space">  </span>op |i|z|<span class="Apple-converted-space">    </span>addr <span class="Apple-converted-space">    </span>|</span></p>

Class p6 sets the monospaced font. Note that nothing like this is done in the Scrivener 3 output for the first "Preserve Formatting" case.

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

Tue Nov 28, 2017 5:02 pm Post

I discovered that underscore followed by any character other than an underscore or space becomes a backslash followed by an underscore when used in a Code Block or Code Span.

I must add to the bullet list of bugs. Some I forgot, others new after doing more investigation. Basically "Preserve Formatting" does nothing for the new EPUB and MOBI formats.
  • I forgot that I don't get monospaced font when I use "Preserve Formatting" in the first section (Embedded Monaco 10pt). This is when I carry over the text from Scrivener 2. If this worked then at least I could get by without having to make any changes. If I compile Epub 2 it all does work, but I guess I lose the advantages of the new Scrivener 3 compiler.
  • I tried "Preserve Formatting" around the Code Span. It makes no difference. Why doesn't it add the <pre> tag?

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

Mon Dec 04, 2017 11:39 am Post

On the last two: monospace fonts will only be added for styles when using ePub 3. Preserve Formatting will not preserve monospace fonts - you must use styles for this.

You need to use the Code Block style (the style set as the "Code blocks style" in the Compile settings) to get the <pre> tag inserted around a block. (Code Span is for code inside a paragraph.)
"You can't waltz in here, use my toaster, and start spouting universal truths without qualification."

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

Mon Dec 04, 2017 12:09 pm Post

The bug with underscores being incorrectly escaped in code blocks is fixed for the next update.

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

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

Tue Dec 05, 2017 6:15 pm Post

KB wrote:The bug with underscores being incorrectly escaped in code blocks is fixed for the next update.


Keith,

Is this somehow related to Markdown? Is it trying to do some Markdown conversion even though I don't use it and haven't checked the boxes?

In the example I show in the first post in this thread, the very first sequence of underscores got converted to a horizontal rule. It seemed to take this as a Markdown command. This was in the text carried over from Scrivener 2 where I did a "code block" by setting the font and marking the text as "Preserve Formatting."