Updated Markdown extension, better event handling

This commit is contained in:
markseu 2024-04-03 10:26:35 +02:00
parent d002650f84
commit 5c9bbaa55c
3 changed files with 37 additions and 17 deletions

View file

@ -2,7 +2,7 @@
// Markdown extension, https://github.com/annaesvensson/yellow-markdown
class YellowMarkdown {
const VERSION = "0.8.27";
const VERSION = "0.8.28";
public $yellow; // access to API
// Handle initialisation
@ -3911,9 +3911,10 @@ class YellowMarkdownParser extends MarkdownExtraParser {
// Handle fenced code blocks
public function _doFencedCodeBlocks_callback($matches) {
$name = $this->getBlockName($matches[2], $matches[3]);
$text = $matches[4];
$name = is_string_empty($matches[2]) ? "" : trim("$matches[2] $matches[3]");
$output = $this->page->parseContentElement($name, $text, "", "code");
$attributes = $matches[3];
$output = $this->page->parseContentElement($name, $text, $attributes, "code");
if (is_null($output)) {
$attr = $this->doExtraAttributes("pre", ".$matches[2] $matches[3]");
$output = "<pre$attr><code>".htmlspecialchars($text, ENT_NOQUOTES)."</code></pre>";
@ -4007,19 +4008,25 @@ class YellowMarkdownParser extends MarkdownExtraParser {
// Handle notice blocks over multiple lines
public function _doNoticeBlocks_callback($matches) {
$lines = $matches[1];
$attr = "";
$text = preg_replace("/^[ ]*![ ]?/m", "", $lines);
if (preg_match("/^[ ]*".$this->id_class_attr_catch_re."[ ]*\n([\S\s]*)$/m", $text, $matches)) {
$attr = $this->doExtraAttributes("div", $dummy =& $matches[1]);
$text = $matches[2];
$name = $attributes = $attr = "";
$text = preg_replace("/^[ ]*![ ]?/m", "", $matches[1]);
if (preg_match("/^[ ]*".$this->id_class_attr_catch_re."[ ]*\n([\S\s]*)$/m", $text, $parts)) {
$name = $this->getBlockName("", $parts[1]);
$text = $parts[2];
$attributes = $parts[1];
$attr = $this->doExtraAttributes("div", $parts[1]);
} elseif ($this->noticeLevel==0) {
$level = strspn(str_replace(array("![", " "), "", $lines), "!");
$level = strspn(str_replace(array("![", " "), "", $matches[1]), "!");
$attr = " class=\"notice$level\"";
}
if (!is_string_empty($text)) {
++$this->noticeLevel;
$output = "<div$attr>\n".$this->runBlockGamut($text)."\n</div>";
$output = $this->page->parseContentElement($name, "[--notice--]", $attributes, "notice");
if (!is_null($output) && preg_match("/^(.+)(\[--notice--\])(.+)$/s", $output, $parts)) {
$output = $parts[1].$this->runBlockGamut($text).$parts[3];
} else {
$output = "<div$attr>\n".$this->runBlockGamut($text)."\n</div>";
}
--$this->noticeLevel;
} else {
$output = "<div$attr></div>";
@ -4045,6 +4052,19 @@ class YellowMarkdownParser extends MarkdownExtraParser {
}
return $text;
}
// Return suitable name for code block or notice block
public function getBlockName($language, $attributes) {
if (!is_string_empty($language)) {
$name = ltrim($language, ".");
} else {
$name = "";
foreach (explode(" ", $attributes) as $token) {
if (substru($token, 0, 1)==".") { $name = substru($token, 1); break; }
}
}
return $name;
}
// Return unique id attribute
public function getIdAttribute($text) {

View file

@ -384,14 +384,14 @@ media/images/language-en.png: language-en.png, create, optional
media/images/language-sv.png: language-sv.png, create, optional
Extension: Highlight
Version: 0.8.17
Version: 0.8.18
Description: Highlight source code.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-highlight/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-highlight
DocumentationLanguage: en, de, sv
Published: 2024-04-01 19:30:24
Published: 2024-04-03 10:13:46
Status: available
system/extensions/highlight.php: highlight.php, create, update
system/extensions/highlight.css: highlight.css, create, update
@ -501,14 +501,14 @@ system/themes/karlskrona.css: karlskrona.css, create, update, careful
system/themes/karlskrona.png: karlskrona.png, create
Extension: Markdown
Version: 0.8.27
Version: 0.8.28
Description: Text formatting for humans.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-markdown/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-markdown
DocumentationLanguage: en, de, sv
Published: 2024-04-01 18:41:04
Published: 2024-04-03 10:08:24
Status: available
system/extensions/markdown.php: markdown.php, create, update

View file

@ -85,14 +85,14 @@ media/downloads/yellow.pdf: yellow.pdf, create
./robots.txt: robots.txt, create
Extension: Markdown
Version: 0.8.27
Version: 0.8.28
Description: Text formatting for humans.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-markdown/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-markdown
DocumentationLanguage: en, de, sv
Published: 2024-04-01 18:41:04
Published: 2024-04-03 10:08:24
Status: available
system/extensions/markdown.php: markdown.php, create, update