use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Model\Item;
+use Friendica\Util\XML;
/**
* Translates input text into different formats (HTML, BBCode, Markdown)
*/
class Babel extends BaseModule
{
- public static function content()
+ public static function content(array $parameters = [])
{
function visible_whitespace($s)
{
$results = [];
if (!empty($_REQUEST['text'])) {
- switch (defaults($_REQUEST, 'type', 'bbcode')) {
+ switch (($_REQUEST['type'] ?? '') ?: 'bbcode') {
case 'bbcode':
$bbcode = trim($_REQUEST['text']);
$results[] = [
$markdown = trim($_REQUEST['text']);
$results[] = [
'title' => L10n::t('Source input (Diaspora format)'),
- 'content' => '<pre>' . $markdown . '</pre>'
+ 'content' => '<pre>' . htmlspecialchars($markdown) . '</pre>'
];
- $html = Text\Markdown::convert($markdown);
+ $html = Text\Markdown::convert(html_entity_decode($markdown,ENT_COMPAT, 'UTF-8'));
$results[] = [
'title' => L10n::t('Markdown::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html))
'content' => $html
];
- $bbcode = Text\Markdown::toBBCode($markdown);
+ $bbcode = Text\Markdown::toBBCode(XML::unescape($markdown));
$results[] = [
'title' => L10n::t('Markdown::toBBCode'),
'content' => '<pre>' . $bbcode . '</pre>'
'content' => htmlspecialchars($html2)
];
+ $bbcode2plain = Text\BBCode::toPlaintext($bbcode);
+ $results[] = [
+ 'title' => L10n::t('HTML::toBBCode => BBCode::toPlaintext'),
+ 'content' => '<pre>' . $bbcode2plain . '</pre>'
+ ];
+
$markdown = Text\HTML::toMarkdown($html);
$results[] = [
'title' => L10n::t('HTML::toMarkdown'),
'content' => visible_whitespace($markdown)
];
- $text = Text\HTML::toPlaintext($html);
+ $text = Text\HTML::toPlaintext($html, 0);
$results[] = [
'title' => L10n::t('HTML::toPlaintext'),
'content' => '<pre>' . $text . '</pre>'
];
+
+ $text = Text\HTML::toPlaintext($html, 0, true);
+ $results[] = [
+ 'title' => L10n::t('HTML::toPlaintext (compact)'),
+ 'content' => '<pre>' . $text . '</pre>'
+ ];
}
}
$tpl = Renderer::getMarkupTemplate('babel.tpl');
$o = Renderer::replaceMacros($tpl, [
- '$text' => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
- '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
- '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
- '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
+ '$text' => ['text', L10n::t('Source text'), $_REQUEST['text'] ?? '', ''],
+ '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'bbcode'],
+ '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'markdown'],
+ '$type_html' => ['type', L10n::t('HTML'), 'html', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'html'],
'$results' => $results
]);