6 use Friendica\Content\Text;
7 use Friendica\Core\L10n;
9 function visible_whitespace($s)
11 $s = str_replace(' ', ' ', $s);
13 return str_replace(["\r\n", "\n", "\r"], '<br />', $s);
16 function babel_content()
19 if (!empty($_REQUEST['text'])) {
20 switch (defaults($_REQUEST, 'type', 'bbcode')) {
22 $bbcode = trim($_REQUEST['text']);
24 'title' => L10n::t('Source input'),
25 'content' => visible_whitespace($bbcode)
28 $plain = Text\BBCode::toPlaintext($bbcode, false);
30 'title' => L10n::t('BBCode::toPlaintext'),
31 'content' => visible_whitespace($plain)
34 $html = Text\BBCode::convert($bbcode);
36 'title' => L10n::t('BBCode::convert (raw HTML)'),
37 'content' => visible_whitespace(htmlspecialchars($html))
41 'title' => L10n::t('BBCode::convert'),
45 $bbcode2 = Text\HTML::toBBCode($html);
47 'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
48 'content' => visible_whitespace($bbcode2)
51 $markdown = Text\BBCode::toMarkdown($bbcode);
53 'title' => L10n::t('BBCode::toMarkdown'),
54 'content' => visible_whitespace($markdown)
57 $html2 = Text\Markdown::convert($markdown);
59 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
63 $bbcode3 = Text\Markdown::toBBCode($markdown);
65 'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
66 'content' => visible_whitespace($bbcode3)
69 $bbcode4 = Text\HTML::toBBCode($html2);
71 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode'),
72 'content' => visible_whitespace($bbcode4)
76 $markdown = trim($_REQUEST['text']);
78 'title' => L10n::t('Source input (Diaspora format)'),
79 'content' => '<pre>' . $markdown . '</pre>'
82 $html = Text\Markdown::convert($markdown);
84 'title' => L10n::t('Markdown::convert (raw HTML)'),
85 'content' => htmlspecialchars($html)
89 'title' => L10n::t('Markdown::convert'),
93 $bbcode = Text\Markdown::toBBCode($markdown);
95 'title' => L10n::t('Markdown::toBBCode'),
96 'content' => '<pre>' . $bbcode . '</pre>'
100 $html = trim($_REQUEST['text']);
102 'title' => L10n::t('Raw HTML input'),
103 'content' => htmlspecialchars($html)
107 'title' => L10n::t('HTML Input'),
111 $bbcode = Text\HTML::toBBCode($html);
113 'title' => L10n::t('HTML::toBBCode'),
114 'content' => visible_whitespace($bbcode)
117 $html2 = Text\BBCode::convert($bbcode);
119 'title' => L10n::t('HTML::toBBCode => BBCode::convert'),
124 'title' => L10n::t('HTML::toBBCode => BBCode::convert (raw HTML)'),
125 'content' => htmlspecialchars($html2)
128 $markdown = Text\HTML::toMarkdown($html);
130 'title' => L10n::t('HTML::toMarkdown'),
131 'content' => visible_whitespace($markdown)
134 $text = Text\HTML::toPlaintext($html);
136 'title' => L10n::t('HTML::toPlaintext'),
137 'content' => '<pre>' . $text . '</pre>'
142 $tpl = get_markup_template('babel.tpl');
143 $o = replace_macros($tpl, [
144 '$text' => ['text', L10n::t('Source text'), htmlentities(defaults($_REQUEST, 'text', '')), ''],
145 '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
146 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
147 '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
148 '$results' => $results