Specify Scrivener styles for imported documents?

Is there any way to tell Scrivener how to map styles of an imported document to the styles of the current project?

I’m importing a document with many code blocks into a Scrivener project which has a Code Block style and many existing code blocks that use it. But I can’t get the newly imported document to use this style. The best I can do is have the new code blocks become No Style with a monospace font format. I can probably find them one by one and manually apply the “Code Block” style, but I have hundreds.

I’m assuming anyone importing a styled document has similar issues, what is the workflow for this?

I’ve tried lots of import formats including markdown and html.

There is this at least — If you drop a Word doc into your Draft/Manuscript folder in Scriv, any assigned Word styles that name-match style names in your Scriv project will be preserved, i.e. those text spans will be assigned the like-named Scriv style. Nice.

(You can also have style assignments preserved when compiling to Word, and get the reverse correspondence.)

But I know of no workflow where you could make your own custom, arbitrary mapping of Word styles to Scriv styles or vice versa.

gr

The style name is the only method Scrivener has for identifying a style in incoming text.

If the Code Block style exists in the Scrivener project and in the imported document, Scrivener should apply the assignment correctly. If it doesn’t, that’s a bug.

If, on the other hand, the Scrivener project calls them Code Blocks and the imported document calls them Code Examples, these are different styles and will not automatically map to each other. The fix is to rename one of the two so that they match.

I have spent 3 days on this, and am losing the will to live
I have two approaches that almost work

If I import as docx
I can now get the styles to match (thanks gr), but Scrivener doesn’t import the table correctly even though the table looks fine in MS Word.
E.g. this markdown file:

### Tables

You can create tables by assembling a list of words and dividing them with hyphens `-` (for the first row), and then separating each column with a pipe `|`:


First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column

If I save it as minExample.md and convert it to docx with pandoc

pandoc   -t docx -s -o minExample.docx minExample.md 

I get a file minExample.docx that looks fine in MS Word, but the table format is broken when I drop minExample.docx into scrivener (it ends up with one column instead of two)

If I import markdown directly with Scrivener "Import and split"
The table imports fine, but now I have the original problem of code not being recognised: all sections of code arrive as No Style text

I can see why you are having some trouble figuring a workflow — as your source documents appear to be an unholy mix of paragraph styling and markdown. :face_with_raised_eyebrow:

I have quite a lot of flexibility in how I format the import document(s).

Originally they’re Markdown, but because the simple approach hasn’t worked I’ve tried going through intermediate formats. In the last week I’ve learned a lot about how to turn Markdown into docx, html, rtf, you name it.

I love Scrivener, and I’m probably trying harder than is logical, to bring these Markdown documents into Scrivener rich text.

I see, so it is now down to this new problem with table import.

I don’t have much idea on that. I guess in your shoes I would probably build a simple example table in Word and save as rtf. Assuming this goes in without breaking, it might be useful to compare the rtf code for that to the rtf that is coming out of your processing of the markdown table.

Also, if memory serves, Scriv has two different import routines it can use for doc import — one third-party, one in-house. At some point the in-house routine pretty much outstripped the 3rd party routine. You might check your Scriv prefs to see which import routine your installation is set to use. (Not at my mac, so hope I am not just spouting antiquated know-how.)

Just to summarise, I have two Scrivener bugs to report:

  1. “Import and Split” for markdown doesn’t convert markdown Code Blocks, nor Block Quotes
  2. Import of Word docx format doesn’t get tables right

Update: the MS Word table problem looks like it’s due to an older docx format.

If I open the docx that pandoc creates in Word, it opens in “compatibility mode”.
If I resave the file and answer “Y” when Word asks to update the format it then imports ok into Scrivener. So I have a workaround, and this isn’t really a Scrivener bug.

The first issue with Scrivener’s Markdown import remains, however.