MODX and Markdown

Jul 11, 2012

The Problem

MODX is a great CMS and generally what I turn to when I have any sort of web related project. With all the power it provides, there have been many times when I get caught up in trying to make modifications in the wrong way.

A perfect example is converting my site to using Markdown when writing my blog posts. Sure, there are other CMS's and blogging engines that have it built-in. You can also find easily installable plugins to make it work. But I wanted to use MODX, and while there was a plugin available, it requires you to place your code between tags that would then be replaced. While not a bad solution, that extra step just didn't appeal to me.

So anyhow, here I am with my fancy MODX install, my blog all configured using Articles to handle posts, and I decided that I really needed Markdown support. I mean, how fantastic would it be to write all my blog posts in plain text from any editor I wanted and just copy/paste it right in when it was ready.

The Investigation

My journey to add the support started with me digging into Articles and modifying Articles.class.php to do my bidding. This was great until an update was release, and of course after updating I needed to re-apply my updates. My next thought was to add a plugin. I already had a plugin parsing my documents and rendering code blocks, adding Markdown should be a piece of cake. So off I go creating a plugin and things were good, until I found a problem (turns out the problem was in my original solution as well.)

The problem I found, was when I wanted to show a summary of my post, it wasn't being rendered correctly. More specifically, either the Markdown was not being parsed at all, or tags were not being closed properly causing issues with the page as a whole. At this point, I had already spent more time than I planned and didn't really have any ideas on how to fix the problem without some convoluted way of going about it. So I deactivated my plugin, re-applied my changes to Articles, and went along my merry way (this was the least problematic solution for me at the time.)

The Solution

Fast-forward to today, and I see there is an update for Articles and I would like to update to this latest version of it. So I upgrade, and then remembered that I needed to re-apply my fixes. And then it hit me... an output filter would be awesome for this. So I created a snippet, updated my template to call the output filter and all was fixed. To top it off, I could now also call the same filter to be applied to post summaries and it didn't have any of the problems I had experienced before. BTW, I also realized the ellipsis output filter actually closes HTML tags, which is kind of awesome.

And just incase anyone was curious, I call my new filter like this:

For post summaries:

[ [+introtext:default=`[ [+content:markdown:ellipsis=`400`]]]]

And the actual blog template:

 [ [*content:markdown]]

Welcome 2012

Jan 16, 2012

Welcome 2012! Apparently the world is ending, so I feel like my goal of getting all my debt paid off this year should be postponed until I find out for sure. Hah, wouldn't that be silly. So far this year has been somewhat productive, even if the projects I'm talking about are all hobby type jobs.

My WoW guild's website finally got an update. I moved the site over to MODX so hopefully some of the guild members can keep it updated more frequently than it has been the last several years.

This site has finally been changed to use the awesome Articles package put together by splittingred, it really lets MODX be a much easier platform to use when creating a simple blog site. Of course, once I started using it I decided I'd really rather write my posts in Markdown so I had to hack up Articles a bit to get that going. I'll try to put up a post soon about that soon. I really wanted to add it as an option to the Articles package, but that was just going to take too long. I may come back and take a look at doing it properly once I finally get some sleep.

In other news, I got an Xbox 360 for Christmas which is pretty awesome. Although now I have a whole new toy to help me have even less free time. I managed to make it almost an entire week before some "l33t h4x0r" figured out the horrible password I had on my windows live account that hadn't been changed in about 9 years. Waking up to e-mails from Microsoft thanking me for spending $135 was exciting. Luckily I got my password changed quickly (they were already trying to change the e-mail address tied to the account). I then contacted Xbox support and was actually quite pleased with how it was all handled. In the end, eventually (they said a few weeks) I will be reimbursed for the transaction and I got a couple free months of Xbox LIVE. That money was going to be put towards some new ice skates, so when that gets resolved you can find me out tearing up all the ice here in Austin, haha!

I think I just woke up

Mar 30, 2011

At least it feels a bit like I just woke up. Things have been busy, busy, busy around here. Most of what I've been working on lately has been for my current employer so not a whole lot to talk about on that front. As for MODx, I actually released FAQ Manager, and that is working fairly well. There are still several things for that I'd like to fix up and improve upon, but at this point it does exactly what I wanted, just allowing you to add/edit FAQ's from inside the manager and not let those silly content editors touch the HTML too much. =)

RSVPMe is still up in GitHub... it actually works fairly well. It lets you set a page for people to RSVP for events. It maintains it's own tables through MODx to hold events and people that have registered. It also lets you set private events that require a code, and even lets you set a price to be paid when registering. The only payment option right now is through PayPal. The main reason it hasn't been released to the MODx Extras section is the lack of payment options and a bit of polish. But do feel free to give it a whirl if you need to handle RSVP's. If/when I get back to working on it, I'd really like to let it integrate with and event handling service (I'm liking EventBrite right now.)

Outside of the MODx world I've been working on my OS X programming. Objective-C and Cocoa are actually pretty cool, I find myself spending more and more time playing with it. I have a couple fun projects brewing for this, although it probably won't interest anyone that doesn't find themselves doing Takeoff/Estimating work in a construction industry. (Although, if that is your field of work, and you like to work on a Mac, send me and email as I'd like to talk to you.)

So, that about sums up those lost months on this site. Hopefully I'll get around to getting all the half-written content finished posted on here some day.  =)

Things I learned this week 6/14 - 6/18

Jun 18, 2010

This is my first weekly (hopefully) post about stuff I've learned/realized through the week. Hopefully there will be enough to make this somewhat valuable. And if nothing else, I can browse back through and remember stuff if I need it. Things will probably revolve mostly around MODx Revolution, with a healthy sprinkling of other little gems thrown in for good measure.

As a disclaimer... I can not promise that everything will work exactly as intended, and I may very well be wrong about how to go about doing some things I describe. If you have a better way, let me know. If something doesn't work... well... it must have, at least for me! haha

6-14

When using MODx Revolution output filters: strtotime needs to be used if your going to use date, otherwise date won't get a properly formatted date string and strange things can occur. This code sample was taken from the Revo docs, and is a good example of not only using these two filters together, but also filter chaining in general.

6-15

Not only Apple hates flash. Well, that isn't fair IE doesn't hate flash, it just doesn't like doing things you sometimes take for granted with other browsers. Our example today came about when my boss was trying to add some videos he'd made to a product's page. Well, of course, the video couldn't be on the page, unless you were watching it, and any sort of pop-up was a bad idea (although most of the content loading from an iframe and the layout being constructed purely from tables and devoid of CSS was a good idea?). I better not get started on my CSS war here at work. So anyway, I whipped up a quick little hide/show video button for him with jQuery and off we go. Well, about 30 minutes later someone views it in IE and realizes the sound just keeps playing even after you hide it. Crazyness... oh and about this time he'd managed to add a second video they wanted so you could end up having audio from both playing at the same time. So, my solution you may ask? I said, "Screw you IE" and completely removed the from inside the little div holding the movie. That worked wonderfully, so there you have it. $('.movie').html(''); will fix all your problems. Although, if you want to be able to show the video later without reloading the page you should probably save the contents of the container.

var movie = $('.movie').html();
$('.movie').html('');

6-17

Today I realized my projects won't continue to code themselves if I goof around for a while, although, I guess that is a good thing, you know, job security and all. I tend to jump around if I'm not paying attention, so I certainly have to try to keep myself focused on completing tasks in order before jumping to the next thing that seems fun.

MODx Makes Me Hungry

Jun 15, 2010

So, today I was busy at work, not working on my actual work, it was great. Well, that sounds bad, it was slightly related to my work, we can call it more of a research day. Anyhow, I was busy working... on this blog... and well I look at the clock at about 10:30 AM, and thought, "Great! Lunch is getting close." Well, wouldn't you know, the next time I looked up it was almost 4:30 (that is PM), and I totally missed lunch. Haven't been that engrossed in something in a long time, so it was kind of nice.

Hopefully I'll actually be able get my projects going to actually contribute at least something to the whole MODx community. I have lots of great ideas, just keep getting distracted.