-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparsedown_filter.module
145 lines (125 loc) · 3.47 KB
/
parsedown_filter.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* @file
* Provides a Markdown Extra input filter.
*/
/**
* Implements hook_filter_info().
*/
function parsedown_filter_filter_info() {
$filters['filter_parsedown_filter'] = array(
'title' => t('Parsedown'),
'description' => t('Allows content to be submitted using Markdown , a simple plain-text syntax that is filtered into valid XHTML.'),
'process callback' => '_filter_parsedown_filter',
'settings callback' => '_filter_parsedown_settings',
'tips callback' => '_filter_parsedown_filter_tips',
);
return $filters;
}
/**
* Implements hook_autoload_info().
*/
function parsedown_filter_autoload_info() {
return array(
'Parsedown' => 'libraries/Parsedown/Parsedown.php',
'ParsedownExtra' => 'libraries/ParsedownExtra/ParsedownExtra.php',
);
}
/**
* Returns the parsedown_filter input filter tips.
*/
function _filter_parsedown_filter_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>
<li>This is a image ![alt](http://the.link.example.com/example.png)</li>
</ul>');
}
else {
return t('You can use <a href="@filter_tips">Markdown syntax</a> to format and style the text.');
}
}
/**
* Implements callback_filter_settings().
*
* Filter settings callback for the Markdown content filter.
*/
function _filter_parsedown_settings($form, &$form_state, $filter, $format) {
$settings['filter_parsedown_extra'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Markdown Extra'),
'#default_value' => isset($filter->settings['filter_parsedown_extra']) ? $filter->settings['filter_parsedown_extra'] : FALSE,
);
return $settings;
}
/**
* Implements hook_block_view().
*/
function parsedown_filter_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'parsedown_filter_help':
$block['title'] = t('Markdown filter tips');
$block['content'] = _parsedown_filter_help_block();
break;
}
return $block;
}
/**
* Implements hook_block_info().
*/
function parsedown_filter_block_info() {
$blocks = array();
$blocks['parsedown_filter_help'] = array(
'info' => t('Markdown filter tips'),
);
return $blocks;
}
/**
* Provides content for the parsedown_filter help block.
*/
function _parsedown_filter_help_block() {
return '<pre>' . t("
## Header 2 ##
### Header 3 ###
#### Header 4 ####
##### Header 5 #####
(Hashes on right are optional)
Link [Backdrop CMS](https://backdropcms.org/)
Inline markup like _italics_,
**bold**, and `code()`.
> Blockquote. Like email replies
>> And, they can be nested
* Bullet lists are easy too
- Another one
+ Another one
1. A numbered list
2. Which is numbered
3. With periods and a space
And now some code:
```php
phpinfo();
```") . '</pre>';
}
/**
* Implements callback_filter_process().
*
* Provides filtering of input into accepted HTML based on Markdown syntax.
*/
function _filter_parsedown_filter($text, $filter) {
if (!empty($text)) {
if ($filter->settings['filter_parsedown_extra']) {
$Extra = new ParsedownExtra();
$text = $Extra->text($text);
}
else {
$Parsedown = new Parsedown();
$text = $Parsedown->text($text);
}
}
return $text;
}