markdown.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/markdown/markdown.module

Functions & methods

NameDescription
markdown_blockImplementation of hook_block().
markdown_filterImplementation of hook_filter().
markdown_filter_tipsImplementation of hook_filter_tips().
markdown_help
_markdown_help_blockProvides content for the markdown help block.
_markdown_processFilter process callback.
_markdown_settingsFilter settings callback. Just provides a version overview.

File

View source
  1. <?php
  2. // == Core hooks ===============================================================
  3. function markdown_help($path = 'admin/help#markdown', $arg) {
  4. switch ($path) {
  5. case 'admin/help#markdown':
  6. 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>');
  7. break;
  8. }
  9. }
  10. /**
  11. * Implementation of hook_filter().
  12. */
  13. function markdown_filter($op, $delta = 0, $format = -1, $text = '') {
  14. switch ($op) {
  15. case 'list':
  16. return array(t('Markdown'));
  17. case 'description':
  18. return t('Allows content to be submitted using Markdown, a simple plain-text syntax that is filtered into valid XHTML.');
  19. case 'settings':
  20. return _markdown_settings($format);
  21. case 'process':
  22. return _markdown_process($text, $format);
  23. default:
  24. return $text;
  25. }
  26. }
  27. /**
  28. * Implementation of hook_block().
  29. *
  30. * Provides help for markdown syntax.
  31. */
  32. function markdown_block($op = 'list', $delta = 0, $edit = array()) {
  33. switch($op) {
  34. case 'list':
  35. return array('help' => array('info' => t('Markdown filter tips')));
  36. case 'view':
  37. switch($delta) {
  38. case 'help':
  39. return array(
  40. 'subject' => t('Markdown filter tips'),
  41. 'content' => _markdown_help_block()
  42. );
  43. }
  44. }
  45. }
  46. /**
  47. * Implementation of hook_filter_tips().
  48. */
  49. function markdown_filter_tips($delta = 0, $format = -1, $long) {
  50. if ($long) {
  51. return t('Quick Tips:<ul>
  52. <li>Two or more spaces at a line\'s end = Line break</li>
  53. <li>Double returns = Paragraph</li>
  54. <li>*Single asterisks* or _single underscores_ = <em>Emphasis</em></li>
  55. <li>**Double** or __double__ = <strong>Strong</strong></li>
  56. <li>This is [a link](http://the.link.example.com "The optional title text")</li>
  57. </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.');
  58. }
  59. else {
  60. 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/'));
  61. }
  62. }
  63. // == Internal functions =======================================================
  64. /**
  65. * Provides content for the markdown help block.
  66. */
  67. function _markdown_help_block(){
  68. return '<pre>'. t("
  69. ## Header 2 ##
  70. ### Header 3 ###
  71. #### Header 4 ####
  72. ##### Header 5 #####
  73. (Hashes on right are optional)
  74. Link [Drupal](http://drupal.org)
  75. Inline markup like _italics_,
  76. **bold**, and `code()`.
  77. > Blockquote. Like email replies
  78. >> And, they can be nested
  79. * Bullet lists are easy too
  80. - Another one
  81. + Another one
  82. 1. A numbered list
  83. 2. Which is numbered
  84. 3. With periods and a space
  85. And now some code:
  86. // Code is indented text
  87. is_easy() to_remember();") .'</pre>';
  88. }
  89. /**
  90. * Filter process callback.
  91. */
  92. function _markdown_process($text, $format) {
  93. if (!empty($text)) {
  94. include_once drupal_get_path('module', 'markdown') .'/markdown.php';
  95. $text = Markdown($text);
  96. }
  97. return $text;
  98. }
  99. /**
  100. * Filter settings callback. Just provides a version overview.
  101. */
  102. function _markdown_settings($format) {
  103. include_once drupal_get_path('module', 'markdown') .'/markdown.php';
  104. $form['markdown_wrapper'] = array(
  105. '#type' => 'fieldset',
  106. '#title' => t('Markdown'),
  107. );
  108. $links = array(
  109. 'Markdown PHP Version: <a href="http://www.michelf.com/projects/php-markdown/">'. MARKDOWN_VERSION .'</a>',
  110. 'Markdown Extra Version: <a href="http://www.michelf.com/projects/php-markdown/">'. MARKDOWNEXTRA_VERSION .'</a>',
  111. );
  112. $form['markdown_wrapper']['markdown_status'] = array(
  113. '#title' => t('Versions'),
  114. '#type' => 'item',
  115. '#value' => theme('item_list', $links),
  116. );
  117. return $form;
  118. }