-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueueit.inc
More file actions
29 lines (27 loc) · 842 Bytes
/
queueit.inc
File metadata and controls
29 lines (27 loc) · 842 Bytes
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
<?php
/**
* @file
* Queue-it module's include file.
*/
/**
* Helper function to convert Markdown text into HTML.
*/
function queueit_md2html($content) {
// Convert new lines into <br>.
$content = nl2br($content, FALSE);
// Format code.
$content = preg_replace('/`(.*?)`/s', '<code>\1</code>', $content);
// Convert links.
$content = preg_replace('/\[([^\[]+)\]\(([^\)]+)\)/', '<a href=\'\2\'>\1</a>', $content);
// Convert headers.
$content = preg_replace('/\n?(.*)\n=+/', '<h1>\1</h1>', $content);
$content = preg_replace_callback('/\n(#+)(.*)/',
function ($regs) {
list(, $chars, $header) = $regs;
return sprintf('<h%d>%s</h%d>', strlen($chars), trim($header), strlen($chars));
},
$content);
// Remove not needed characters.
$content = strtr($content, ['=' => '']);
return $content;
}