user-pic

PHP Markdown Extra

Vote 0 Votes

Does anyone know

  1. If MT4.2 support PHP Markdown and PHP Markdown Extra?
  2. If so, how is it to be installed?
  3. Once installed, does it work on static pages or only dynamic? Most of my pages are suffixed PHP, but that's only because I want to retain the option of adding simple PHP code (such as includes) when necessary. Otherwise, to all intents and purposes, they're no different from html pages and are entirely static.

Reported on Movable Type 4.2

5 Replies

| Add a Reply
  • (Answering some old questions still in the archive; sorry for the late response.)

    The answer here is YES. MT, as you may know supports both static and dynamic publishing. For our dynamic publishing support, we do have PHP Markdown built-in (version 1.0.1c). You'd just need to change the publishing for your site to be dynamic instead of static to use this module.

    If you want to keep static publishing and still use PHP Markdown OR PHP Markdown Extra, you can do that also. But this will require the following:

    * If you're not publishing your pages as PHP files, you'll need to do that.
    * Template changes so that the EntryBody and EntryMore tags are output in their raw form.
    * Template changes to include PHP Markdown (or PHP Markdown Extra) module where the entry text is published.

    Here, your pages would be dynamic, in the sense that they are PHP files, but they are statically published (each page view would not require access to the database for the entry content). The dynamic element would be the Markdown transformation. So instead of publishing the EntryBody tag with Markdown formatting done by MT, you'd defer that to be done when the page is viewed.

    Here's a simple example showing how you would call the PHP Markdown library with the content from your entry:

    <?php
    include_once "markdown.php";
    echo Markdown('<$MTEntryBody encode_php="q" convert_breaks="0"$>');
    ?>

    And a similar block would be necessary to publish the EntryMore tag. Don't forget to make similar changes to the main index template and any feed you publish.

  • Brad,

    Can you point me to the example?

    Thanks.

  • The code didn't appear earlier; it does now, thanks to OtherNiceMan over at Pronet. Many thanks.

  • Actually, I think the code example is somewhat inaccurate with the later releases of MT.

    If you want to use only markdown (and not markdown with smartypants) it should be:

    <?php
    require_once "modifier.markdown.php";
    echo markdown('<$MTEntryBody encode_php="q" convert_breaks="0"$>');
    ?>
    

    But if you want to use smarty's smarty typography (I do), it should be:

    <?php
    require_once "modifier.markdown_with_smartypants.php";
    echo smarty_modifier_markdown_with_smartypants('<$MTEntryBody encode_php="q" convert_breaks="0"$>');
    ?>
    

    The reason is that there is no file called markdown.php in the /mt/plugins/Markdown/php folder. The files are modifier.markdown.php and modifier.markdown_with_smartypants.php.

    Also, it very likely won't work on a local Xampp installation. For that, you have to install smarty in Xampp. There's a good tutorial on that here, but while that works generally (in Xampp but outside MT), it's not enough to work with MT.

    To get it to work with MT on XAMPP, you need to edit the php.ini file (c:\xampp\php\php.ini) and add this:

    include_path = ".;C:\xampp\smarty\libs"
    include_path = ".;C:\xampp\htdocs\mt\plugins\Markdown\php"
    

    The first line is what is required for smarty to work outside MT. The second gets markdown-smarty working in MT on XAMPP.

    PHP Markdown Extra

    The shipped PHP Markdown is straight markdown ported for PHP. What's truly beautiful is Michel Fortin's PHP Markdown Extra. That is a thing of joy and beauty because it lets you

    1. Use Markdown inside block-level html tags (like <div>);
    2. Use ids for headers;
    3. Use definition lists;
    4. Create tables and even align cells in Markdown, plus use Markdown formatting inside cells;
    5. Create and use footnotes;
    6. Use abbreviations natively;
    7. Use emphasis code (underscores) between words without fouling the output; so you_can_do_this and it won't show up as youcandothis -- which has plagued so many of us.

    To use Php Markdown Extra, download the latest version (1.2.3 at time of writing) from here, and extract it. There's a file there called markdown.php. Rename this to modifier.markdown.php and copy it over to your Markdown PHP plugins folder (your-mt-install/plugins/Markdown/php). I suggest you rename the existing modifier.markdown.php to something like modifier.markdown.php.orginal just to be safe.

    That's all. Now you're good to go, with all the advantages of PHP Markdown Extra even on your static page, even on your local installation.

    Hope this helps someone. As in all things, there's probably an easier way to do this, but this one works.

  • Correction. The code should be

    <?php
    require_once($_SERVER['DOCUMENT_ROOT'].'/mt/plugins/Markdown/php/modifier.markdown_with_smartypants.php');
    echo markdown('<$MTEntryBody encode_php="q" convert_breaks="0"$>');
    ?>
    

    But if you want to use smarty's smarty typography (I do), it should be:

    <?php
    require_once($_SERVER['DOCUMENT_ROOT'].'/mt/plugins/Markdown/php/modifier.markdown_with_smartypants.php');
    echo smarty_modifier_markdown_with_smartypants('<$MTEntryBody encode_php="q" convert_breaks="0"$>');
    ?>
    

    This ensures that the correct file is called relative to the root.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 567

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012