DEV: Preliminary work for adding emoji and spoiler

This commit is contained in:
Evg 2021-12-16 00:25:28 +03:00
parent 3160ad3d69
commit 5fdeba6cd9
7 changed files with 85 additions and 32 deletions

View file

@ -45,7 +45,6 @@ class AuditsController extends MainController
'uid' => Base::getUid(),
'data' => [
'sheet' => $sheet,
'type' => $type,
'type' => 'audits',
'pagesCount' => ceil($pagesCount / $this->limit),
'pNum' => $page,

View file

@ -13,6 +13,7 @@ class Content
if ($type == 'text') {
$text = $Parsedown->text($content);
$text = self::parseVideo($text);
$text = self::parseSpoiler($text);
} else {
$text = $Parsedown->line($content);
}
@ -38,6 +39,16 @@ class Content
return $content;
}
public static function parseSpoiler($content)
{
$regexp = '/\{spoiler(?!.*\{spoiler)(\s?)(?(1)(.*?))\}(.*?)\{\/spoiler\}/is';
while (preg_match($regexp, $content)) {
$content = preg_replace($regexp, "<details><summary>" . Translate::get('see more') . "</summary>$2$3</details>", $content);
}
return $content;
}
// Парсинг user login / uid
public static function parseUser($content, $with_user = false, $to_uid = false)
{

View file

@ -5,17 +5,15 @@
class MyParsedown extends Parsedown
{
private $baseImagePath;
function __construct()
{
$this->InlineTypes['{'][]= 'ColoredText';
$this->InlineTypes['{'][] = 'ColoredText';
$this->inlineMarkerList .= '{';
// $this->baseImagePath = Config::get('meta.url');
// $this->baseImagePath = Config::get('meta.url');
$this->InlineTypes[':'][] = 'Emoji';
}
protected function element(array $Element)
{
if ($this->safeMode) {
@ -28,8 +26,8 @@ class MyParsedown extends Parsedown
$server_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
$href_host = isset($Element['attributes']['href']) ? parse_url($Element['attributes']['href'], PHP_URL_HOST) : null;
// Add a list of allowed urls to the config?
if ($server_host != $href_host) {
// Add a list of allowed urls to the config?
if ($server_host != $href_host) {
$Element['attributes']['target'] = '_blank';
$Element['attributes']['rel'] = 'noopener nofollow ugc';
}
@ -54,29 +52,26 @@ class MyParsedown extends Parsedown
if (isset($Element['handler'])) {
$markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']);
}
else {
} else {
$markup .= self::escape($Element['text'], true);
}
$markup .= '</' . $Element['name'] . '>';
}
else {
} else {
$markup .= ' />';
}
return $markup;
}
}
protected function inlineColoredText($excerpt)
{
if (preg_match('/^{c:([#\w]\w+)}(.*?){\/c}/', $excerpt['text'], $matches))
{
if (preg_match('/^{c:([#\w]\w+)}(.*?){\/c}/', $excerpt['text'], $matches)) {
return array(
// How many characters to advance the Parsedown's
// cursor after being done processing this tag.
'extent' => strlen($matches[0]),
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'span',
'text' => $matches[2],
@ -88,8 +83,35 @@ class MyParsedown extends Parsedown
);
}
}
// Добавим url домен в тело контента
protected function inlineEmoji($Excerpt)
{
if (preg_match('/\:(\w+)\:/mUs', $Excerpt['text'], $matches)) {
$path = HLEB_PUBLIC_DIR . "/assets/images/emoji/" . $matches[1];
$file_ext = "";
if (file_exists($path . ".png"))
$file_ext = ".png";
else if (file_exists($path . ".gif"))
$file_ext = ".gif";
if ($file_ext === "")
return;
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'img',
'handler' => 'line',
'attributes' => [
'class' => 'w18 h18 inline',
'src' => '/assets/images/emoji/' . $matches[1] . $file_ext,
'alt' => ':' . $matches[1] . ':',
'title' => ':' . $matches[1] . ':'
],
]
];
}
}
// Добавим url домена в тело контента
/* protected function inlineImage($excerpt)
{
$image = parent::inlineImage($excerpt);
@ -103,6 +125,4 @@ class MyParsedown extends Parsedown
return $image;
} */
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

View file

@ -12,8 +12,9 @@
let dark = document.querySelector('.bg-gray-100.dark');
let viewerEl = document.querySelector('.editorSection');
let body = viewerEl.innerHTML;
let body = viewerEl.innerHTML.trim();
body = body.replace(/&gt;/gi, ">");
if (viewerEl == null) {
return;
}
@ -39,9 +40,10 @@
toolbarItems: [
['heading', 'bold', 'italic', 'strike'],
['hr', 'quote'],
['ul', 'ol'],
['ul'],
['table', 'image', 'link'],
['code', 'codeblock'],
],
events: {
change: function() {
@ -71,6 +73,5 @@
});
editor.getMarkdown();
});
</script>

View file

@ -199,7 +199,7 @@ textarea:focus { border: 1px solid #9ccdf8; }
}
/* Tags */
.tags-look .tagify__dropdown__item{
.tags-look .tagify__dropdown__item {
display: inline-block;
border-radius: 3px;
padding: .3em .5em;
@ -211,11 +211,30 @@ textarea:focus { border: 1px solid #9ccdf8; }
transition: 0s;
}
.tags-look .tagify__dropdown__item--active{
.tags-look .tagify__dropdown__item--active {
color: black;
}
.tags-look .tagify__dropdown__item:hover{
.tags-look .tagify__dropdown__item:hover {
background: lightyellow;
border-color: gold;
}
details {
border-radius: 0 0 3px 3px;
background-color: #f5f5fa;
padding: 2px 6px;
margin: 0;
box-shadow: 3px 3px 4px #eee;
}
summary {
background-color: #f5f5fa;
color: #666;
font-size: 14px;
}
details[open] > summary {
padding: 0 0 10px 0;
color: #666;
}