Merge remote-tracking branch 'upstream/2020.03-rc' into acessible-pictures

This commit is contained in:
Michael 2020-03-12 09:31:52 +00:00
commit 5479321550
10 changed files with 67 additions and 33 deletions

View file

@ -109,8 +109,6 @@ class Markdown
*/ */
public static function toBBCode($s) public static function toBBCode($s)
{ {
$s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
// The parser cannot handle paragraphs correctly // The parser cannot handle paragraphs correctly
$s = str_replace(['</p>', '<p>', '<p dir="ltr">'], ['<br>', '<br>', '<br>'], $s); $s = str_replace(['</p>', '<p>', '<p dir="ltr">'], ['<br>', '<br>', '<br>'], $s);

View file

@ -37,9 +37,7 @@ class Babel extends BaseModule
{ {
function visible_whitespace($s) function visible_whitespace($s)
{ {
$s = str_replace(' ', '&nbsp;', $s); return '<pre>' . htmlspecialchars($s) . '</pre>';
return str_replace(["\r\n", "\n", "\r"], '<br />', $s);
} }
$results = []; $results = [];
@ -61,7 +59,7 @@ class Babel extends BaseModule
$html = Text\BBCode::convert($bbcode); $html = Text\BBCode::convert($bbcode);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('BBCode::convert (raw HTML)'), 'title' => DI::l10n()->t('BBCode::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html)) 'content' => visible_whitespace($html)
]; ];
$results[] = [ $results[] = [
@ -78,13 +76,13 @@ class Babel extends BaseModule
$markdown = Text\BBCode::toMarkdown($bbcode); $markdown = Text\BBCode::toMarkdown($bbcode);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('BBCode::toMarkdown'), 'title' => DI::l10n()->t('BBCode::toMarkdown'),
'content' => visible_whitespace(htmlspecialchars($markdown)) 'content' => visible_whitespace($markdown)
]; ];
$html2 = Text\Markdown::convert($markdown); $html2 = Text\Markdown::convert($markdown);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert (raw HTML)'), 'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html2)) 'content' => visible_whitespace($html2)
]; ];
$results[] = [ $results[] = [
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert'), 'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert'),
@ -118,17 +116,28 @@ class Babel extends BaseModule
'content' => $item['tag'] 'content' => $item['tag']
]; ];
break; break;
case 'markdown': case 'diaspora':
$markdown = trim($_REQUEST['text']); $diaspora = trim($_REQUEST['text']);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('Source input (Diaspora format)'), 'title' => DI::l10n()->t('Source input (Diaspora format)'),
'content' => '<pre>' . htmlspecialchars($markdown) . '</pre>' 'content' => visible_whitespace($diaspora),
]; ];
$html = Text\Markdown::convert(html_entity_decode($markdown,ENT_COMPAT, 'UTF-8')); $markdown = XML::unescape($diaspora);
case 'markdown':
if (!isset($markdown)) {
$markdown = trim($_REQUEST['text']);
}
$results[] = [
'title' => DI::l10n()->t('Source input (Markdown)'),
'content' => visible_whitespace($markdown),
];
$html = Text\Markdown::convert($markdown);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('Markdown::convert (raw HTML)'), 'title' => DI::l10n()->t('Markdown::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html)) 'content' => visible_whitespace($html),
]; ];
$results[] = [ $results[] = [
@ -136,17 +145,17 @@ class Babel extends BaseModule
'content' => $html 'content' => $html
]; ];
$bbcode = Text\Markdown::toBBCode(XML::unescape($markdown)); $bbcode = Text\Markdown::toBBCode($markdown);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('Markdown::toBBCode'), 'title' => DI::l10n()->t('Markdown::toBBCode'),
'content' => '<pre>' . $bbcode . '</pre>' 'content' => visible_whitespace($bbcode),
]; ];
break; break;
case 'html' : case 'html' :
$html = trim($_REQUEST['text']); $html = trim($_REQUEST['text']);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('Raw HTML input'), 'title' => DI::l10n()->t('Raw HTML input'),
'content' => htmlspecialchars($html) 'content' => visible_whitespace($html),
]; ];
$results[] = [ $results[] = [
@ -174,7 +183,7 @@ class Babel extends BaseModule
$bbcode2plain = Text\BBCode::toPlaintext($bbcode); $bbcode2plain = Text\BBCode::toPlaintext($bbcode);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('HTML::toBBCode => BBCode::toPlaintext'), 'title' => DI::l10n()->t('HTML::toBBCode => BBCode::toPlaintext'),
'content' => '<pre>' . $bbcode2plain . '</pre>' 'content' => visible_whitespace($bbcode2plain),
]; ];
$markdown = Text\HTML::toMarkdown($html); $markdown = Text\HTML::toMarkdown($html);
@ -186,13 +195,13 @@ class Babel extends BaseModule
$text = Text\HTML::toPlaintext($html, 0); $text = Text\HTML::toPlaintext($html, 0);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('HTML::toPlaintext'), 'title' => DI::l10n()->t('HTML::toPlaintext'),
'content' => '<pre>' . $text . '</pre>' 'content' => visible_whitespace($text),
]; ];
$text = Text\HTML::toPlaintext($html, 0, true); $text = Text\HTML::toPlaintext($html, 0, true);
$results[] = [ $results[] = [
'title' => DI::l10n()->t('HTML::toPlaintext (compact)'), 'title' => DI::l10n()->t('HTML::toPlaintext (compact)'),
'content' => '<pre>' . $text . '</pre>' 'content' => visible_whitespace($text),
]; ];
} }
} }
@ -201,6 +210,7 @@ class Babel extends BaseModule
$o = Renderer::replaceMacros($tpl, [ $o = Renderer::replaceMacros($tpl, [
'$text' => ['text', DI::l10n()->t('Source text'), $_REQUEST['text'] ?? '', ''], '$text' => ['text', DI::l10n()->t('Source text'), $_REQUEST['text'] ?? '', ''],
'$type_bbcode' => ['type', DI::l10n()->t('BBCode'), 'bbcode', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'bbcode'], '$type_bbcode' => ['type', DI::l10n()->t('BBCode'), 'bbcode', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'bbcode'],
'$type_diaspora' => ['type', DI::l10n()->t('Diaspora'), 'diaspora', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'diaspora'],
'$type_markdown' => ['type', DI::l10n()->t('Markdown'), 'markdown', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'markdown'], '$type_markdown' => ['type', DI::l10n()->t('Markdown'), 'markdown', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'markdown'],
'$type_html' => ['type', DI::l10n()->t('HTML'), 'html', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'html'], '$type_html' => ['type', DI::l10n()->t('HTML'), 'html', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'html'],
'$results' => $results '$results' => $results

View file

@ -320,8 +320,8 @@ return [
"contact-relation" => [ "contact-relation" => [
"comment" => "Contact relations", "comment" => "Contact relations",
"fields" => [ "fields" => [
"cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact the related contact had interacted with"], "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "primary" => "1", "comment" => "contact the related contact had interacted with"],
"relation-cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "related contact who had interacted with the contact"], "relation-cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "primary" => "1", "comment" => "related contact who had interacted with the contact"],
"last-interaction" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last interaction"], "last-interaction" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last interaction"],
], ],
"indexes" => [ "indexes" => [

View file

@ -21,6 +21,7 @@
namespace Friendica\Test\src\Content\Text; namespace Friendica\Test\src\Content\Text;
use Friendica\Content\Text\HTML;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait; use Friendica\Test\Util\AppMockTrait;
@ -68,4 +69,30 @@ class MarkdownTest extends MockedTest
$this->assertEquals($expected, $output); $this->assertEquals($expected, $output);
} }
public function dataMarkdownText()
{
return [
'bug-8358-double-decode' => [
'expectedBBCode' => 'with the <sup> and </sup> tag',
'markdown' => 'with the &lt;sup&gt; and &lt;/sup&gt; tag',
],
];
}
/**
* Test convert Markdown to BBCode
*
* @dataProvider dataMarkdownText
*
* @param string $expectedBBCode Expected BBCode output
* @param string $html Markdown text
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function testToBBCode($expectedBBCode, $html)
{
$actual = Markdown::toBBCode($html);
$this->assertEquals($expectedBBCode, $actual);
}
} }

View file

@ -259,9 +259,9 @@
$contact_deny_input.val(''); $contact_deny_input.val('');
[].forEach.call($acl_deny_input.tagsinput('items'), function (item) { [].forEach.call($acl_deny_input.tagsinput('items'), function (item) {
if (item.type === 'group') { if (item.type === 'group') {
$group_deny_input.val($group_allow_input.val() + ',' + item.id); $group_deny_input.val($group_deny_input.val() + ',' + item.id);
} else { } else {
$contact_deny_input.val($contact_allow_input.val() + ',' + item.id); $contact_deny_input.val($contact_deny_input.val() + ',' + item.id);
} }
}); });
}); });

View file

@ -6,6 +6,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
{{include file="field_radio.tpl" field=$type_bbcode}} {{include file="field_radio.tpl" field=$type_bbcode}}
{{include file="field_radio.tpl" field=$type_diaspora}}
{{include file="field_radio.tpl" field=$type_markdown}} {{include file="field_radio.tpl" field=$type_markdown}}
{{include file="field_radio.tpl" field=$type_html}} {{include file="field_radio.tpl" field=$type_html}}
</div> </div>

View file

@ -1,12 +1,10 @@
<div class="vcard h-card"> <div class="vcard h-card">
<div class="fn label p-name">{{$profile.name}}</div> <div class="fn p-name">{{$profile.name}}</div>
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $profile.about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
{{if $profile.picdate}} {{if $profile.picdate}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div> <div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div>
{{else}} {{else}}

View file

@ -1,11 +1,10 @@
<div class="vcard h-card"> <div class="vcard h-card">
<div class="fn label p-name">{{$profile.name}}</div> <div class="fn p-name">{{$profile.name}}</div>
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $profile.about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
<div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></div> <div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></div>
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}
@ -26,6 +25,8 @@
</dl> </dl>
{{/if}} {{/if}}
{{if $profile.about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
{{if $profile.pubkey}}<div class="key" style="display:none;">{{$profile.pubkey}}</div>{{/if}} {{if $profile.pubkey}}<div class="key" style="display:none;">{{$profile.pubkey}}</div>{{/if}}
{{if $homepage}}<dl class="homepage"><dt class="homepage-label">{{$homepage}}</dt><dd class="homepage-url"><a href="{{$profile.homepage}}" class="u-url" rel="me" target="external-link">{{$profile.homepage}}</a></dd></dl>{{/if}} {{if $homepage}}<dl class="homepage"><dt class="homepage-label">{{$homepage}}</dt><dd class="homepage-url"><a href="{{$profile.homepage}}" class="u-url" rel="me" target="external-link">{{$profile.homepage}}</a></dd></dl>{{/if}}

View file

@ -1,7 +1,7 @@
<div class="vcard h-card"> <div class="vcard h-card">
<div class="tool"> <div class="tool">
<div class="fn label p-name">{{$profile.name}}</div> <div class="fn p-name">{{$profile.name}}</div>
{{if $profile.edit}} {{if $profile.edit}}
<div class="action"> <div class="action">
<a class="icon s16 edit ttright" href="#" rel="#profiles-menu" title="{{$profile.edit.3}}"><span>{{$profile.edit.1}}</span></a> <a class="icon s16 edit ttright" href="#" rel="#profiles-menu" title="{{$profile.edit.3}}"><span>{{$profile.edit.1}}</span></a>
@ -17,7 +17,6 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
<div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}" /></div> <div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}" /></div>
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}
@ -38,6 +37,8 @@
</dl> </dl>
{{/if}} {{/if}}
{{if $about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
{{if $profile.xmpp}} {{if $profile.xmpp}}
<dl class="xmpp"> <dl class="xmpp">
<dt class="xmpp-label">{{$xmpp}}</dt> <dt class="xmpp-label">{{$xmpp}}</dt>

View file

@ -1,7 +1,7 @@
<div class="vcard h-card"> <div class="vcard h-card">
<div class="tool"> <div class="tool">
<div class="fn label p-name">{{$profile.name}}</div> <div class="fn p-name">{{$profile.name}}</div>
{{if $profile.edit}} {{if $profile.edit}}
<div class="action"> <div class="action">
<a class="icon s16 edit ttright" href="{{$profile.edit.0}}" title="{{$profile.edit.3}}"><span>{{$profile.edit.1}}</span></a> <a class="icon s16 edit ttright" href="{{$profile.edit.0}}" title="{{$profile.edit.3}}"><span>{{$profile.edit.1}}</span></a>
@ -11,8 +11,6 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $profile.about}}<div class="title">{{$profile.about nofilter}}</div>{{/if}}
{{if $profile.picdate}} {{if $profile.picdate}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div> <div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div>
{{else}} {{else}}