Import markdown (or HTML) and see as formatted Scrivener word processor style in editor?

I’m a new user and trying to figure out whether a conceptually simple idea is possible: to take 50 or so existing markdown files (also available as HTML) and import them into Scrivener as formatted chapters. The markdown/html tags would be converted to Scrivener paragraph or character styles.

I don’t want to keep them as markdown nor edit them or otherwise write in markdown. The files are in that format because I have exported them from my blog. What I want to do is to edit them in Scrivener as the start of a compiled volume in native Scrivener format, as if I had written them from the beginning in Scrivener with styles applied.

I’ve tried copy/paste and importing .md and .html files, and what I get is raw text showing the markdown and html codes, without styles. Below is a short snippet that demonstrates the kind of formatting I have.

Existing discussions I have found so far here are about authoring markdown rather than importing it. Is there an option I am missing?

Thank you and apologies for the newbie question!

=== example markdown excerpt follows ===
[update: this example didn’t work LOL. The editor here automatically does the actual conversion that I want, showing styles instead of the markdown tags. That’s what I was hoping in the Scrivener editor.]

“I don’t have anything to present!” {#heading-i-dont-have-anything-to-present}

Ask yourself this question: what is something I learned in the past
two years, that I wish I had known before?
If you can answer that,
then you probably have a presentation that will interest others!

Want more specific ideas? Here are some ideas I would personally like
to see, off the top of my head:

  • A walkthrough of a favorite but little-known R (or Python) package

  • How to set up a local SQL server so you can learn SQL on
    your own

I’m no expert, but I’m pretty sure that Scrivener treats .md and .html files as text blocks, so that it never renders tags into styles.

If it were me, I’d export to .html and import into Word. I’d save it as an .rtf file. I’d import the .rtf file into Scrivener.

Others with far more experience with this sort of thing will no doubt jump in. :slight_smile:

1 Like

The best option is to use a Markdown tool, such as Pandoc or MultiMarkdown, to convert your files to RTF, DOCX or ODT, and then import those into Scrivener. That will give you the highest quality transfer with styled text (so long as you create styles in your project with the named styled they will be using), real footnotes, real comments, etc.

3 Likes

Just to be transparent, I’ve never tried the method I mentioned. Best to follow the advice from @AmberV .

2 Likes

HTML is all right if you don’t have anything better and can’t install software for some reason, but it will be a bit lossy in the sense that HTML doesn’t do everything rich text does. Markdown, very basic Markdown only does what HTML can do, yes, but it has come a long ways since then, and with these more sophisticated converters it can do many things (like footnotes and styles) that HTML can only simulate, and thus you’d be importing the simulation rather than the real deal.

If one can’t install a converter, or isn’t comfortable learning how to use it with the command line, at the very least I would drop all of the .md files verbatim into a temporary project, compile using the MultiMarkdown → ODT (which is embedded in the software, no installations necessary), and then import and split. You’d probably want to do a little setup with section layouts to get hierarchical headings, so that Import and Split can chunk the file back out into sections using its ability to do so with styled outlined headings.

And hey, maybe in doing that one will find it’s not so bad writing in Markdown in Scrivener and getting a good result from it. I would never willingly subject myself to the horror I see all around me that is the rich text life style, for any software. But that’s just me. :wink:

4 Likes

Thank you AmberV and SCN!

That helps a lot. I can use pandoc. An initial attempt is working on that path!

(Well, TBH it is partially working but the remainder is outside Scrivener. Pandoc only converts the first paragraph. But that problem is before the successful Scrivener import step; so I’ll explore whether it is a file format, pandoc option, and/or encoding issue. Will also try the ODT path that AmberV outlines. The solution above solves my primary question. Thanks again!)

1 Like

Agreed, that is another possibility. FWIW, I’ve written 1 published book entirely using markdown, and another before that in LaTeX. Just trying something different this round, mostly wanting to keep it simple as I learn Scrivener. Glad to know of the options! :folded_hands:

2 Likes

Okay, well if you have Pandoc installed then you’ll find Scrivener’s integration with it in the Compile For menu as well, and its DOCX output is probably a bit better than the MMD / ODT output.

As for why you’re only getting one line, I’m not sure about that. I know it handles CRLF as well as LF, so that common culprit shouldn’t be an issue. What was the note-taking program you were using?

1 Like

Short version: it’s all working now. Thank you for the right pointers to get there!

Specifically: I convert the HTML to ODT using pandoc; then import that ODT into Scrivener. It then appears with styles in the “word processor” format in the editor as desired.

As for the one line issue … it’s an extreme edge case, but just for for the record: My blog is exported from Hashnode (blog platform) to a JSON object that comprises all the 50 or so posts. I process that with custom code I wrote in R that extracts and saves individual HTML files. The single-paragraph-only issue turns out to be this: my code in R uses the “writeLines()” command, and by default that function adds an extra \n separator for each line written. That confuses pandoc. I changed it to call writeLines( ... , sep="") instead, which suppresses the extra newline. That solves it, and now pandoc converts the entire extracted HTML to ODT, and that in turn imports and shows with styles in Scrivener. So it all works, at least for now :folded_hands:) Hope this helps someone else down the road!

2 Likes

It sounds like you’re one step away from writing a Scrivener .scrivx XML writer and building a project generator from the blog. :wink:

Glad it’s all working well now.

4 Likes