6 use Friendica\Content\Text;
7 use Friendica\Core\L10n;
9 function visible_lf($s)
11 return str_replace("\n", '<br />', $s);
14 function babel_content()
17 if (!empty($_REQUEST['text'])) {
18 switch (defaults($_REQUEST, 'type', 'bbcode')) {
20 $bbcode = trim($_REQUEST['text']);
22 'title' => L10n::t('Source input'),
23 'content' => visible_lf($bbcode)
26 $plain = Text\BBCode::toPlaintext($bbcode, false);
28 'title' => L10n::t('BBCode::toPlaintext'),
29 'content' => visible_lf($plain)
32 $html = Text\BBCode::convert($bbcode);
34 'title' => L10n::t("BBCode::convert \x28raw HTML\x29"),
35 'content' => htmlspecialchars($html)
39 'title' => L10n::t('BBCode::convert'),
43 $bbcode2 = Text\HTML::toBBCode($html);
45 'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
46 'content' => visible_lf($bbcode2)
49 $markdown = Text\BBCode::toMarkdown($bbcode);
51 'title' => L10n::t('BBCode::toMarkdown'),
52 'content' => visible_lf($markdown)
55 $html2 = Text\Markdown::convert($markdown);
57 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
61 $bbcode3 = Text\Markdown::toBBCode($markdown);
63 'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
64 'content' => visible_lf($bbcode3)
67 $bbcode4 = Text\HTML::toBBCode($html2);
69 'title' => L10n::t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode'),
70 'content' => visible_lf($bbcode4)
74 $markdown = trim($_REQUEST['text']);
76 'title' => L10n::t('Source input \x28Diaspora format\x29'),
77 'content' => '<pre>' . $markdown . '</pre>'
80 $bbcode = Text\Markdown::toBBCode($markdown);
82 'title' => L10n::t('Markdown::toBBCode'),
83 'content' => '<pre>' . $bbcode . '</pre>'
87 $html = trim($_REQUEST['text']);
89 'title' => L10n::t("Raw HTML input"),
90 'content' => htmlspecialchars($html)
94 'title' => L10n::t('HTML Input'),
98 $bbcode = Text\HTML::toBBCode($html);
100 'title' => L10n::t('HTML::toBBCode'),
101 'content' => visible_lf($bbcode)
104 $text = Text\HTML::toPlaintext($html);
106 'title' => L10n::t('HTML::toPlaintext'),
107 'content' => '<pre>' . $text . '</pre>'
112 $tpl = get_markup_template('babel.tpl');
113 $o = replace_macros($tpl, [
114 '$text' => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
115 '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
116 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
117 '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
118 '$results' => $results