Skip to content
This repository has been archived by the owner on Dec 24, 2017. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Lewis committed Sep 4, 2011
2 parents 1280470 + b2f7c84 commit 721046e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
131 changes: 89 additions & 42 deletions ee2/third_party/smartdown/pi.smartdown.php
Expand Up @@ -6,8 +6,8 @@
* @author Stephen Lewis (github.com/experience)
* @copyright Experience Internet
* @link http://experienceinternet.co.uk/software/smartdown/
* @package SmartDown
* @version 1.1.0
* @package Smartdown
* @version 1.2.0
*/

require_once PATH_THIRD .'smartdown/markdown/markdown.php';
Expand All @@ -20,7 +20,7 @@
'pi_description' => 'Smarter Markdown, with PHP Markdown Extra and SmartyPants for spicy content goodness.',
'pi_name' => 'SmartDown',
'pi_usage' => Smartdown::usage(),
'pi_version' => '1.1.0'
'pi_version' => '1.2.0'
);


Expand Down Expand Up @@ -61,51 +61,94 @@ public function __construct($tagdata = '')
$functions = $ee->functions;
$tmpl = $ee->TMPL;

$default_smartquotes = '2';
$this->return_data = '';
$this->return_data = '';

if ($tagdata)
/**
* Establish the default settings, and override them with
* any config settings.
*/

$settings = array(
'disable:markdown' => $config->item('disable:markdown', 'smartdown') === TRUE ? TRUE : FALSE,
'disable:smartypants' => $config->item('disable:smartypants', 'smartdown') === TRUE ? TRUE : FALSE,
'ee_tags:encode' => $config->item('ee_tags:encode', 'smartdown') === TRUE ? TRUE : FALSE,
'smart_quotes' => $config->item('smart_quotes', 'smartdown') ? $config->item('smart_quotes', 'smartdown') : '2'
);

if ( ! $tagdata)
{
$tagdata = $tmpl->tagdata;

/**
* Override the settings with any tag parameters. There must be
* a more elegant way of doing this, but my brain is failing me
* right now.
*/

$settings = array(
'disable:markdown' => $tmpl->fetch_param('disable:markdown')
? ($tmpl->fetch_param('disable:markdown') == 'yes')
: $settings['disable:markdown'],

'disable:smartypants' => $tmpl->fetch_param('disable:smartypants')
? ($tmpl->fetch_param('disable:smartypants') == 'yes')
: $settings['disable:smartypants'],

'ee_tags:encode' => $tmpl->fetch_param('ee_tags:encode')
? ($tmpl->fetch_param('ee_tags:encode') == 'yes')
: $settings['ee_tags:encode'],

'smart_quotes' => $tmpl->fetch_param('smart_quotes')
? $tmpl->fetch_param('smart_quotes')
: $settings['smart_quotes']
);
}

// Encode EE tags.
if ($settings['ee_tags:encode'])
{
// Fieldtype.
$encode = $config->item('smartdown:ee_tags:encode') == 'yes';
$fix_images = !($config->item('smartdown:ee_tags:fix_transplanted_images') == 'no');
$smart_quotes = $config->item('smartdown:smart_quotes') ? $config->item('smartdown:smart_quotes') : $default_smartquotes;
$tagdata = $functions->encode_ee_tags($tagdata, TRUE);
}
else

// Pre-processing hook.
if ($ee->extensions->active_hook('smartdown_parse_start') === TRUE)
{
// Template tag.
$tagdata = $tmpl->tagdata;
$encode = ($tmpl->fetch_param('ee_tags:encode') == 'yes') OR ($tmpl->fetch_param('encode_ee_tags') == 'yes');
$fix_images = !($tmpl->fetch_param('ee_tags:fix_transplanted_images') == 'no');
$smart_quotes = $tmpl->fetch_param('smart_quotes') ? $tmpl->fetch_param('smart_quotes') : $default_smartquotes;
$tagdata = $ee->extensions->call('smartdown_parse_start', $tagdata, $settings);
}

if ($encode)
// Markdown.
if ( ! $settings['disable:markdown'])
{
$tagdata = Markdown($functions->encode_ee_tags($tagdata, TRUE));
$tagdata = Markdown($tagdata);

/**
* ExpressionEngine automatically encodes any EE tags within
* the tagdata, regardless of context.
*
* This is not what is required within <code> tags, so we
* fix that problem here.
*/

// Fix EE code samples.
$tagdata = preg_replace_callback(
'|' .preg_quote('<code>') .'(.*?)' .preg_quote('</code>') .'|s',
array($this, '_fix_encoded_ee_code_samples'),
$tagdata
);

// Fix {path=} URLs.
$tagdata = preg_replace('/&#123;(path=.*?)&#125;/i', '{$1}', $tagdata);

// Play nicely with NSM Transplant and the {image_xx} technique.
if ($fix_images)
{
$tagdata = preg_replace('/&#123;(image_[0-9]+)&#125;/i', '{$1}', $tagdata);
}
}
else

// SmartyPants.
if ( ! $settings['disable:smartypants'])
{
$tagdata = Markdown($tagdata);
$tagdata = SmartyPants($tagdata, $settings['smart_quotes']);
}

$this->return_data = SmartyPants($tagdata, $smart_quotes);

// Post-processing hook.
if ($ee->extensions->active_hook('smartdown_parse_end') === TRUE)
{
$tagdata = $ee->extensions->call('smartdown_parse_end', $tagdata, $settings);
}

$this->return_data = $tagdata;
}


Expand Down Expand Up @@ -144,27 +187,30 @@ public function usage()
{/exp:smartdown}

## Parameters ##
`disable:markdown`
: Set to `yes` to disable Markdown. Default is `no`.

`disable:smartypants`
: Set to `yes` to disable SmartyPants. Default is `no`.

`ee_tags:encode`
: Set to `yes`, to convert the curly braces for all EE tags and variables into entities. Default is `no`.

`ee_tags:fix_transplanted_images`
: Set to `no` to prevent `ee_tags:encode` from playing nicely with NSM Transplant and the `{image_xx}` technique. Default is `yes`.

`smart_quotes`
: Fine-grained control over SmartyPants' handling of smart quotes. Will never be used by 99% of you.
Nosey types should take a look at the SmartyPants source code.

## Fieldtype parameters ##
The SmartDown fieldtype may be configured using `config.php`. This makes it possible to set any of the supported SmartDown parameters directly in the fieldtype, without the requirement to use the `{exp:smartdown}` template tag.

`$config['smartdown:ee_tags:encode']`
: Mirrors the `ee_tags:encode` template tag.

`$config['smartdown:ee_tags:fix_transplanted_images']`
: Mirrors the `ee_tags:fix_transplanted_images` template tag.
The SmartDown config settings should take the form of an associative array. All of the documented template parameters are supported, the only difference being that `TRUE` should be used instead of `yes`, and `FALSE` instead of `no`.

`$config['smartdown:smart_quotes']`
: Mirrors the `smart_quotes` template tag.
$config['smartdown'] => array(
'disable:markdown' => TRUE, // TRUE or FALSE. Default is FALSE.
'disable:smartypants' => TRUE, // TRUE or FALSE. Default is FALSE.
'ee_tags:encode' => TRUE, // TRUE or FALSE. Default is FALSE.
'smart_quotes' => 1 // Default is 2.
);

<?php

Expand Down Expand Up @@ -201,5 +247,6 @@ private function _fix_encoded_ee_code_samples($matches)

}


/* End of file : pi.smartdown.php */
/* File location : third_party/smartdown/pi.smartdown.php */

0 comments on commit 721046e

Please sign in to comment.