Code snippets, tech tricks and other bits and bobs

markdown via email test

This is a test of that same script send via RTF email:

And it’s gone a bit wrong again. Well, this isn’t Posterous' fault, but Outlook’s. When I highlight a block of code and tab it in wholesale, instead of inserting tabs, Outlook decides to fuck around with the HTML. What a surprise! I’d never have expected that.

[p class=MsoNormal style=‘margin-left:72.0pt’]function strip_html_tags( $text )[o:p][/o:p][/p]

n.b. < > replaced with [ ]

OK, I can see the point in using styles, to a point. But a new set of p tags with the same style tag AND a class on EVERY LINE? Oh, COME ON Microsoft! And what on EARTH is [o:p][/o:p] for? BAD Outlook. No biskwits for you.

Can Posterous work around this? It’s easy to replace every instance of style=‘margin-left:72.0pt’ with two tabs, but does every user have Outlook set up to use that size and units? If not, it gets damn complicated. Good luck to them, I wouldn’t want to do it. Dealing with MS' idea of HTML is a daily nightmare for me and probably anyone who ever reads this (probably no-one!)

Posterous Chris is still working on the problem with MCE chewing up the Object tags in the script, but that’s a separate issue.

/**

  • Remove HTML tags, including invisible text such as style and

  • script code, and embedded objects. Add line breaks around

  • block-level tags to prevent word joining after tag removal.

*/

function strip_html_tags( $text )

{

$text = preg_replace(

    array(

      // Remove invisible content

        '@@siu',

        '@@siu',

        '@@siu',

        '@]*?.*?@siu',

        '@]*?.*?@siu',

        '@]*?.*?@siu',

        '@]*?.*?@siu',

        '@@siu',

        '@]*?.*?@siu',

      // Add line breaks before and after blocks

        '@

Filed under  //   Outlook 2007   markdown  

Props to Posterous

I mailed Posterous earlier regarding the problems I was having with markdown mode, and before the end of the day we'd had a short discussion, they'd found the source of the problem and we should have a fix in the works very soon.

Top marks!

Filed under  //   Posterous   markdown  

Another attempt at PHP syntax highlighting

So this is an illustration of Posterous' markdown tag. Lets see how we go:

Well, starters, if I include a link to the markdown help page on the text of the word markdown above, then that’s it. End of post. Bit shit really. Here’s the link pasted in plain text. Will it break again?

http://posterous.com/help/markdown

No. Was the parser getting confused by the word markdown being in the href attribute of the A tag? or by the word markdown being in the middle of the A and /A tags? That is possible – an overly greedy Regex could confuse {a}markdown{/a} with {markdown}, or something along those lines. Anyway, on with the syntax highlighting. See here for my first attempt: http://disasterman.posterous.com/tech-snippets And here’s the code with syntax highlighting:

strip_html_tags() Function

/**
 * Remove HTML tags, including invisible text such as style and
 * script code, and embedded objects.  Add line breaks around
 * block-level tags to prevent word joining after tag removal.
 */
function strip_html_tags( $text )
{
  $text = preg_replace(
    array(
      // Remove invisible content
      '@]*?>.*?@siu',
      '@@siu',
      '@@siu',
      '@]*?.*?@siu',
      '@]*?.*?@siu',
      '@]*?.*?@siu',
      '@]*?.*?@siu',
      '@@siu',
      '@]*?.*?@siu',
      // Add line breaks before and after blocks
      '@

Well, this is still being mangled badly.

The trick to getting Syntax highlighting is to precede all code lines with two tab characters. My booboo – failed to spot that.

This causes problems in itself though – if you send post with a plain text email, line breaks will be introduced, which will break code and be missing the tabs for formatting on the new lines.

There should be 36 lines of code above, but due to the Posterous parser introducing html comment tags all over the shop, you can’t see most of it. Well, for now, some code simply can not be posted it would seem.

Get the original code courtesy of: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_p age

The code is covered by the OSI BSD license so you can use, modify, redistribute, and sell as you see fit. http://www.opensource.org/licenses/bsd-license.php

Filed under  //   PHP   markdown