You are here

markdown.module in Markdown 5

File

markdown.module
View source
<?php

// == Core hooks ===============================================================
function markdown_help($section = 'admin/help#markdown') {
  switch ($section) {
    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>');
      break;
  }
}

/**
 * Implementation of hook_filter().
 */
function markdown_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        t('Markdown'),
      );
    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;
  }
}

/**
 * Implementation of hook_block().
 *
 * Provides help for markdown syntax.
 */
function markdown_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      return array(
        'help' => array(
          'info' => t('Markdown filter tips'),
        ),
      );
    case 'view':
      switch ($delta) {
        case 'help':
          return array(
            'subject' => t('Markdown filter tips'),
            'content' => _markdown_help_block(),
          );
      }
  }
}

/**
 * Implementation of hook_filter_tips().
 */
function markdown_filter_tips($delta = 0, $format = -1, $long) {
  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/',
    ));
  }
}

// == Internal functions =======================================================

/**
 * 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 _markdown_process($text, $format) {
  if (!empty($text)) {
    include_once drupal_get_path('module', 'markdown') . '/markdown.php';
    $text = Markdown($text);
  }
  return $text;
}

/**
 * Filter settings callback. Just provides a version overview.
 */
function _markdown_settings($format) {
  include_once drupal_get_path('module', 'markdown') . '/markdown.php';
  $form['markdown_wrapper'] = array(
    '#type' => 'fieldset',
    '#title' => t('Markdown'),
  );
  $links = array(
    'Markdown PHP Version: <a href="http://www.michelf.com/projects/php-markdown/">' . MARKDOWN_VERSION . '</a>',
    'Markdown Extra Version: <a href="http://www.michelf.com/projects/php-markdown/">' . MARKDOWNEXTRA_VERSION . '</a>',
  );
  $form['markdown_wrapper']['markdown_status'] = array(
    '#title' => t('Versions'),
    '#type' => 'item',
    '#value' => theme('item_list', $links),
  );
  return $form;
}

Functions

Namesort descending Description
markdown_block Implementation of hook_block().
markdown_filter Implementation of hook_filter().
markdown_filter_tips Implementation of hook_filter_tips().
markdown_help
_markdown_help_block Provides content for the markdown help block.
_markdown_process Filter process callback.
_markdown_settings Filter settings callback. Just provides a version overview.