'&' produces epub errors when adding prefix/suffix to style

Because I keep chopping and changing my mind about how to format written text like signs or mobile texts within my manuscript I have set up a character style that then changes them according to my latest whim when I compile to epub (my preferred format for reading through and editing away from my desktop).

Today I added curly quote marks around them using the prefix/suffix section of the compile>edit format>styles section, using ‘ALT+0145’ & ‘ALT+0146’.

I have two instances of the ‘&’ symbol within this style and they now both produce errors when compiling to ePub. Sigil gives me the following error:
xmlParseEntityRef: noname

I noticed the & is showing as ‘&’ within this style instead of ‘&#38’ in other instances.

The problem is solved by using & instead of ‘&’.

Is this a bug or do I need to type something different in the prefix/suffix boxes to ensure the compile works properly?

I am not quite sure what you mean when you say that “I have two instances of the ‘&’ symbol within this style”. Do you mean that the text you are styling in this way contains ampersands within it: something like “Crosse & Blackwell make pickles”, for example?

I think you are running into the fact that XML (and XHTML, which epub 2 uses) regard the ampersand as a reserved character used to start the declaration of XML entities. This is not a bug in Scrivener but a limitation of XML.

I would need to understand what you are actually doing a bit more before I could suggest a workaround. The usual approach would be to replace the ampersands in the text with & but that may not suit your purposes.

1 Like

I’m also having difficulty seeing this problem. I have modified the “Emphasis” style so that it inserts a typographic left and right single quote around the marked text, in the prefix and suffix fields, and then marked a couple of bits of text, one being just a solitary ampersand by itself. This is the HTML I get:

Ma er ma ‘<span class="emphasis">jince ma rintax ma</span>’ wex ux wynlarce. Xu, zeuhl lydran ux erk. Sernag epp anu er cree ik korsa groum rintax velar ozlint velar thung vo korsa berot ‘<span class="emphasis">&#38;</span>’ menardis er arul.

Are there any other settings I would need to change? Here’s all I did:

  1. Duplicated and edited the “Ebook” compile format.
  2. Added a character style called “Emphasis” to the Styles pane and removed italics from it.
  3. Added and to the prefix and suffix fields, respectively.

Yep. I have ‘F&B Manager’ and ‘Cocktail Bar & Restaurant’ within this style.

I set up my own style instead of using Emphasis, added a highlight colour to it in the editor but yes that’s what I did. But I also had ‘Treat as raw markup’ option ticked. I’m an idiot, sorry! :roll_eyes:

Oh! Yup that’ll do it. :slight_smile: It expects everything in that range to be valid HTML so that you can inject your own custom syntax.

Thanks! I have another problem now though. Paragraphs that contain this style no longer have an indent on the first line.

Hmm, yeah I am seeing that as well. It’s a bit of a compound problem in that normal paragraphs shouldn’t even be marked as having special formatting in the first place. But it looks like using a character style with a prefix/suffix anywhere in a paragraph changes the whole paragraph’s formatting. So this is a problem on top of a problem.

Unfortunately I don’t see an elegant way around it sort of saving the fix for one of the very last steps, and then going through any place where this style is used, and fixing the “ps2” (or whatever automatically generated number gets assigned) CSS in an ebook editor. I say leave it for last, because those numbers can change depending on the order in which formatting occurs.

If I think of a better solution I’ll let you know.

2 Likes