It would be helpful for my workflow if I could have MultiMarkdown compilation escape special characters in my documents (where I can apply formatting directly) but not in anything added during compile (e.g. separators with raw markup in them). Is there a way to set Scrivener to do this?
If you can make a minimal test project and specify your output targets it will be easier to help, given the range of possible options during compile (like you have enabled escaping due to wanting to convert RTF?). In general you can âprotectâ content using raw_attributes so for example:
This is proteted `\myblah()`{=latex} for latex outputs
Sorry if I wasnât clear. I convert the rich text in my Files to markdown for post-processing, and want to escape any âspecial charactersâ in those Files, but I also want to include raw markup in things like Styles prefixes and suffixes. Maybe Iâm going about this the wrong way, but for example, I want to put a string around BLOCK QUOTE-ed text that I can postprocess later, and I donât want those characters escaped, but I do want similar characters in the Files escaped. Is there a way to âprotectâ text in the Style Prefix/Suffix fields from the " Convert Rich Text to Markdown options" â âEscape Special Charactersâ option?
In general, I never use âConvert RichtextâŠâ for exactly these reasons, it devolves into a complex set of when things are escaped or not. Styles can replace all RTF use, and then you donât need to worry about escapingâŠ
Anyway, lets say you have âConvert richtextâŠâ ON and âEscape special charactersâ ON â the following simulated scrivener text has a smallcaps style attached to âCUPCAKEâ (which for output will be converted to [Cupcake]{.smallcaps}
) and RTF italic on âipsum dolor.â
CUPCAKE ipsum dolor.
This causes the problem you specify when compiled, the style markdown gets escaped:
\[Cupcake\]\{.smallcaps\} *ipsum dolor*
So the RTF was correctly converted BUT the style markdown was escaped, this is your problem?
If you turn ON âTreat as rawâ for that style then compile generates this:
[Cupcake]{.smallcaps} *ipsum dolor*.
So now both the style markdown and the converted markdown should render fine. Separators donât seem to be escaped so markdown is left untouched AFAICT.
Could you expand on this? It sounds like my problem might be that Iâm using the wrong tool for this jobâŠ
Well, for what or why are you using RTF direct formatting?
Only a specific set of things will translate from RTF to markdown anyway, and all of those things can be better handled by Scrivenerâs styles. My suggestion is turn Convert richtextâŠ
OFF, and where you have been using RTF direct formatting, make a style. You can even bind âb and âi to apply the style rather than bold or italic direct formatting. Now you donât need to worry about escaping, and you get the flexibility that if you want bold to be represented by small capitals, just reassign the style rule in the compilerâŠ
The problem with just using Styles is that I do have literal symbols like *
s in my text that need escaping to \*
. Otherwise I could just turn âEscape Special Charactersâ off completely. However, with âEscape Special Charactersâ turned on, my ~~
strike-through syntax becomes \~\~
.
Maybe the easiest option is to just put the escapes directly in the text and turn off âEscape Special Charactersâ. Itâs not pretty but if thereâs no easy way to protect text in the Styles field from escapement it would be a simple fix.
Why not use styles for escapes? The style can add the \
as required. Also your strike through could be a style too, that way you have no pollution of markup peppering your text, styles provide the semantic âcontainersâ to provide your intent. This way, say you want to compile to another output, there are no escape or markdown specific characters peppering your work. This âseparation of concernsâ gets you clean text with a flexible path to output what you needâŠ
Maybe I explained it badly, but it sounds like youâre trying to explain how to do the reverse process that I actually want. I have a strike-through style defined to prefix/suffix ~~
around the struck-through text, so struck becomes ~~struck~~
just like bold and italics become **bold**
and *italics*
. The problem is that I want to have text like aster*sk render to ~~aster\*sk~~
, when I can only get Scrivener to output either ~~aster*sk~~
or \~\~aster\*sk\~\~
.
Ah, well then one solution is to live with the escapes in the text (only use styles for your markdown):
In this case a strike-through style is applied with the escaped \*
as plain text. Iâve also added an emphasis and strong style just to show how you can make your text âlookâ like RTF. This compiles to:
Muffin ~~dan\*ish~~ chocolate *soufflé* pastry icing bonbon **oat cake**.
So now styles will replace all markdown, and escapes are explicit. If compile replacements could be made to optionally run before styles were transformed, we could take benefit of replacements to escape the asterisks, but at least on macOS they run after styles and so regex replacements also operate on any injected markdown. There may be some other tweaks that could be performed.