A Test Entry with Markdown+Strikedown
I like Markdown; it works very well. But it doesn’t have the ability to emphasize text with strikethroughs, which are a mainstay of modern conversation in blogs these days.
So I modified it. Watch this:
Here is a strikethrough.
See how easy that was? All I did was type a dash before and after the word “strikethrough,” and Markdown now makes that into a strikethrough.
To do this, all I did was modify the Markdown.pl code a bit. Here’s how you can do it, too.
Find Markdown.pl. For MoveableType users, it’s in mt/plugins/Markdown. Edit it with your favorite editor and go to line 1040. Make that block of code look like this by adding the last two or three lines (you can credit me if you want):
sub _DoItalicsAndBold {
my $text = shift;
# <strong> must go first:
$text =~ s{ (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }
{<strong>$2</strong>}gsx;
$text =~ s{ (\*|_) (?=\S) (.+?) (?<=\S) \1 }
{<em>$2</em>}gsx;
# These lines added by Bill Eccles, 2008-07-04
$text =~ s{ (\s) (-) (?=\S) (.+?) (?<=\S) (-) }
{$1<strike>$3</strike>}gsx;
return $text;
}
Be forewarned that I’ve only tested it in very simple use (you’ve seen all the testing I’ve done, above) and that it might do unexpected things. But so far, so excellent good!
UPDATE: I wonder if this will make problem for people who-make-use of words-with hyphens-randomly scattered throughout their text… YES! AGH!
I’ll have to go work on that for a bit… back in a while.
UPDATE: OK, that problem is fixed (as you can see above). It does fail, however, with striking through hyphenated words, (Here’s an example-.) but that’s OK in my book. Just leave out the hyphen—it’d be lost in the strikethrough anyway.
Rob Shearer had this to say:
[Bill says: Don't know what happened with the commenting system. Sometimes I find that the recaptcha text isn't necessarily a recognizable word and I've got to guess, too. But it works. And I tried--and this is what might have messed up Rob--to get his code into MT, but it didn't work worth a hoot. Where you see "strikethrough" above, substitute in the real HTML tag element with GT's and LT's around 'em.
Anyway, I disagree that the purpose of Markdown is to make something that looks like HTML. In fact, John explicitly states:
andRob's absolutely correct that dashes don't convey the same semantics, but Markdown isn't about semantics. It's about ease of use and readability, and perhaps I haven't got the right-est solution, but it works for me. And, I assume, Rob's works for him, too.
Hey, the best part about all of this? To each his own!
Thanks for the comment, Rob, and sorry you had trouble with the commenting system. /Bill]