Drafts Mac and IOS are great but the conversion from Markdown to other formats is tedious. Even Pandoc is not that great because I must export from IOS (Mac cannot export) a Draft → text mode → copy to Scrivener and format in Scrivener, which slows down workflow tremendously.
I was wondering if it would be possible to use regex to convert Draft → copy content (Cmd-A) → process the clipboard as per below → which I would paste into Scrivener
normal text converted (which I think originally is Menlo) converted to Arial regular 13
sentence in Markdown starting with # (Header) converted to Scrivener Heading Arial Bold 18
sentence in Markdown contained between 2 sets of ** ** converted to Arial 13 Bold (Cmd-B)
sentence in Markdown contained between 2 sets of * * converted to Arial 13 Italics (Cmd-I)
thanks very much for your time and help
example (Markdown and Screenshot). Ironically when I copy paste the draft content into this forum post, the preview ... looks like what I am aiming for
this is the title
testing normal font
testing normal again
This is what the text looks like in Drafts
Since I don't have the apps you mention, Scrivener, Markdown, Pandoc, Menlo, etc., I may not be able to get a solution for you because the solution may involve sending keystrokes to those apps. And the main reason for doing the conversion outside of KM is that KM doesn't support bold and italic. See Simply, can a variable paste formatted ie. BOLD text? But don't let that worry you, if an app can convert text to bold and italic, KM can send key sequences to make that happen. In most apps you can select text and convert to bold with CMD-B, for example.
Would you be satisfied if I showed you a macro that solves this problem by sending the desired output to the macOS Notes app? Sending it to Notes would allow the macro to have it converted to the styles you want. Is that sufficient?
Would this be a fair rewording of your question: "I have a set of text lines in a KM variable named TextSource. I want to create a note in macOS Notes using the font Arial which is created by: (a) converting all lines starting with "#" to Bold size 18; (b) converting all lines surrounded by "**" to Bold size 13; (c) converting all lines surrounded by "*" to Italic size 13; (d) all other lines should be size 13." This would be easy. Is this an acceptable interpretation of your question?
If you only have one sentence in each line formatted in one of those different ways, you can do something like this (demonstrated with TextEdit, since I still don't have Scrivener 3):
Convert Drafts Markdown to Formatted Text Per Line.kmmacros (18.1 KB)
But it's also not especially fast, and I can't see a good/easy way to have KM only apply styles to Markdown-formatted strings in the middle of otherwise plain text. If this is only an occasional need and your drafts are formatted one line per sentence like in your example, then this macro should work in a pinch, but otherwise, finding a way to use Pandoc (it looks to me like Drafts can export on the Mac just fine?
or an app like Marked 2 is probably the way to go.
I guess I was wrong this time. How did I miss that bold/italic option? I did read the documentation and the wiki, and I saw that post from Peter saying there is no bold/italic option. He mentioned an action called Insert Styled Text but I saw no such action, I presumed it was some sort of add-on action. I failed this one.
Okay, here's one that goes through Marked that is a lot faster and handles words as well as lines:
Convert Drafts Markdown to Rich Text with Marked.kmmacros (7.4 KB)
It's still not as seamless as Pandoc theoretically would be given that it relies on going through another GUI-based app, but I'd say it's still an improvement over the one I posted earlier, so I'll leave it here as another option. You should also be able to configure it to apply the font styles you want, which seems like it would be easier to do with an app than a command line utility like Pandoc.
I looked at that thread, and I don't know why no one there brought up the Apply Style to Clipboard action either. Still, live and learn, right? I know I'm still surprised sometimes by finding out about things I didn't know KM could do.
As for Insert Styled Text, it can indeed be easy to overlook if you don't know it's there, but it's just another option on the Insert Text action:
Thanks. I actually did read through that list LOOKING FOR IT while I prepared my post but somehow I skipped over it.
thank you very much for the macros !
I purchased Marked 2
I changed textedit to Scrivener in the macro
both macros work
- 1st macro a little bit slow, otherwise fine. Fonts are the right size.
- 2nd macro : faster but fonts are much too large: header 42 , otherwise 10.
I could very well function with the first macro. The 2nd macro requires too much formatting because of the font size.
But there is another issue, which is style. In Scrivener like in many apps, you can use styles which can be customized. The big advantage of using styles is that you can (for example in Scrivener), as you know very well, go to the styles panel, change a style (change the size of a heading), and all the headings defined with that style will change at the same time. It's a tremendous advantage in comparison to having to go through the whole document to reformat non style defined headings (I am just using headings as an example)
So, be it with GG's 1st or 2nd macro, I still end up with text which is unrelated to the app's style menu. One feature of Scrivener's style panel is that a keyboard shortcut can be assigned to each style.
If it was possible to have the macro
- select the line following the hash sign # and apply the keyboard shortcut Opt-Cmd 4 to it
- select all text between * and *, and apply the keyboard shortcut Opt-Cmd 1
- select all text between ** and **, and apply the keyboard shortcut Opt-Cmd 2
I would imagine that the macro actions have to happen within Scrivener, and not the clipboard, but the question is beyond me.
Just curious: is there any way to get marked 2 to view draft in real time using a draft's link or UUID ? Saving as a file as an intermediary step is a bit tedious.
thanks again very much for all the work !
Again, while I don't have Scrivener 3 myself and thus can't test this, it looks like Scrivener 3 supports searching with regex, so if you really want to apply Scrivener's own styles in this way, it might be possible by having KM drive a series of automated Find Nexts. Still, before you try that, now that you've bought Marked 2 (which can be used natively with Scrivener, by the way) I'd encourage you to look into making a custom CSS style for Marked that replicates the style you want applied: https://marked2app.com/help/Writing_Custom_CSS.html
You can do this with some other apps, but I don't believe you can do this with Drafts, at least not yet. It may be worth making a request to Marked's developer to add support for Drafts, since Marked already works with a good number of other third-party apps such as Bear, iA Writer, MindNode, nvALT, and OmniOutliner.
I'm sorry, I don't get the point.
Let's set aside anyone writing web pages. I know nothing about the subject and can understand the need for a preview app like Marked, and let's set aside all needs for export to html.
In apps like Drafts or Bear, the text displayed in Markdown looks 'basic' and I understand the need for a preview app like Marked for the purposes of viewing and exporting. The exporting options of Drafts Mac are very limited (json or txt).
But once you are in Scrivener, Omnioutliner, MindNode, etc why bother with a preview app ? Take Scrivener for example: you can do all the formatting, styling and exporting you want. The possibilities are too numerous to count. Why on earth would someone want a preview app ?
I use Scrivener a lot to write. My objective is to write. Why would I waste time playing around with Marked ,learning the syntax and editing cryptic CSS files (where even font and margin size is gibberish - see below)?
I am sure that there is something I don't understand and that's my point. I am not criticizing Marked and I certainly welcome all of your suggestions.
example of CSS file specs for a header:
margin: .6563em 0;
My main point was just to point out that you can use Marked in more ways than the one you bought it for; I know that I like to know what apps I buy can do, even if I don't end up using everything they can do. But of course, just because you can use Marked with other apps certainly doesn't mean that you need to. As for why someone would bother with a preview app for ones that already include formatting, I don't use mind maps or outliners and can't speak for those use cases, but my understanding with Scrivener is that you can use Marked to preview an entire Scrivener project at once, including one with many chapters and sections, even as you only focus on one small part of the project yourself. Depending on the user and type of project, I can see the utility in having two views of the same source. That said, it's not something I have much of a use for myself, and if you don't either, I'm sure you can keep writing in Scrivener without touching Marked if you don't see a need.
As for CSS, I believe it's what you'll need to get just the right kind of formatting if you use my second macro that goes through Marked. While I too wish that Marked offered more straightforward options for setting how it interprets Markdown into rich text, it doesn't seem to at this point, so if you explore your other options with automating Scrivener's styles and come to the conclusion that using Marked is still the best of an imperfect choice, it looks like you'll have to either learn enough about CSS to customize the skeleton theme to fit your needs, or perhaps ask someone who does know CSS for help (they may even be someone like that here for all I know; certainly there have been people who have done impressive things with KM's custom HTML prompts).
a very good point. thank you. The ability to work in Scrivener and see via Marked an emulation of the compilation is very interesting.
I am very happy you suggest and I bought Marked. It opens up a whole universe that I didn't know existed.
I just want to give you an update: it turns out that the 2nd macro version using Marked is extremely useful because the formatting is not so bad when I paste and preserve style in Scrivener, and incredibly pasted lists are fully functional, which is much more important than pretty headers. It is a highly unexpected surprise.
By functional lists, I mean can I can continue using the list in Scrivener, I can move items in all 4 directions which is fantastic.
I apologize for the negative tone of my previous email.
I'm glad to hear that, thank you. I would have felt bad if I had inadvertently gotten you to spend money on an app you didn't end up needing, so this is a relief. Just to make sure, I assume this means you modified the macro to select Scrivener's Paste and Match Styles menu option for the semi-final step then, like this?
I was doing it manually at the end. I will modify the macro.
I'm glad I said something then
No reason to do that yourself when KM is perfectly capable of automating it, after all.
I did some more testing, and the best Scrivener output is by going from Drafts → Marked as per your macro, and then Marked → export as RTFD → save RTFD file → open RTFD file in Scrivener.
I edited your macro as per below.
Funny thing: if I go through menu to export as RTFD, the macro sometimes works, but if I use the shortcut to do so (Shift-Cmd-S), it works fine.
I am posting because although the macro works, I do not find it very elegant because there are so many long pauses. The pauses have to be so long, otherwise from time to time, the macro does not work because the waiting time is unpredictable.
I was wondering if you have a way of avoiding so many pauses, perhaps replacing pauses with wait until.
I would like to learn to write more elegant macros.
I also wanted to ask you about the if then else action: if the else is simply to continue to the next action, I leave the otherwise execute part at the bottom blank ?
Please note how much I have already learnt from you: click on button, if then else, wait until, etc and I am very grateful.
thanks very much
Drafts→ Marked→ RTFD→ Scrivener.kmmacros (36.3 KB)
Okay, here's a quick crack at updating the macro to use a minimum of pauses. New actions are marked in yellow and orange to make them easier to find, since it's a fairly lengthy macro:
Drafts→ Marked→ RTFD→ Scrivener JL 1.2.kmmacros|attachment (37.6 KB)
I'm not sure why the shortcut to export as RTFD only works for you sometimes, as it worked consistently for me in my tests, but in case that's still the case for you, I left the old shortcut and pause intact but disabled so you can switch back.
As you can see, your intuition was right; using Pause Until was the way to go to reducing the number of lengthy pause actions. You were also correct to leave the "otherwise execute" part of the If Then Else action blank to have it continue to the next action without doing anything if its condition is not met.
I think most of my changes should be self-explanatory, but one that may be worth pointing out is how I changed the macro's way of accommodating for the existence of a pre-existing temp.rtfd file by having KM itself trash it if it exists, which lets you circumvent the need to deal with the "Replace?" dialogue completely.
your new macro is extremely instructive, much faster and flawless.
I learned a lot including replacing pauses with wait until button, check for the existence of files instead of replace, and confirming the otherwise execute.
You are extremely kind and generous with your time and expertise