Yes, you can do both of these things with Scrivener, though there are some platform differences to be aware of.
On the Mac: go into the Sharing: Import preferences pane, and in the âPlain Textâ section, note the file extension list on the right. Add â.htmlâ, â.htmâ or whatever else you need here.
This will override the normal behaviour, where dropping HTML files into the binder will either archive them (using MHT or WebArchive) or convert them to editable formatted text. Neither is what you want.
On Windows: this option hasnât been added yet, so normal import is off the table. Youâll need to copy and paste from a plain-text editor to bring raw HTML into the editor. That of course works on the Mac as wellâmaybe you donât want to change that setting so you can continue archiving pages normally, well thatâs how youâd get both.
So that gets the syntax into the editor, but in order for that to remain HTML through compile, you need to tell Scrivener thatâs what you want. For all it knows you are writing about HTML and want it to print verbatim. To achieve that we need to use styles. First, letâs explore how that works.
Open File ⸠Compile..., set the Compile for option at the top to ePub, and select the âEbookâ compile Format in the left sidebar.
Double-click on it to duplicate and edit, and click on the Styles pane. Scrolling through that list youâll find two prepared styles: âRaw HTMLâ and âRaw HTML Blockâ. One is for inline snippets of raw syntax, the other for whole chunks, as you would expect. Click on these, and note they are both set to use the Treat as raw markup flag. Thatâs the special sauce, you can apply that to any style you want.
We know what we need to know for now, make a mental note of these style names, and feel free to cancel out of this dialogue and Opt/Alt click on the âCompileâ button to just save your changes to the file type and format.
Back in the editor, select the syntax youâve imported (one way or another), and use the Format ⸠Styles ⸠New Style from Selection... menu command. The formatting and settings are completely arbitrary, do what works best for you, it will all be ignored completely, for obvious reasons. The only thing that matters is using one of the style names, depending on whether it is paragraph or character level.
Now as to your second question, yes you can insert text from .html files on the fly, using the placeholder documented in §10.1.5, Including Text From Other Documents, in the user manual PDF. If you intend to compile from multiple platforms, itâll work best to keep the .html files in the same folder as the project, so you that you avoid having to give a full path, which will of course be completely different between Win/Mac.
However, I wouldnât depend on that approach right now, as both platforms have bugs that relate to this feature that effectively make it not useful for inserting raw syntax.
Thank you Amber for the help, however I must have done something incorrect as the HTML now showing as text. At this time I am on a Mac (Intel), Catalina 10.15.7 if that matters.
I got as far as âBack in the editorâ when things became fuzzy. I did create a New Style called HTML, the styles talked about from #2 do NOT show up here. There is no shortcut, formatting is Save all formatting with both checked boxes. I have Highlight box checked with a color and Next Style is None. I have a folder called Code Blocks and have a text document there with the below code and Styled with HTML. In the Manuscript I have a document with <$Include:TestCodeBlock>. When I recompile using the copied called âEbook with HTMLâ the code is now showing as text instead of raw html to be rendered.
Below is the raw HTML I would like to insert, hope you like Animatics . Could you either provide more step by step like you did in the beginning (prefered) or a sample document that has the changes you described with the changes pointed out. Just to be clear the below HTML should not have any changes, just inserted.
I did create a New Style called HTML, the styles talked about from #2 do NOT show up here.
I may not be following, but as noted in the the original instructions: âThe only thing that matters is using one of the style names, depending on whether it is paragraph or character level.â And to clarify, since this is taken out of context, one of the style names refers to the list of styles in the compile format.
You say they donât show up here, but Iâm not sure what that is in reference to. They wouldnât be in the project itself until you create them, so that would be expected. If they arenât in the compile format, thatâs why I recommended starting with the stock âEbookâ compile format.
So for a large block of HTML like this you want a paragraph style called âRaw HTML Blockâ. Calling it âHTMLâ isnât going to do anything. Just redefine it and rename it to âRaw HTML Blockââor go into the compile formatâs Styles pane and renamed âRaw HTML Blockâ to âHTMLâ. Either way serves the same purpose.
One last thing to be aware of is that when you insert text using the <$include:âŚ> placeholder, it uses the styles from the source text. So you do want to apply the âRaw HTML Blockâ style to the TestCodeBlock itemâs text, rather than applying it to the placeholder itself at the point of insertion. It sounds like that is what you are doing, but doing things the other way around is one way in which the HTML would end up escaped and printing as visible text.
Also, linking documents with the extension .htm or .html when compiled show the <$include:whatfile.html> not the contents. I tried changing to .txt and it worked. Am I missing something?
Okay, yes I see what is going on here. Internally and during the compile process Scrivener uses MultiMarkdown to generate the HTML, but that detail should be largely invisible to you. In this case it is causing a problem though, because when you use the raw markup flag on a style, it passes the text through verbatim into the internal Markdown file used for processing. So that means three things:
These lines youâve got that have an amount of indenting applied to them end up being interpreted as code blocks, because prefixing a line with at least four spaces or one tab is how you mark code blocks in Markdown.
The empty lines would mark the boundaries of these code blocks, as empty lines are how you separate block level elements.
The line starting with a â#â character is interpreted as a heading.
So to the first problem, youâll do best by removing the indenting, or at least making sure that the first line is at the beginning of the line. Indenting HTML in Markdown is okay, but only so long as there are no empty lines within the range, where the next line starts off indented. So for example:
<div>
<p>This is fine...</p>
<p>This is the first line of a new code block</p>
</div> <!-- This is outside of the code block. -->
The line starting with a â#â could be resolved by just moving it up to the previous line.
As for whether itâs truly a bug. I donât know if thatâs right to sayâitâs nice to be able to use Markdown to generate HTML if you want. Itâs something worth better documenting though, as I donât think that is mentioned anywhere.
Thank you very much for the explanation. Now that I know I would be able to massage the HTML. It does disturb me though since the HTML is marked as Raw HTML Block. To me this would be a literal copy of the RAW HTML Block and not process that code at all, but that is my opinion and I have no idea how the software is coded.