6 use Friendica\Content\Text;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
10 function visible_whitespace($s)
12 $s = str_replace(' ', ' ', $s);
14 return str_replace(["\r\n", "\n", "\r"], '<br />', $s);
17 function babel_content()
20 if (!empty($_REQUEST['text'])) {
21 switch (defaults($_REQUEST, 'type', 'bbcode')) {
23 $bbcode = trim($_REQUEST['text']);
25 'title' => L10n::t('Source input'),
26 'content' => visible_whitespace($bbcode)
29 $plain = Text\BBCode::toPlaintext($bbcode, false);
31 'title' => L10n::t('BBCode::toPlaintext'),
32 'content' => visible_whitespace($plain)
35 $html = Text\BBCode::convert($bbcode);
37 'title' => L10n::t('BBCode::convert (raw HTML)'),
38 'content' => visible_whitespace(htmlspecialchars($html))
42 'title' => L10n::t('BBCode::convert'),
46 $bbcode2 = Text\HTML::toBBCode($html);
48 'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
49 'content' => visible_whitespace($bbcode2)
52 $markdown = Text\BBCode::toMarkdown($bbcode);
54 'title' => L10n::t('BBCode::toMarkdown'),
55 'content' => visible_whitespace($markdown)
58 $html2 = Text\Markdown::convert($markdown);
60 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
64 $bbcode3 = Text\Markdown::toBBCode($markdown);
66 'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
67 'content' => visible_whitespace($bbcode3)
70 $bbcode4 = Text\HTML::toBBCode($html2);
72 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode'),
73 'content' => visible_whitespace($bbcode4)
77 $markdown = trim($_REQUEST['text']);
79 'title' => L10n::t('Source input (Diaspora format)'),
80 'content' => '<pre>' . $markdown . '</pre>'
83 $html = Text\Markdown::convert($markdown);
85 'title' => L10n::t('Markdown::convert (raw HTML)'),
86 'content' => htmlspecialchars($html)
90 'title' => L10n::t('Markdown::convert'),
94 $bbcode = Text\Markdown::toBBCode($markdown);
96 'title' => L10n::t('Markdown::toBBCode'),
97 'content' => '<pre>' . $bbcode . '</pre>'
101 $html = trim($_REQUEST['text']);
103 'title' => L10n::t('Raw HTML input'),
104 'content' => htmlspecialchars($html)
108 'title' => L10n::t('HTML Input'),
112 $bbcode = Text\HTML::toBBCode($html);
114 'title' => L10n::t('HTML::toBBCode'),
115 'content' => visible_whitespace($bbcode)
118 $html2 = Text\BBCode::convert($bbcode);
120 'title' => L10n::t('HTML::toBBCode => BBCode::convert'),
125 'title' => L10n::t('HTML::toBBCode => BBCode::convert (raw HTML)'),
126 'content' => htmlspecialchars($html2)
129 $markdown = Text\HTML::toMarkdown($html);
131 'title' => L10n::t('HTML::toMarkdown'),
132 'content' => visible_whitespace($markdown)
135 $text = Text\HTML::toPlaintext($html);
137 'title' => L10n::t('HTML::toPlaintext'),
138 'content' => '<pre>' . $text . '</pre>'
143 $tpl = Renderer::getMarkupTemplate('babel.tpl');
144 $o = Renderer::replaceMacros($tpl, [
145 '$text' => ['text', L10n::t('Source text'), htmlentities(defaults($_REQUEST, 'text', '')), ''],
146 '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
147 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
148 '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
149 '$results' => $results