Camen Design Forum


(Leave this as-is, it’s a trap!)

To delete this post you must be either the original author or a designated moderator.
The content of the post will be removed but the name and date will remain.

  • The post will be removed completely from the thread, rather than blanked
  • Only posts on the last page of the thread can be removed completely (so as to not break permalinks)

RE: Kroc, why did you bestow upon me this nightmare?


Something that immediately strikes me is that since JS doesn't support recursive regexes, the PRE block is not going to work. You should be feeding your script documentation.rem as a more robust test. Also, don't change the placeholder style! You appear to have added : and - to it, this won't work; the placeholder is the way it is because it is always the exact size of the content it is replacing, which is necessary for wordwrapping. By adding extra characters to it, you will break the wordwrapping, as well as that ReMarkable will crash with the "placeholders already in the markup" test and the title-casing code.

ReMarkable was written to compliment PHPs functionality and would be an entirely different beast if I were to write it in JS. Much of the complexity in the regexes (especially with look-behinds) is to do with the basic principle of how ReMarkable splits the content into chunks. In essence, what ReMarkable does is ensure that every paragraph has a blank line before and after it and any block-level elements (such as OL / DL) are on a separate line, not directly on the paragraph text. This allows something like this to have paragraphs added quickly and reliably:


The quick brown fox.

Jumps over the lazy dog.


The regexes have to do various checks to find the blank lines where each chunk starts and stops and must also check where lists come to an end and some other content follows. The lists are very complicated because ReMarkable has to assess whether the line before and after a list item is the beginning or end of the whole list or just an optional blank line between list items, and whether this blank line belongs to one list item or another one. It was a real headache to write and took something like a week to write that regex alone.

Because these regexes are operating on the whole source text, they have to be careful not to step on other content. This is where the JavaScript regex limitations are going to suffer badly.

If I were doing ReMarkable from scratch in JS (where closures are cheap), I would instead chunk the content in to multi-level object arrays, based on type.

For example, if you use regex to recognise a whole list, you would remove the whole list from the source text and put it into an array of removed chunks with everything else, and then use a sub-array for each of the list items (so that the list-item regex would not have to be aware of what was above / below the list). With all the source text broken into a nested array that represents actual depth, doing the word-wrapping, output and indenting would be very cheap.

This is also how I would probably do it when -- if ever -- my host upgrades to PHP5.3, where I can use cheap closures.

As it stands I cannot see anyway that JS can recursively recognise the PRE fences and this syntax will have to be changed to better support weak regex engines.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn