Export to Multimarkdown and to Word

Am
Amafortas
Posts: 30
Joined: Wed Dec 24, 2008 4:08 pm

Tue Nov 21, 2017 8:49 pm Post

Hi,
I'm using the styles in Scrivener 3 to denote heading levels and was wondering if there is a way to export or compile to a Multimarkdown file that preserves the header levels.

Otherwise, is there a way to export or compile a file to a Word document and strip out setting for font face and size that I've set up in Scrivener? I want to preserve the styles, but that's it.

Cheers,

Amafortas
Macbook Pro -- 2.8Ghz, 4GBRam, 320 GB @ 7,200 RPM

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

Wed Nov 22, 2017 1:35 am Post

If you use MMD there is no need to explicitly define heading styles in Scrivener: binder levels are converted to Markdown Heading levels (denoted but 1-6 #), which get converted to Word Heading1-6 automatically. [url-http://pandoc.org/]Pandoc[/url] is much better at generating a well formed word document directly from Scrivener's MMD compile. MMD is a plain text format, and so style data is always stripped out, leaving the semantic structure alone (block quotes, figures, emphasis etc), allowing you flexibility in the final output.

If you don't want to use MMD, then you must use the style mapping in compile. Keith did not want to add heading styles as a default on DOCX compile, and so you must create Heading 1-6 styles and map them using a custom compile format manually. Personally I find MMD+Pandoc a much more flexible route. The other major advantage of Pandoc is you can create a "blank" Word document with your preferred styles, page layout etc, and you pass this to pandoc and it will extract the style and page metadata and apply it to your new document. This means no fiddling in Word afterwards...

User avatar
gr
Posts: 1593
Joined: Wed Feb 14, 2007 3:57 am
Platform: Mac + iOS
Location: Florida

Wed Nov 22, 2017 3:35 am Post

If you create styles in Scrivener with precisely the same style names as Word's Heading styles, when you compile to Word, the styling of paragraphs set in those styles will be controlled by Word's heading styles (b/c the style assignment is carried over into the Word environment).

gr
gr : Scrivener user : not affiliated with Lit^Lat

"Perhaps the true book is the one on the far side of the prism."

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

Wed Nov 22, 2017 4:18 am Post

@gr: the slight caveat being if you generate titles from the Binder names you cannot directly style these in the editor; they must be assigned by using section types in the compiler.

Am
Amafortas
Posts: 30
Joined: Wed Dec 24, 2008 4:08 pm

Wed Nov 22, 2017 5:35 pm Post

Thank you, nontropo for your advice about PanDoc.
I'm working with assignments for a class, so I don't want to use binder for heading structure. For instance, I'm writing about 30 discussion board posts, and I'd like each to be self-contained. (Perhaps I'm pushing Scrivener in directions it is not supposed to go.)

I'm not wedded to MMD files. I just need something that will preserve HTML structure so that I can create 508 compliant content for my classes.

Would your solution, or some variation of it, work?

Cheers,
Amafortas
Macbook Pro -- 2.8Ghz, 4GBRam, 320 GB @ 7,200 RPM

User avatar
AmberV
Posts: 20608
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Wed Nov 22, 2017 7:59 pm Post

You can use styles for MMD style headings, that’s no problem from Scrivener’s point of view. I agree with Nontroppo, typically speaking it would be better to use sections and types to handle structural decisions like that, but if the documents are quite short and there is no need to break them up, then styles make a good bridge.

The trick is to go into the Styles compile format pane and create a matching heading style (by name), and use those Prefix/Suffix options to bake MMD hashmarks into any instance of text using the style. I’ve attached a very simple demonstration. You’ll see some junk text that when compiled will acquire Markdown-style heading syntax on those styled headings in the editor. To see how it works:

  1. Load up File/Compile...
  2. Double-click on the “MultiMarkdown with Styled Headings” compile format.
  3. Go to the Styles format compile pane.
Now take a look at the Heading 1 – 4 styles, in particular the prefix/suffix settings to the right (you can for the most part ignore the formatting editor with MMD).

If you want to use that format as starting point in your project:

  1. Flip the Save to option at the top of the format designer window to “My Formats”
  2. Click Save. Now it is yours.
Perhaps I’m pushing Scrivener in directions it is not supposed to go

I would say you are doing just fine. :)
Attachments
17326867-scriv-mmd_as_headings.zip
(20.99 KiB) Downloaded 11 times
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Am
Amafortas
Posts: 30
Joined: Wed Dec 24, 2008 4:08 pm

Thu Nov 23, 2017 3:35 pm Post

Hi AmberV,

Thank you for the style template. It solves almost all of the challenges I was having. The two that remain are lists and hyperlinks. The lists are being tabbed indented, so they are in a block quote format in Multmarkdown. (This is just an aesthetic problem.)

The other problem is the hyperlinks which are losing their linkiness after the conversion. The text is still there, but it is no longer a link.

Is there an easy fix?

And to go back to the Word export, is there a way to keep the styles but strip out any formatting? In other words, I don't want any special formatting to be passed through to Word. At the moment, my Word documents are picking up the formats from Scrivener.

Cheers,
Paul K.
Macbook Pro -- 2.8Ghz, 4GBRam, 320 GB @ 7,200 RPM

User avatar
AmberV
Posts: 20608
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Thu Nov 23, 2017 5:06 pm Post

Well there are two options you could take here, both are in the gear tab of compile overview with a Markdown-based file type selected:
  • Convert rich text to MultiMarkdown: that does almost everything, including links. That may be too much though, seeing as how you’re wanting to strip out most formatting.
  • Convert tables and lists to MultiMarkdown: this is a setting I’ve been using myself for a bit in some things. I don’t use it for everything because those bullets aren’t as nice when you just want to copy and paste rather than fully compile. But, if you are compiling then they can be a nice alternative to typing in the numbers and asterisks yourself.
So if you want just links and lists, there isn’t a good option for you. You should use Markdown syntax for links I think, given what you want.

And to go back to the Word export, is there a way to keep the styles but strip out any formatting? In other words, I don’t want any special formatting to be passed through to Word. At the moment, my Word documents are picking up the formats from Scrivener.

You mean outside of the context of Markdown stuff? Because that shouldn’t be happening (unless you have that first checkbox I mentioned ticked). But if you mean can you strip out all formatting from the stock .docx format—not easily. Pretty much the entire kit is built around the notion that people are going to want to keep their italics, etc. The best I can think of off of the top of my head would be to override the font to something that only has a regular variant, like Inconsolata.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Am
Amafortas
Posts: 30
Joined: Wed Dec 24, 2008 4:08 pm

Wed Dec 06, 2017 3:14 pm Post

Hi,
When I compile for output, I'm getting an odd character the \ at the beginning of each set of hash tags to create a heading. So, for instance, I'm seeing a

Code: Select all

\##Heading 2 ##.
Is there a way to remove the leading character
Cheers,
Ama
Macbook Pro -- 2.8Ghz, 4GBRam, 320 GB @ 7,200 RPM

User avatar
AmberV
Posts: 20608
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Wed Dec 06, 2017 10:29 pm Post

The example project I posted doesn’t seem to be doing that out of the .zip, it must be a setting you’ve changed—I’d walk back through those to see what might be the cause.

As a guess, you might have rich text to MMD conversion enabled, which presumes you are using rich text, not MMD headings. You can override that assumption by ticking the Treat as raw markup checkbox for these styles in the Styles pane.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

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

Wed Dec 06, 2017 11:14 pm Post

AmberV: "Rich text to Markdown" seems to escape markdown symbols here as well:

viewtopic.php?p=245261#p245261

I'm not quite sure why this has to happen, it seems like this setting should target the rich text, not unset any existing markdown content (or special Scrivener features like the captions which happen to use a markdown-like symbol)?

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

Thu Dec 07, 2017 9:39 am Post

There was an update to Scrivener for iOS today where the escaping of # with convert to markdown for plain text was considered a bug, I assume that means this is to?

User avatar
AmberV
Posts: 20608
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Thu Dec 07, 2017 2:26 pm Post

Because the setting is primarily meant for those wishing to use the Markdown compile options secondarily; where one might be using the native ePub 3 or PDF output for some things, they might also want LaTeX or DocBook without having to modify their entire source document to do so. In cases such as that, one would most likely not be paying attention to special Markdown characters, and any usage of them should be considered verbatim. So all punctuation that might be used to form markup is escaped. If you want to number your paragraphs with #1, #2 then you can do so.

Meanwhile it is easier to escape a character that should be escaped in a Markdown sense. For example if I want to literally print an HTML element like <this>, then I would escape the lesser-than sign to avoid it being interpreted as HTML, like \<this>. You wouldn’t want to do that with the native PDF. Hence you can type the element in bare and compile to PDF fine, then switch over to DocBook and have your text properly escaped to print as typed there as well. Going in the other direction would be more awkward.

For those cases, like the above, where you really do mean to use Markdown then that is what the aforementioned Treat as raw markup setting is for. You might also want to hide text styled as raw Markdown in your PDF, which would also be easy to do with styles on a per format basis.

There was an update to Scrivener for iOS today where the escaping of # with convert to markdown for plain text was considered a bug, I assume that means this is to?

That’s different, but an important distinction worth noting. In that case Scrivener for iOS was escaping its own automatically generated Markdown, in this case the product of the heading switch right above it. You will note that the macOS compiler does not escape its own automatically generated syntax—such as images, headings via Layouts and anything in the MultiMarkdown|Pandoc Options compile pane. It only escapes what we ourselves input.

The above solution is a case of text being entered via our input in that technically speaking, that’s not Scrivener generated Markdown—that’s us telling Scrivener to generate Markdown around a style. It treats style prefix/suffix text as text we have entered ourselves—and escapes it.

So, moral of the story: if you use a mechanism of the compiler to generate Markdown in an otherwise RTF document with the RTF->MMD conversion process enabled, make sure to instruct the compiler to treat it as markup.

As to your linked forum thread specifically—the use of Markdown captions in conjunction with compile settings designed for non-Markdown users to make use of the Markdown workflow—that might not be something we can fix? I’ll see if it is possible since it does make a certain sense, it being a Scrivener feature for captioning, but it’s worth noting that isn’t a global Scrivener feature for captioning—only for Markdown, and hence if you used your source to print a PDF then you would end up with bare brackets—thus Scrivener presuming that is your intention, and is trying to preserve it by escaping them. :)

It strives to generate a Markdown text that matches the content when printed via PDF. I’ve added a note to clear this up a bit in the manual.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles