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)
81 \Friendica\Model\Item::setHashtags($item);
83 'title' => L10n::t('Item Body'),
84 'content' => visible_whitespace($item['body'])
87 'title' => L10n::t('Item Tags'),
88 'content' => $item['tag']
92 $markdown = trim($_REQUEST['text']);
94 'title' => L10n::t('Source input (Diaspora format)'),
95 'content' => '<pre>' . $markdown . '</pre>'
98 $html = Text\Markdown::convert($markdown);
100 'title' => L10n::t('Markdown::convert (raw HTML)'),
101 'content' => visible_whitespace(htmlspecialchars($html))
105 'title' => L10n::t('Markdown::convert'),
109 $bbcode = Text\Markdown::toBBCode($markdown);
111 'title' => L10n::t('Markdown::toBBCode'),
112 'content' => '<pre>' . $bbcode . '</pre>'
116 $html = trim($_REQUEST['text']);
118 'title' => L10n::t('Raw HTML input'),
119 'content' => htmlspecialchars($html)
123 'title' => L10n::t('HTML Input'),
127 $bbcode = Text\HTML::toBBCode($html);
129 'title' => L10n::t('HTML::toBBCode'),
130 'content' => visible_whitespace($bbcode)
133 $html2 = Text\BBCode::convert($bbcode);
135 'title' => L10n::t('HTML::toBBCode => BBCode::convert'),
140 'title' => L10n::t('HTML::toBBCode => BBCode::convert (raw HTML)'),
141 'content' => htmlspecialchars($html2)
144 $markdown = Text\HTML::toMarkdown($html);
146 'title' => L10n::t('HTML::toMarkdown'),
147 'content' => visible_whitespace($markdown)
150 $text = Text\HTML::toPlaintext($html);
152 'title' => L10n::t('HTML::toPlaintext'),
153 'content' => '<pre>' . $text . '</pre>'
158 $tpl = Renderer::getMarkupTemplate('babel.tpl');
159 $o = Renderer::replaceMacros($tpl, [
160 '$text' => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
161 '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
162 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
163 '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
164 '$results' => $results