MDIH Separation

MDIH Separation

Michel Fortin was kind enough to reply regarding my post on the Markdown mailing list. He pointed out inconsistencies in the syntax I had chosen, and suggested some more forward-looking approaches.

As a result, I was able to separate my code from Markdown, so it’s now “quicky and independent”, just right for my own website. A pretty instructional journey.

As I would expect, leaving the original Markdown image syntax alone would be preferable (this was my thought too), but I didn’t know how to actually add the additional parameters I needed (width, alignment, etc). Starting from the actual PHP-Markdown source allowed me to develop the core ideas behind the image features I wanted, but my inexperience with PHP, WordPress–heck, all of this–was lacking. So I just hacked, copied/pasted code with Markdown to achieve this.

Michel suggested something I hadn’t considered…using special URLs within the existing Markdown image framework, then running another filter AFTERWARDS that keyed off of that. It could look for my own pseudo-protocol identifiers, and then substitute my own formatting.

The problem is to get a link, the syntax is basically the image syntax embedded in the link syntax:

    `[![alt-text](image.jpg "img-title")](link/url "link-title")

And it’s rather cumbersome. And the image formatting I’m doing needs to invoke a class for the A tag and for the image tag.

In the interest of separating from Markdown and working in the future, perhaps the thing to do now is dump the ref-id functionality and make an independent filter. So that’s what I’ll do next!

My philosophy: * Retain the formatting control from MDIH * Retain thumbnail generation * Don’t interfere with Markdown syntax * Maintain terse-as-possible syntax, which probably means it won’t be compatible. So be it!

So here’s what I did…

  1. Tried stripping out all the code except for my own, and see what happens. Hm, there is a conflict between Markdown and my image syntax. I’ll first run it AFTER Markdown, at priority 7.

  2. Hmm, the images turned into links. Ah, it’s sees the syntax. So I need to run my code before Markdown runs. So let me change the priority to 5.

  3. That seemed to work. A lot of the special stuff that Markdown does is for other features, but I’m doing some pretty straight-forward replacement.

    • One problem is that I can’t show my !@ code inside a code block because it executes before Markdown escapes it. That sucks. The alternative is to change my image syntax so it doesn’t look like Markdown, which is what I should probably do.
  4. Let’s evaluate the syntax. Can it be made more terse using the conventions expressed? And what would make sense for breaking away? The new syntax is… !@ ( path_to_image:asize url "alt-text)


p>…without the space between the @ and (. Since the filter runs outside of Markdown, the magical code quoting doesn’t work.

  1. I’m using the syntax !@ --- (again, without the space) to designate a break. The —, however, gets turned into a long dash. Therefore I installed TWO filters: a LazyImagesPre() which runs at priority 5, and a LazyImagesPost() which runs at priority 7. So I get the — before Markdown does.

So that’s the new syntax.

!@[img](dest title)(asize)

LZIL: file not found:
url title) would break the match, and then it could run after Markdown.