-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
71 lines (60 loc) · 2.16 KB
/
helper.php
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
<?php
/**
* DokuWiki Plugin LineBreak2; helper component
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Chris Smith <[email protected]>
* @author Satoshi Sahara <[email protected]>
*/
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define ('DOKU_LF',"\n");
class helper_plugin_linebreak2 extends DokuWiki_Plugin
{
protected $doc = ''; // output buffer
/**
* Flush and empty doc output buffer
*/
private function flush() {
$doc = '';
list($doc, $this->doc) = array($this->doc, $doc);
return $doc;
}
/**
* Return plain text data, instead of render them into $this->doc
*
* @param string $text the text to display
*/
public function cdata($text)
{
$html = hsc($text); // $this->_xmlEntities($text);
// get linebreak mode
$linebreak = $this->getConf('_linebreak', null) ?? $this->getConf('linebreak');
// BR mode: XHTML output with preserved linebreaks
if ($linebreak == 'br' || $linebreak == 'BR') {
$this->doc .= str_replace(DOKU_LF, '<br />', $html);
return $this->flush();
}
// Normal mode or scriptio continua
// CJK typesetting
// remove unnecessary spaces between any CJK characters
// caused by line feed (LF) in a multi-line paragraph
if ($this->getConf('cjk')) {
$cjk = '\p{Han}\p{Hiragana}\p{Katakana}\p{Hangul}';
$html = preg_replace('/(?<=['.$cjk.'])\n(?=['.$cjk.'])/u', '', $html);
}
// Markdown linebreak syntax
// force newline if found more than two spaces at the end of line
if ($this->getConf('markdown')) {
$html = preg_replace('/ {2,}\n/', '<br />', $html);
}
// scriptio continua: concatenate next line without word delimiting space
if ($linebreak == '') {
$this->doc .= str_replace(DOKU_LF, '', $html);
return $this->flush();
}
// Normal mode: identical with the standard xhml renderer
// leave line break chars as is
$this->doc .= $html;
return $this->flush();
}
}