Hoppa över navigering, gå direkt till textinnehållet



Markdown with Textpattern

Start by downloading Michel Fortins PHP Markdown that is a ported version of John Grubers Markdown to PHP.

Getting it to work is very simple, just replace classTextile.php with the markdown code, make sure the file is still named classTextile.php.

We now have a working textpattern install with Markdown instead of Textile, but there is a few things that we have to do to make it work better.

  1. Make sure textpattern tags not being wrapped with <p> tags.
  2. Change so comments are wrapped with <p> tags instead of a new line is done with a <br />.

We start with the wrapped textpattern tags. Open your classTextile.php that now have markdowns PHP code instead.

Goto line #222 and #224 and add |txp(.*) at the end of the both strings, when you are done you will have it like below.

  1. $block_tags_a = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'.
  2. 'script|noscript|form|fieldset|iframe|math|ins|del|txp(.*)';
  3. $block_tags_b = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'.
  4. 'script|noscript|form|fieldset|iframe|math|txp(.*)';
  5. Download this code: /code/040.txt

This will do the trick with textpattern tags that looks like <txp:my_plugin>some text here</txp:my_plugin>. But with tags that looks like <txp:my_plugin /> we have to do another change.

Goto line #289 after the special case for <hr /> tags and insert this bunch of code.

  1. # Special case just for Textpatterns one line tags.
  2. $text = preg_replace_callback('{
  3. (?:
  4. (?<=\n\n)# Startingafter a blank line
  5. |# or
  6. \A\n?# thebeginning of the doc
  7. )
  8. (# save in $1
  9. [ ]{0,'.$less_than_tab.'}
  10. <(txp)(.*)# start tag = $2
  11. \b# word break
  12. ([^<>])*?#
  13. /?># the matching end tag
  14. [ \t]*
  15. (?=\n{2,}|\Z)# followed by a blank line or end of document
  16. )
  17. }x',
  18. '_HashHTMLBlocks_callback',
  19. $text);
  20. Download this code: /code/039.txt

Thats it, we are now done with the first part. Now lets take a look at the comment part.

In comment.php goto somewhere around line #87, comment out and insert the new changed line like the example below.

  1. // $message = trim(nl2br($textile->TextileThis(strip_tags($message),1,'',$im)));
  2. $message = trim($textile->TextileThis(strip_tags($message)));
  3. Download this code: /code/041.txt

Now goto somewhere around line #302 look for $message2db and comment out the line and insert the new line like the example below shows.

  1. //$message2db = addslashes(nl2br($textile->textileThis($message,1,'',$im)));
  2. $message2db = addslashes($textile->textileThis($message));
  3. Download this code: /code/042.txt

Thats it!

Tobias Bergius sa,
31. januari 2005, 03:43

Nice! But you still get the Textile help. Is there an easy way to change this so you can see the Markdown syntax instead?

Tobias Bergius sa,
31. januari 2005, 04:27

This doesn’t work with your ÅÄÖ-converter tho. :(
Any way to fix this?
I get these errors:
[client 127.0.0.1] PHP Fatal error: Call to a member function decode_high() on a non-object in C:\wwwroot\textpattern\publish\taghandlers.php on line 212
[client 127.0.0.1] PHP Notice: Undefined variable: Textile in C:\wwwroot\textpattern\publish\taghandlers.php on line 212

Tobias Bergius sa,
31. januari 2005, 04:35

Nevermind the last error. That was me doing a typo. :)

31. januari 2005, 08:21

Open /textpattern/include/txp_article.php and look for the function sidehelp(). Then you have to translate the Textile syntax over to Markdowns syntax.

25. april 2005, 11:46
Hi, nice work!

I’m considering moving to Markdown, mainly because I can’t post code (i.e. txp tags) in my comments, as all HTML code is stripped, and it seems there is no way to fix this. At least I couldn’t find it.

Do you know if I replace Textile with Markdown I will be able to post code (tags) on the comments?

I tried your Code transformer for Textpattern, but it doesn’t work for me, Textile simply strip everything between the @

Thanks for any info
andrea sa,
1. juni 2005, 06:11
i have the same question as multiverso – does the stripping of html tags still happen with markdown installed as they do with textile? i’d like to use just two tags: the anchor tag and the image tag.

thanks!
25. maj 2007, 04:36

life insurance here
globe life insurance and here [URL=”http://life-insurance.superbankonline.info/variable-life-insurance.html”]variable life insurance[/URL]

Gott nytt år!Igår och idag