Export with partial HTML tags

Ed
EddieEdwards
Posts: 3
Joined: Wed Nov 15, 2017 2:37 pm
Platform: Windows

Wed Nov 15, 2017 3:31 pm Post

Hi,

I consider myself a bit of a n00b with Scrivener, even though I have used it for over a year now :) So perhaps this feature exists already, but I cannot find it.

What I need to do is export a document mostly as plain text, with empty lines for paragraphs, but I want to have HTML tags to represent the parts of my text which are italic and bold.

This is how many older document entry systems work on the internet, where they try to "hide" the HTML nature but still allow you to use certain HTML tags if you wish.

I spent a little time in the export section but I do find it quite confusing. Is there any preset for this or is there a way to make Scrivener do it out of the box? Otherwise, could I request this as a feature?

JJ
JJSlote
Posts: 419
Joined: Tue Oct 26, 2010 5:44 pm
Platform: Windows
Location: NY, USA              Docs in Binder: 9800+

Wed Nov 15, 2017 8:06 pm Post

For copying into a WordPress comment box, for example! I actually wrote an AutoHotKey script to do this, starting from the HTML markup we can obtain from the Copy Special command. Kinda like ungrinding sausage. Sorry, too complicated and fragile to share.

Scriv's Copy as BBCode is similar in its objective, but it's buggy and we've heard it'll be removed from Version 3.

Rgds - Jerome

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

Thu Nov 16, 2017 1:07 am Post

Scrivener 3 will allow you to use styles (e.g. strong and emphasis, but any style can be set up) and these can be transformed into whichever HTML tags you would want, which should flexibly solve your problem. 8)

Ed
EddieEdwards
Posts: 3
Joined: Wed Nov 15, 2017 2:37 pm
Platform: Windows

Thu Nov 16, 2017 9:39 am Post

Thanks for the replies.

Jerome, I know a little Python, so I may investigate that Copy Special thing. Thanks for the hint.

Look forward to version 3 :)

JJ
JJSlote
Posts: 419
Joined: Tue Oct 26, 2010 5:44 pm
Platform: Windows
Location: NY, USA              Docs in Binder: 9800+

Thu Nov 16, 2017 3:30 pm Post

Styles in Scriv 3 will enable the user to designate a stretch of text a Blockquote and have it processed as a Blockquote all the way through to the Epub, irrespective of the formatting instructions used to achieve that effect within the editor. And we'll be able to make our own styles based on any RTF formatting we'd like to reuse by name.

But there's no evidence we'll be able to use those styles to structure our own HTML output. We might make our own (redundant) style called Bold. But Scriv would still determine whether that style is implemented as <b> or as <span style="font-weight:600;">. It's not natively an HTML editor built to give us that level of control.

And in fact a global style requires doing away with inline formatting instructions, so the HTML generated thereby would probably be more like <span class="ScrivUserStyleBold;">. Sure, "Bold" lives on in the name in our example, but the implementation of the format would reside in a stylesheet suited to the destination medium. This styling by external reference is a generation removed from the "street" HTML used in WordPress comments.

Keith did blog that Scriv3 uses MultiMarkdown as the bridge format, upon Compile, between the RTF maintained by the editor, and the HTML5 required by EPub3. If we're fortunate enough to have that MultiMarkdown rendition also available on Copy Special and on Export Files, it will become much easier to generate our own light variety of HTML from a Scrivener doc.

Rgds - Jerome

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

Fri Nov 17, 2017 1:56 am Post

JJSlote wrote:But there's no evidence we'll be able to use those styles to structure our own HTML output.


Any style can be replaced with prefix and suffix. This means for a large class of HTML tags, we can simply add the opening and closing markup for that. So as a concrete example, I create an inline style called "Strong Emphasis", and in the compile settings I add PREFIX=<strong><em> and SUFFIX=</em></strong> then compile will perform this arbitrary style⇨markup conversion. Yo can even rebind ⌘B and ⌘I so they use your custom styles instead of the RTF bold/italic. We will even be able to add complex HTML markup for comment annotations, as we now can identify the comment and the selection seperately. So for example you can convert a Scrivener comment into a <span class="comment" title="COMMENT TEXT">SELECTED TEXT</span>. I use this system to allow me to use Scrivener paragraph and inline styles for all of my writing, yet they are all accurately transformed in to Pandoc flavoured markdown.

Personally, I would use MMD/Pandoc to generate HTML, but we do now have the ability to create a powerful custom HTML generator using style transformation! 8)

Ed
EddieEdwards
Posts: 3
Joined: Wed Nov 15, 2017 2:37 pm
Platform: Windows

Fri Nov 17, 2017 9:26 am Post

Well I created a solution, thanks to JJSlote's hint.

I compile the story to HTML instead of TXT, and then I run the enclosed Python script, giving the HTML file as the command-line parameter. It writes the corresponding TXT file. Only works for <i> so far but extending it for bold, underline etc. should be easy enough.

Scriv's HTML output is extremely verbose. The script works by parsing the style attribute and searching for font-style:italic. That's basically it, apart from a small HTML parser that tracks <p> and <span> and handles <br>.

That's me happy for now so thanks for everybody's help!

Convert.txt
Python script to strip HTML down
(3.04 KiB) Downloaded 14 times

JJ
JJSlote
Posts: 419
Joined: Tue Oct 26, 2010 5:44 pm
Platform: Windows
Location: NY, USA              Docs in Binder: 9800+

Fri Nov 17, 2017 9:53 pm Post

nontroppo wrote:Personally, I would use MMD/Pandoc to generate HTML, but we do now have the ability to create a powerful custom HTML generator using style transformation! 8)
Well, there's the evidence! Great digging; appreciate the V3 preview, nontroppo.

Rgds - Jerome