Bad rendering on MultiMarkdown Syntax Highlighting

I believe I may have found a bug in the MultiMarkdown Syntax highlighter. I’m currently studying an intro level JS course and adding a whole bunch of code blocks in MultiMarkdown draft. As I add more and more, it seems like the on-screen rendering gets confused and starts showing everything below a certain portion as code env if the code block has been closed off. Usually this goes away by switching to a different Draft and then coming back but now it seems like it’s broken.

I can provide the .md file if desired (not allowed to attach here in the forum). Here’s a screenshot illustrating the problem.

Note from below, if you render to HTML, it looks fine

Sort of a bug, sort of a performance trade off.

To do syntax highlighting, you have to scan the text. To truly be correct in a longer document with a lot of code blocks like this, you have to rescan the entire text to find the paired sets of ticks. Unfortunately, that can be really slow to rescan the entire document for every change. This is less of problem with shorter documents, and less of a problem on Mac than on iOS, but to minimize the performance issues, the default syntax definition for MultiMarkdown is currently configured to look around a text change up to 1000 characters ahead and behind to evaluate syntax.

This means you can get in a case like you describe where you end up with mismatched block elements in the scope of the evaluation. If you reselect the draft from the list, the full text is evaluated, and the variance corrected.

This is configurable in Drafts syntax engine. Once custom syntaxes become available later this year, you could configure an alternate MMD syntax that always evaluated the full text. As it stands, I don’t think it’s a good default, because it longer documents it can create a real noticeable lag when typing.

Hopefully that made some sense.

2 Likes

That makes perfect sense. Thanks for the quick response!

The issue is still there, even for short samples. Is there something we can tweak to improve our day-to-day experience?

Example source md:


HeartBeat

  • Send message to the SQS Queue ss-{env}
{"userId":""0"}

In ff-server:

{"level":"INFO","message":"Activated Server_, set slot time ? true","position":"location","timestamp":"2022-02-01T10:48:52,351"}

In MongoDB

use db
jj({"PrivateBIC":"Server_SyY1McFQ8DXHcQ7C6ylOjzrFCD.Pz3mXyRrlNJ-r1SFdY0R"})
{ "_id" : ObjectId("61f9101405065c72aacd4786"), "PrivateBIC" : "k-r1SFdY0R", "userId" : "119009367", "variant" : { "language" : "en", "country" : "US", "ski" : "0.25.0" }, "expireAt" : ISODate("2022-02-03T10:48:52.326Z") }

Inspect the slot

db.user.find({"PrivateBIC":"fe-r1SFdY0R"})
{ "_id" : ObjectId("f"), "PrivateBIC" : "Server_SyY1McFQ8DXfCD.Pz3mXyRrlNJ-r1SFdY0R", "ServerId" : "119009367", "createdAt" : ISODate("2022-02-01T10:48:52.326Z"), "activatedAt" : ISODate("2022-02-01T10:48:52.326Z"), "status" : "active", "slotTime" : { "hour" : 0, "minute" : 22 } }
f = File.open("random-us.pre-cache")

f.each_line do |l|
	dd, ServerId = l.chop.split(" ")
	puts %Q|{"userId":"#" }|
end

This is broken


As mentioned in my above response, you can do this with custom syntaxes, as long as the trade-off of performance is not an issue for you. Those were not available at the time I made that comment, but are now.

If you use code blocks a lot, and want to always force syntax highlighting to re-evaluate the entire content of the draft on each render pass, you can alter the syntax. Export the “MultiMarkdown” syntax, open it in a JSON editor, and change the rangeExtensionType default value to “fullText” instead of “lineExtended”, like:

"rangeExtensionType": {
    "default": "fullText"
  }

Also, probably, change the name property to “MultiMarkdown-Custom” or something to more easily distinguish the syntax, import it into Drafts, and assign this syntax to your draft (or as a default for new drafts).

If you use that, it will not be susceptible to this issue. More on modifying syntaxes and this value:

1 Like

I understand the point you are making and I’m sure you’ve considered this very carefully, but this design choice is really painful. I frequently use Drafts for code documentation and it is pretty much unusable. Is there anything that can be done to improve the usability for code blocks? How about adding an option to the preferences, so that I can at least toggle between rendering modes.

There is an example syntax in the directory that uses full text evaluation. If this is important to you, you can install and use it instead of the default MultiMarkdown syntax:

1 Like

@agiletortoise
Thanks for providing this syntax. It really bummed me out, because I love the simplicity of drafts for documentation and note-taking, but the text scan was annoying as hell. I do understand the performance aspect, but does it really affect the performance so much that it can’t be the default?
Anyway, my problem has been solved with your syntax! Thanks :pray: