? geshi_compliance.patch ? geshi_compliant.patch ? marksmarty.2.module ? marksmarty.geshi.module ? marksmarty.module.back ? marksmarty_geshi.patch ? no-markup.patch ? no-markup_markdown.php ? no_markup_and_geshi.2.patch ? no_markup_and_geshi.patch ? no_markup_in_markdown.patch ? split_marksmarty.patch Index: marksmarty.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/marksmarty/marksmarty.module,v retrieving revision 1.21 diff -u -p -r1.21 marksmarty.module --- marksmarty.module 22 Jan 2008 22:25:27 -0000 1.21 +++ marksmarty.module 14 Feb 2008 19:10:09 -0000 @@ -6,27 +6,45 @@ ********************************************************************/ function marksmarty_filter($op, $delta = 0, $format = -1, $text = '') { - switch ($op) { - case 'list': - return array(t('Markdown with SmartyPants')); - - case 'description': - return t('Allows content to be submitted using Markdown, a simple plain-text syntax that is filtered into valid XHTML, and converts plain ASCII characters to Unicode entities using SmartyPants.'); - - case 'settings': - return _marksmarty_settings($format); - - case 'process': - return _marksmarty_process($text, $format); - - default: - return $text; + if ($op == 'list') { + return array(0 => t('Markdown'), 1 => t('SmartyPants')); + } + if ($delta == 0) { + // markdown + switch ($op) { + case 'description': + return t('Allows content to be submitted using Markdown, a simple plain-text syntax that is filtered into valid XHTML.'); + + case 'settings': + return _markdown_settings($format); + + case 'process': + return _markdown_process($text, $format); + + default: + return $text; + } + } else { + // smartypants + switch ($op) { + case 'description': + return t('Converts plain ASCII characters to Unicode entities using SmartyPants.'); + + case 'settings': + return _smartypants_settings($format); + + case 'process': + return _smartypants_process($text, $format); + + default: + return $text; + } } } function marksmarty_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { - $blocks[0] = array('info' => t('Marksmarty Filter Tips')); + $blocks[0] = array('info' => t('Markdown Filter Tips')); return $blocks; } else if ($op == 'view') { @@ -47,7 +65,7 @@ function marksmarty_display_block_1(){ ### Header 3 ### #### Header 4 #### ##### Header 5 ##### -(Hashes on right are optional) +(Hashes on the right are optional) Link [Drupal](http://drupal.org) @@ -68,7 +86,7 @@ Inline markup like _italics_, And now some code: // Code is indented text is_easy() to_remember(); - + END_MARKSMARTY_BLOCK; return $content; @@ -111,62 +129,125 @@ function marksmarty_help($path = 'admin/ * Module Functions ********************************************************************/ -function _marksmarty_process($text, $format) { +function _markdown_process($text, $format) { require_once(dirname(__FILE__) .'/markdown.php'); - require_once(dirname(__FILE__) .'/smartypants.php'); - if (variable_get("marksmarty_is_markdown_on_$format", 1) == 1) { + + $filters = filter_list_format($format); + if (isset($filters['geshifilter/0'])) { + // geshi is activated! + // when geshi is called _after_ marksmarty we have to do some compliance stuff + $geshi_compliant = $filters['geshifilter/0']->weight > $filters['marksmarty/0']->weight; + } + + if ($geshi_compliant) { + // geshi prepares itself and replaces tags with a square bracket notation + // this can produce unwanted results with markdown + // revert it temporarily + $text = preg_replace('#\[geshifilter-(code(?: [^\]]*)?)\](.+)\[/geshifilter-code\]#Us', + 'geshi:$1|$2|code', $text); + $text = preg_replace('#\[geshifilter-(([a-z]+)(?: [^\]]*)?)\](.+)\[/geshifilter-\2\]#Us', + '
geshi:$1|$3|$2
', $text); + } + + if (variable_get("marksmarty_markdown_no_markup_$format", 0) == 1) { + // use special markdown parser to escape unwanted html tags + // we cannot use HTML filter module since then we'd either + // have to add all those html tags supported by markdown + // to its whitelist, or loose autolinks and blockquotes + require_once(dirname(__FILE__).'/no-markup_markdown.php'); + + $text = MarkdownWithoutMarkup($text, variable_get("marksmarty_markdown_allowed_html_$format", '')); + + $text = filter_xss_admin($text); + } else { + // default markdown parser $text = Markdown($text); } - if (variable_get("marksmarty_is_smarty_on_$format", 1) == 1) { - global $smartypants_attr; - $smartypants_attr = variable_get("marksmarty_smarty_hyphens_$format", 0) + 1; - $text = SmartyPants($text); + + if ($geshi_compliant) { + // redo what we reverted above so that the GeSHi module can do its work + $text = preg_replace('#geshi:(code(?: [^|]*)?)\|(.+)\|code#Us', + '[geshifilter-$1]$2[/geshifilter-code]', $text); + $text = preg_replace('#
geshi:(([a-z]+)(?: [^|]*)?)\|(.+)\|\2
#Us', + '[geshifilter-$1]$3[/geshifilter-$2]', $text); + // enable plaintext style for generic code blocks & spans + $text = str_replace( + array('
', '
', + '', ''), + array('[geshifilter-blockcode]', '[/geshifilter-blockcode]', + '[geshifilter-code]', '[/geshifilter-code]'), + $text); } + return $text; } -function _marksmarty_settings($format) { - require_once(dirname(__FILE__) .'/markdown.php'); +function _smartypants_process($text, $format) { require_once(dirname(__FILE__) .'/smartypants.php'); - $form['markdown_settings'] = array( + global $smartypants_attr; + $smartypants_attr = variable_get("marksmarty_smarty_hyphens_$format", 0) + 1; + $text = SmartyPants($text); + + return $text; +} + + +function _markdown_settings($format) { + require_once(dirname(__FILE__) .'/markdown.php'); + $form['markdown'] = array( '#type' => 'fieldset', - '#title' => t('Markdown with SmartyPants'), + '#title' => 'Markdown', '#collapsible' => TRUE, '#collapsed' => TRUE, ); - $form['markdown_settings']['help'] = array( + $form['markdown']['help'] = array( '#type' => 'markup', - '#value' => '

Please read the Markdown documentation for full details on its formatting syntax.

', + '#value' => '

'.t('Please read the Markdown documentation for full details on its formatting syntax.
+ You are using PHP Markdown Extra version !markdownextraversion, build upon PHP Markdown version !markdownversion.', + array( + '!markdownversion' => MARKDOWN_VERSION, + '!markdownextraversion' => MARKDOWNEXTRA_VERSION, + ) + ).'

', ); - $form['markdown_settings']["marksmarty_is_markdown_on_$format"] = array( + $form['markdown']["marksmarty_markdown_no_markup_$format"] = array( '#type' => 'select', - '#title' => t('Enable Markdown?'), - '#default_value' => variable_get("marksmarty_is_markdown_on_$format", 1), + '#title' => t('Disable HTML markup in Markdown?'), + '#default_value' => variable_get("marksmarty_markdown_no_markup_$format", 0), '#options' => array(0 => t('No'), 1 => t('Yes')), ); - $form['markdown_settings']["marksmarty_is_smarty_on_$format"] = array( - '#type' => 'select', - '#title' => t('Enable SmartyPants?'), - '#default_value' => variable_get("marksmarty_is_smarty_on_$format", 1), - '#options' => array(0 => t('No'), 1 => t('Yes')), + $form['markdown']["marksmarty_markdown_allowed_html_$format"] = array( + '#type' => 'textfield', + '#title' => t('HTML tag whitelist'), + '#description' => t('only applies when markup is disabled (see above)'), + '#default_value' => variable_get("marksmarty_markdown_allowed_html_$format", ''), ); - $form['markdown_settings']["marksmarty_smarty_hyphens_$format"] = array( + return $form; +} + +function _smartypants_settings($format) { + require_once(dirname(__FILE__) .'/smartypants.php'); + $form['smartypants'] = array( + '#type' => 'fieldset', + '#title' => 'SmartyPants', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['smartypants']['help'] = array( + '#type' => 'markup', + '#value' => '

'.t('You can read more about SmartyPants on the official project page.
+ You are using PHP SmartyPants version !phpsmartyversion, utilizing the !smartyversion syntax.', + array( + '!phpsmartyversion' => $GLOBALS['SmartyPantsPHPVersion'], + '!smartyversion' => $GLOBALS['SmartyPantsSyntaxVersion'], + ) + ).'

', + ); + $form['smartypants']["marksmarty_smarty_hyphens_$format"] = array( '#type' => 'select', '#title' => t('Hyphenation settings for SmartyPants'), '#default_value' => variable_get("marksmarty_smarty_hyphens_$format", 0), '#options' => array(0 => t('"--" for em-dashes; no en-dash support'), 1 => t('"---" for em-dashes; "--" for en-dashes'), 2 => t('"--" for em-dashes; "---" for en-dashes')), ); - - $links[] = 'Markdown PHP Version: '. MARKDOWN_VERSION .''; - $links[] .= 'Markdown Extra Version: '. MARKDOWNEXTRA_VERSION; - $links[] .= 'SmartyPants PHP Version: '. $GLOBALS['SmartyPantsPHPVersion'] .''; - $links[] .= 'SmartyPants Syntax Version: '. $GLOBALS['SmartyPantsSyntaxVersion']; - - $form['markdown_settings']['markdown_status'] = array( - '#title' => t('Versions'), - '#type' => 'item', - '#value' => theme('item_list', $links), - ); - return $form; } \ No newline at end of file