| 1 |
<?php
|
| 2 |
// $Id: marksmarty.module,v 1.21 2008/01/22 22:25:27 weitzman Exp $
|
| 3 |
|
| 4 |
/********************************************************************
|
| 5 |
* Drupal Hooks
|
| 6 |
********************************************************************/
|
| 7 |
|
| 8 |
function marksmarty_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 9 |
switch ($op) {
|
| 10 |
case 'list':
|
| 11 |
return array(t('Markdown with SmartyPants'));
|
| 12 |
|
| 13 |
case 'description':
|
| 14 |
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.');
|
| 15 |
|
| 16 |
case 'settings':
|
| 17 |
return _marksmarty_settings($format);
|
| 18 |
|
| 19 |
case 'process':
|
| 20 |
return _marksmarty_process($text, $format);
|
| 21 |
|
| 22 |
default:
|
| 23 |
return $text;
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
function marksmarty_block($op = 'list', $delta = 0, $edit = array()) {
|
| 28 |
if ($op == 'list') {
|
| 29 |
$blocks[0] = array('info' => t('Marksmarty Filter Tips'));
|
| 30 |
return $blocks;
|
| 31 |
}
|
| 32 |
else if ($op == 'view') {
|
| 33 |
switch($delta) {
|
| 34 |
case 0:
|
| 35 |
$block = array('subject' => t('Title of block #1'),
|
| 36 |
'content' => marksmarty_display_block_1());
|
| 37 |
break;
|
| 38 |
}
|
| 39 |
return $block;
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
function marksmarty_display_block_1(){
|
| 44 |
$content = <<<END_MARKSMARTY_BLOCK
|
| 45 |
<pre>
|
| 46 |
## Header 2 ##
|
| 47 |
### Header 3 ###
|
| 48 |
#### Header 4 ####
|
| 49 |
##### Header 5 #####
|
| 50 |
(Hashes on right are optional)
|
| 51 |
|
| 52 |
Link [Drupal](http://drupal.org)
|
| 53 |
|
| 54 |
Inline markup like _italics_,
|
| 55 |
**bold**, and `code()`.
|
| 56 |
|
| 57 |
> Blockquote. Like email replies
|
| 58 |
>> And, they can be nested
|
| 59 |
|
| 60 |
* Bullet lists are easy too
|
| 61 |
- Another one
|
| 62 |
+ Another one
|
| 63 |
|
| 64 |
1. A numbered list
|
| 65 |
2. Which is numbered
|
| 66 |
3. With periods and a space
|
| 67 |
|
| 68 |
And now some code:
|
| 69 |
// Code is indented text
|
| 70 |
is_easy() to_remember();
|
| 71 |
</pre>
|
| 72 |
END_MARKSMARTY_BLOCK;
|
| 73 |
|
| 74 |
return $content;
|
| 75 |
|
| 76 |
}
|
| 77 |
|
| 78 |
function marksmarty_filter_tips($delta = 0, $format = -1, $long) {
|
| 79 |
if ($long) {
|
| 80 |
$the_output = t('Quick Tips:<ul>
|
| 81 |
<li>Two or more spaces at a line\'s end = Line break</li>
|
| 82 |
<li>Double returns = Paragraph</li>
|
| 83 |
<li>*Single asterisks* or _single underscores_ = <em>Emphasis</em></li>
|
| 84 |
<li>**Double** or __double__ = <strong>Strong</strong></li>
|
| 85 |
<li>This is [a link](http://the.link.com "The optional title text")</li>
|
| 86 |
</ul>For complete details on the Markdown syntax, see the <a href="http://daringfireball.net/projects/markdown/syntax">Markdown documentation</a> and <a href="http://michelf.com/projects/php-markdown/extra/">Markdown Extra documentation</a> for tables, footnotes, and more.');
|
| 87 |
}
|
| 88 |
else {
|
| 89 |
$the_output = t('You can use !link to format and style the text. Also see and <a href="http://michelf.com/projects/php-markdown/extra/">Markdown Extra</a> for tables, footnotes, and more.', array('!link' => l(t('Markdown syntax'), 'filter/tips')));
|
| 90 |
}
|
| 91 |
|
| 92 |
return $the_output;
|
| 93 |
}
|
| 94 |
|
| 95 |
function marksmarty_help($path = 'admin/help#marksmarty', $arg) {
|
| 96 |
switch ($path) {
|
| 97 |
case 'admin/settings/modules#description':
|
| 98 |
$the_output = t('Allows content to be submitted using Markdown, a simple plain-text syntax that is transformed into valid XHTML, and/or using SmartyPants, a filter for auto-translating plain ASCII characters to Unicode characters.');
|
| 99 |
break;
|
| 100 |
|
| 101 |
case 'admin/help#marksmarty':
|
| 102 |
$the_output = t('<p>The Markdown with SmartyPants module allows you to enter content using <a href="http://daringfireball.net/projects/markdown">Markdown</a>, a simple plain-text syntax that is transformed into valid XHTML, and will automatically convert plain ASCII characters to their proper Unicode entities in context ("curly quotes," et al.) using <a href="http://daringfireball.net/projects/smartypants">SmartyPants</a>.</p>');
|
| 103 |
break;
|
| 104 |
}
|
| 105 |
if (isset($the_output)) {
|
| 106 |
return $the_output;
|
| 107 |
}
|
| 108 |
}
|
| 109 |
|
| 110 |
/********************************************************************
|
| 111 |
* Module Functions
|
| 112 |
********************************************************************/
|
| 113 |
|
| 114 |
function _marksmarty_process($text, $format) {
|
| 115 |
if (!empty($text) && variable_get("marksmarty_is_markdown_on_$format", 1) == 1) {
|
| 116 |
require_once(dirname(__FILE__) .'/markdown.php');
|
| 117 |
$text = Markdown($text);
|
| 118 |
}
|
| 119 |
if (!empty($text) && variable_get("marksmarty_is_smarty_on_$format", 1) == 1) {
|
| 120 |
global $smartypants_attr;
|
| 121 |
require_once(dirname(__FILE__) .'/smartypants.php');
|
| 122 |
|
| 123 |
$smartypants_attr = variable_get("marksmarty_smarty_hyphens_$format", 0) + 1;
|
| 124 |
$text = SmartyPants($text);
|
| 125 |
}
|
| 126 |
return $text;
|
| 127 |
}
|
| 128 |
|
| 129 |
function _marksmarty_settings($format) {
|
| 130 |
require_once(dirname(__FILE__) .'/markdown.php');
|
| 131 |
require_once(dirname(__FILE__) .'/smartypants.php');
|
| 132 |
$form['markdown_settings'] = array(
|
| 133 |
'#type' => 'fieldset',
|
| 134 |
'#title' => t('Markdown with SmartyPants'),
|
| 135 |
'#collapsible' => TRUE,
|
| 136 |
'#collapsed' => TRUE,
|
| 137 |
);
|
| 138 |
$form['markdown_settings']['help'] = array(
|
| 139 |
'#type' => 'markup',
|
| 140 |
'#value' => '<p>Please read the <a href="http://daringfireball.net/projects/markdown/syntax">Markdown documentation</a> for full details on its formatting syntax.</p>',
|
| 141 |
);
|
| 142 |
$form['markdown_settings']["marksmarty_is_markdown_on_$format"] = array(
|
| 143 |
'#type' => 'select',
|
| 144 |
'#title' => t('Enable Markdown?'),
|
| 145 |
'#default_value' => variable_get("marksmarty_is_markdown_on_$format", 1),
|
| 146 |
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
| 147 |
);
|
| 148 |
$form['markdown_settings']["marksmarty_is_smarty_on_$format"] = array(
|
| 149 |
'#type' => 'select',
|
| 150 |
'#title' => t('Enable SmartyPants?'),
|
| 151 |
'#default_value' => variable_get("marksmarty_is_smarty_on_$format", 1),
|
| 152 |
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
| 153 |
);
|
| 154 |
$form['markdown_settings']["marksmarty_smarty_hyphens_$format"] = array(
|
| 155 |
'#type' => 'select',
|
| 156 |
'#title' => t('Hyphenation settings for SmartyPants'),
|
| 157 |
'#default_value' => variable_get("marksmarty_smarty_hyphens_$format", 0),
|
| 158 |
'#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')),
|
| 159 |
);
|
| 160 |
|
| 161 |
$links[] = 'Markdown PHP Version: <a href="http://www.michelf.com/projects/php-markdown/">'. MARKDOWN_VERSION .'</a>';
|
| 162 |
$links[] .= 'Markdown Extra Version: '. MARKDOWNEXTRA_VERSION;
|
| 163 |
$links[] .= 'SmartyPants PHP Version: <a href="http://www.michelf.com/projects/php-smartypants/">'. $GLOBALS['SmartyPantsPHPVersion'] .'</a>';
|
| 164 |
$links[] .= 'SmartyPants Syntax Version: '. $GLOBALS['SmartyPantsSyntaxVersion'];
|
| 165 |
|
| 166 |
$form['markdown_settings']['markdown_status'] = array(
|
| 167 |
'#title' => t('Versions'),
|
| 168 |
'#type' => 'item',
|
| 169 |
'#value' => theme('item_list', $links),
|
| 170 |
);
|
| 171 |
|
| 172 |
return $form;
|
| 173 |
}
|