Colon in the first line of a Markdown text creates pseudo-empty note

I have been pushing text notes in Markdown format from Drafts to DTTG for a while now. I all worked well with one exception: If there was a colon in the first line of the note body it arrived empty in DDTG.

I thought that some bug in my little JavaScript in Drafts I was unable to spot was the cause of that but I was wrong. It is DDTG itself and I find the same behaviour in the DTP 3 beta.

When a Markdown note contains a colon (exception: a colon right at the beginning) in the first line of the note body DTTP prompts: “Dieses Markdown-Dokumet [sic!] enthält nur Metadaten und erscheint daher als leer” (in my rough translation: “This Markdown Document does contain only meta data and therefore is displayed as empty”).

The “as” is interesting: The note just seems to be empty. If tapped on Bearbeiten/Edit the (not rendered) content becomes visible. Again: The same in the DTP 3 beta. And as I have set up a Smart Rule in DTP 3 to automatically convert Markdown to RTF the pseudo-empty note automatically turns into a real empty one.

This is not a bug. We support MultMarkdown and this is how metadata headers are declared.

Oh. Another reason why I will probably never become a friend of Markdown. Markdown has caused me more problems than RTF ever had due to the careless use of standard characters. I know that the idea was to just use characters everyone has at hand in any writing app but the inventors of Markdown would have made things way easier if they had used a syntax with, say, double square brackets, double colons etc. instead of single ones as if there were not already in use for writing purposes.

Not that I’m a fan of RTF and even less of Apple’s half-baked implementation of it but for the time being it will stay the format of my choice. If possible, that is. Sadly, Drafts does not support RTF.

Is there a way to tell the Markdown interpreter that the metadata section has ended? It would not be a problem to automatically add some header stuff to my markdown notes. Or wait: I could replace the first : with \:.

Jim, thank you for pointing me in the right direction. “Metadata” was prompted but I did not make the connection although I know MultiMarkdown and its headers.

I :heart::heart::heart::heart::heart: Markdown! (And yes, I look like a 15 year old schoolgirl there :stuck_out_tongue: ) I write long-form Markdown every single day and actually use Markdown in my support work.

If you put an empty space at the top of the file, it won’t resolve as Markdown metadata.

The beauty with MarkDown is that you don’t need to learn strange characters or tags to add formatting info your text files – and they look just fine as well when opening up in a text editor.

1 Like

I do see the merits of replacing html markup with easy-to-use Markdown markup.

I do see the merits of creating an exchange format based on plain text to get the utmost compatibility and durability of text files.

But—and listen carefully as here speaketh a father of an actual 15 year old school girl—: Control characters. do. not. look. fine. There lies no beauty in going back to the 90ties (or even the 80ties).

Fine typography is beautiful. Well crafted fonts with well crafted italics are beautiful.

I can write a text in Scrivener in rich text format, compile it via MultiMarkdown to LaTeX to PDF. Perfect writing environment with a perfect result. And Markdown banned to where it belongs, the engine room. That’s how it should be. (If PDF or print is the format you want. Of course html, see above, is a different kind of breed.)

And Jim, we will have to talk about the Markdown implementation in DT, but not here and now.

Control characters look ugly and hard to remember. Latex never took off outside the acacemia as it was hopeless to type it in without a cheat sheet.

MarkDow will be fine until it’s full of additional features few use.

You never used Wordstar! It was a great app, control characters and all.

How about an old Compugraphic typesetting system?


And yes, this shows my age a bit, but I cut my teeth on these, as well as…

and many more cool things!

nroff/troff was also good, speaking as a dinosaur to another.


I have to drag up this old thread because my Markdown notes to DEVONthink workflow has changed and my workaround for the colon-in-the-first-paragraph problem doesn’t work anymore.

To freshen our memories up: Due to a lack of any iPadOS note taking app that suits my needs and works with rich text notes I use a markdown note app (at the moment 1Writer) instead. A Smart Rule in DT converts the markdown note to RTF which works quite fine—with the one exception if there is a colon in the first paragraph. In that case that paragraph (and all following ones) are taken as MultiMarkdown metadata. And that metadata simply vanishes in the conversion to RTF.

I still do resist to adjust my writing to a flaw of the file format I am more or less forced to use.

So I politely want to ask for either an option in DT to deactivate MultiMarkdown Metadata in the parsing process.

Or to provide me with script snippets to enhance my Smart Rule. (The latter without any doubt can be done with much less effort.)

This is what I intend to do:

  1. Import the MMD file into DT
  2. Add an empty first paragraph to that MMD file.
  3. Convert the MMD file to RTF with DT’s own conversion feature
  4. Remove the empty first paragraph from the RTF file

The first and the third steps are taken already. The second should not be a problem because the note contains just plain text.

But how can I remove the first paragraph of a rich text file without flattening it to plain text?

Working with (rich) text in Apple Script is a pain and quite the opposite of easy to work with for anyone who is not an Apple Script expert.

It’s not a “flaw in the format”. It’s a feature.

The request is noted but Development would have to assess this.

It is a flaw in the format. If metadata in the first paragraphs used, say, a double colon instead of a single one there would not be a problem at all (that goes, by the way, for all markdown markups; I understand the idea of using only common characters for markup but this must not conflict with their non-markdown use). Except for people who are using kind of a free jazz punctuation.

Thank you for noting the request.

Is chopping off the first paragraph of a rich text without flattening it actually complicated? Could an own conversation routine via HTML or Plain Text be a simpler solution?

I played around a bit with the other note formats:

  1. If the Markdown note is converted to Plain Text every single character including first paragraphs with a colon is preserved in the text. As was to be expected—plain text doesn’t know anything about metadata.
  2. If the Markdown note is converted to either HTML or Formatted Note (it’s the same, isn’t it?) the first paragraphs containing a note are not preserved in the text but they are converted into proper HTML metadata. As was expected too—Markdown was invented as a user friendly way to produce simple HTML code.
  3. If the Markdown note is converted to RTF the first paragraphs with colons are simply erased.

So maybe it is the conversion to RTF that should be altered and not the handling of Markdown? My guess is that the RTF conversion works with the rendered Markdown file (which has, as intended, no visible metadata) and not with the source file. Or even with an HTML file created from the Markdown file.

My guess is that the RTF conversion works with the rendered Markdown file (which has, as intended, no visible metadata) and not with the source file. Or even with an HTML file created from the Markdown file.

Correct in both cases.

I have taken a first timid step to script my own basic TXT to RTF converter and I already failed.

Can anyone tell me why this does not work?

tell application id "DNtp"
	set this_record to content record
	set theText to plain text of this_record as string
	set theText to findAndReplaceInText(theText, "e", "o")
	set plain text of this_record to ("{RTF Header " & theText & "}") -- as string
end try
end tell

on findAndReplaceInText(theText, theSearchString, theReplacementString)
	set AppleScript's text item delimiters to theSearchString
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to theReplacementString
	set theText to theTextItems as string
	set AppleScript's text item delimiters to ""
	return theText
end findAndReplaceInText

I copied the findAndReplaceInText subroutine from Apple’s Apple Script page without altering it but it doesn’t work. Without calling findAndReplaceInText it works just fine.

A good first attempt :slight_smile:

When calling handlers (what the on findAndReplace… routine is called), use my handlerName, like so…

set theText to my findAndReplaceInText(theText, "e", "o")

Only two letters missing. Now it does work. Thank you.

But that was, like I said, only my first step. What I really want to do is of course to replace *something* by the RTF coding for italics and so forth.

Which means I need either Regular Expressions or I need a replace every second item handler. Is either of this possible in the text unfriendly Apple Script?

Another question (and most certainly not the last one regarding this subject): Is it possible to change the type of a file in DEVONthink without using any conversion routine? Renaming a file that has been recognized by DT as TXT to “.rtf” does not work, although it has a proper RTF header.

The idea is that my I replace all the Markdown asterisks (and maybe some more markups) in the MD/TXT file by its RTF counterparts in the first step. Then I’ll add a basic RTF header and a closing curly quote. In the last step I rename .md or .txt or whatever the extention ist to .rtf. This works when the file is renamed before it is moved to DT but not within. At least I haven’t found I way how to do this yet.

in the text unfriendly Apple Script?

I’m not sure what this means.

Is it possible to change the type of a file in DEVONthink without using any conversion routine?

No. But you could create a new RTF file with the text you’ve processed.

The idea is that my I replace all the Markdown asterisks (and maybe some more markups) in the MD/TXT file by its RTF counterparts in the first step.

That would be possible but difficult unless you know and understand the rich text specification. Under the hood, rich text is not a friendly format.

PS: Don’t use try… end try blocks when you’re initially writing your scripts. You have no error reported without it.

Alternatively, you could use an try… on error… end try block, like this…

set r to "a"
return r as real
on error theErrorMessage
display alert "" & theErrorMessage
end try

would display this…

PPS: Look at DEVONthink’s AppleScript dictionary. It’s your friend.

tell application id "DNtp"
	set this_record to content record
	convert record this_record to rich
end tell

See? :slight_smile: