markdown.module in Markdown 7.2
Same filename and directory in other branches
Provides a Markdown input filter.
File
markdown.moduleView source
<?php
/**
* @file
* Provides a Markdown input filter.
*/
/**
* Implements hook_help().
*/
function markdown_help($path, $arg) {
switch ($path) {
case 'admin/help#markdown':
return t('<p>The Markdown filter 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.</p>');
}
}
/**
* Implements hook_filter_info().
*/
function markdown_filter_info() {
$filters['filter_markdown'] = array(
'title' => t('Markdown'),
'description' => t('Allows content to be submitted using Markdown, a simple plain-text syntax that is filtered into valid XHTML.'),
'process callback' => '_filter_markdown',
'settings callback' => '_filter_markdown_settings',
'tips callback' => '_filter_markdown_tips',
);
return $filters;
}
/**
* Implements hook_libraries_info().
*/
function markdown_libraries_info() {
$libraries['markdown'] = array(
'name' => 'Markdown PHP plugin',
'vendor url' => 'https://michelf.ca/projects/php-markdown/',
'download url' => 'https://littoral.michelf.ca/code/php-markdown/php-markdown-lib-1.5.0.zip',
'path' => 'Michelf',
'version arguments' => array(
'file' => 'Readme.md',
'pattern' => '/PHP Markdown Lib (\\d+\\.\\d+.\\d+)/',
'lines' => 4,
),
'files' => array(
'php' => array(
'MarkdownInterface.php',
'Markdown.php',
'MarkdownExtra.php',
),
),
);
return $libraries;
}
/**
* Returns the markdown input filter tips.
* @TODO: make it easier for translators.
*/
function _filter_markdown_tips($format, $long = FALSE) {
if ($long) {
return t('Quick Tips:<ul>
<li>Two or more spaces at a line\'s end = Line break</li>
<li>Double returns = Paragraph</li>
<li>*Single asterisks* or _single underscores_ = <em>Emphasis</em></li>
<li>**Double** or __double__ = <strong>Strong</strong></li>
<li>This is [a link](http://the.link.example.com "The optional title text")</li>
</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.');
}
else {
return t('You can use <a href="@filter_tips">Markdown syntax</a> to format and style the text. Also see <a href="@markdown_extra">Markdown Extra</a> for tables, footnotes, and more.', array(
'@filter_tips' => url('filter/tips'),
'@markdown_extra' => 'http://michelf.com/projects/php-markdown/extra/',
));
}
}
/**
* Implements hook_block_view().
*/
function markdown_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'markdown_help':
$block['title'] = t('Markdown filter tips');
$block['content'] = _markdown_help_block();
break;
}
return $block;
}
/**
* Implements hook_block_info().
*/
function markdown_block_info() {
$blocks = array();
$blocks['markdown_help'] = array(
'info' => t('Markdown filter tips'),
);
return $blocks;
}
/**
* Provides content for the markdown help block.
*/
function _markdown_help_block() {
return '<pre>' . t("\n## Header 2 ##\n### Header 3 ###\n#### Header 4 ####\n##### Header 5 #####\n(Hashes on right are optional)\n\nLink [Drupal](http://drupal.org)\n\nInline markup like _italics_,\n **bold**, and `code()`.\n\n> Blockquote. Like email replies\n>> And, they can be nested\n\n* Bullet lists are easy too\n- Another one\n+ Another one\n\n1. A numbered list\n2. Which is numbered\n3. With periods and a space\n\nAnd now some code:\n // Code is indented text\n is_easy() to_remember();") . '</pre>';
}
/**
* Filter process callback.
*/
function _filter_markdown($text, $format) {
if (empty($text)) {
return $text;
}
if (($library = libraries_load('markdown')) && !empty($library['loaded'])) {
$text = Michelf\MarkdownExtra::defaultTransform($text);
}
else {
$href = url(drupal_get_path('module', 'markdown') . '/README.txt');
drupal_set_message(t('Missing Markdown library. Read installation section in <a href="@href">README.txt</a> file.', array(
'@href' => $href,
)), 'error', FALSE);
}
return $text;
}
/**
* Filter settings callback. Just provides a version overview.
*/
function _filter_markdown_settings($form, &$form_state, $filter, $format, $defaults) {
$settings['markdown_wrapper'] = array(
'#type' => 'fieldset',
'#title' => t('Markdown'),
);
// Try to load the library and check if that worked.
if (($library = libraries_load('markdown')) && !empty($library['loaded'])) {
$links = array(
'Markdown PHP Version: <a href="http://michelf.com/projects/php-markdown/">' . $library['version'] . '</a>',
);
$settings['markdown_wrapper']['markdown_status'] = array(
'#title' => t('Versions'),
'#type' => 'item',
'#markup' => theme('item_list', array(
'items' => $links,
)),
);
}
else {
$href = url(drupal_get_path('module', 'markdown') . '/README.txt');
drupal_set_message(t('Missing Markdown library. Read installation section in <a href="@href">README.txt</a> file.', array(
'@href' => $href,
)), 'error', FALSE);
}
return $settings;
}
Functions
Name | Description |
---|---|
markdown_block_info | Implements hook_block_info(). |
markdown_block_view | Implements hook_block_view(). |
markdown_filter_info | Implements hook_filter_info(). |
markdown_help | Implements hook_help(). |
markdown_libraries_info | Implements hook_libraries_info(). |
_filter_markdown | Filter process callback. |
_filter_markdown_settings | Filter settings callback. Just provides a version overview. |
_filter_markdown_tips | Returns the markdown input filter tips. @TODO: make it easier for translators. |
_markdown_help_block | Provides content for the markdown help block. |