fox markdown bugs

This commit is contained in:
Dennis Eichhorn 2023-11-11 05:21:36 +00:00
parent 5c38b8b250
commit f3f3f2846b
16 changed files with 149 additions and 80 deletions

View File

@ -98,7 +98,7 @@ class Markdown
*/
protected array $emRegex = [
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
'_' => '/^[_]((?:\\\\\_|[^_]|[_][_][^_]+?[_][_])+?)[_](?![_])/s',
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
];
/**
@ -170,7 +170,7 @@ class Markdown
* @var string
* @since 1.0.0
*/
protected string $inlineMarkerList = '!*_&[:<`~\\';
protected string $inlineMarkerList = '!*_&[:<`~';
/**
* Uses strict mode?
@ -527,6 +527,14 @@ class Markdown
if ($this->options['contact'] ?? false) {
$this->inlineTypes['['][] = 'Contact';
}
// Progress
if ($this->options['progress'] ?? false) {
$this->inlineTypes['['][] = 'Progress';
}
// Escaping needs to happen at the end
$this->inlineMarkerList .= '\\';
}
/**
@ -694,7 +702,7 @@ class Markdown
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
if (\strpos($excerpt['text'], '>') === false
|| \preg_match('/^<((mailto:)?{' . $commonMarkEmail . '})>/i', $excerpt['text'], $matches) !== 1
|| \preg_match('/^<((mailto:)?' . $commonMarkEmail . ')>/i', $excerpt['text'], $matches) !== 1
) {
return null;
}
@ -1243,8 +1251,22 @@ class Markdown
return [
'extent' => \strlen($matches[0]),
'element' => [
'name' => 'mark',
'text' => $matches[2],
'name' => 'span',
'attributes' => [
'class' => 'spoiler'
],
'elements' => [
[
'name' => 'input',
'attributes' => [
'type' => 'checkbox'
]
],
[
'name' => 'span',
'text' => $matches[1],
]
]
],
];
}
@ -1378,7 +1400,7 @@ class Markdown
protected function inlineMap(array $excerpt) : ?array
{
if (!($this->options['map'] ?? false)
|| (\preg_match('/\[map(?:\s+(?:name="([^"]+)"|country="([^"]+)"|city="([^"]+)"|zip="([^"]+)"|address="([^"]+)"|lat="([^"]+)"|lon="([^"]+)")){0,3}\]/', $excerpt['text'], $matches) !== 1)
|| (\preg_match('/\[map(?:\s+(?:name="([^"]+)"|country="([^"]+)"|city="([^"]+)"|zip="([^"]+)"|address="([^"]+)"|lat="([^"]+)"|lon="([^"]+)")){0,7}\]/', $excerpt['text'], $matches) !== 1)
) {
return null;
}
@ -1389,8 +1411,8 @@ class Markdown
$zip = $matches[4];
$address = $matches[5];
$lat = empty($matches[6]) ? '' : (float) $matches[6];
$lon = empty($matches[7]) ? '' : (float) $matches[7];
$lat = $matches[6];
$lon = $matches[7];
if ($lat === '' || $lon === '') {
[$lat, $lon] = \phpOMS\Api\Geocoding\Nominatim::geocoding($country, $city, $address, $zip);
@ -1402,7 +1424,7 @@ class Markdown
'name' => 'div',
'text' => '',
'attributes' => [
'id' => '-' . \bin2hex(\random_bytes(4)),
'id' => 'i' . \bin2hex(\random_bytes(4)),
'class' => 'map',
'data-lat' => $lat,
'data-lon' => $lon,
@ -1423,7 +1445,7 @@ class Markdown
protected function inlineAddress(array $excerpt) : ?array
{
if (!($this->options['address'] ?? false)
|| (\preg_match('/\[addr(?:\s+(?:name="([^"]+)"|country="([^"]+)"|city="([^"]+)"|zip="([^"]+)"|address="([^"]+)")){0,3}\]/', $excerpt['text'], $matches) !== 1)
|| (\preg_match('/\[addr(?:\s+(?:name="([^"]+)"|country="([^"]+)"|city="([^"]+)"|zip="([^"]+)"|address="([^"]+)")){0,5}\]/', $excerpt['text'], $matches) !== 1)
) {
return null;
}
@ -1573,9 +1595,9 @@ class Markdown
return null;
}
// $type = $matches[1] ?? 'meter';
$percent = $matches[2] ?? ($matches[3]);
$value = $matches[3] ?? $matches[2];
// $type = empty($matches[1]) ? 'meter' : $matches[1];
$percent = empty($matches[2]) ? $matches[3] : $matches[2];
$value = empty($matches[3]) ? $matches[2] : $matches[3];
if ($percent === ''
|| $value === ''
@ -1587,7 +1609,7 @@ class Markdown
'extent' => \strlen($matches[0]),
'element' => [
'name' => 'progress',
//'text' => '',
'text' => '',
'attributes' => [
'value' => $value,
'max' => '100',
@ -1725,7 +1747,7 @@ class Markdown
protected function inlineEscapeSequence(array $excerpt) : ?array
{
if (!isset($excerpt['text'][1])
|| \in_array($excerpt['text'][1], $this->specialCharacters)
|| !\in_array($excerpt['text'][1], $this->specialCharacters)
) {
return null;
}
@ -2315,7 +2337,7 @@ class Markdown
foreach ($headerCells as $index => $headerCell) {
$headerCell = \trim($headerCell);
$HeaderElement = [
$headerElement = [
'name' => 'th',
'handler' => [
'function' => 'lineElements',
@ -2327,12 +2349,12 @@ class Markdown
if (isset($alignments[$index])) {
$alignment = $alignments[$index];
$HeaderElement['attributes'] = [
$headerElement['attributes'] = [
'style' => "text-align: {$alignment};",
];
}
$headerElements [] = $HeaderElement;
$headerElements[] = $headerElement;
}
$block = [
@ -2623,7 +2645,7 @@ class Markdown
return null;
}
$summary = \trim(\preg_replace('/^\?{3}([^\s]+)(.+)?/s', '$1', $line['text']));
$summary = \trim(\preg_replace('/^\?{3}(.+)?/s', '$1', $line['text']));
$infostring = \trim(\substr($line['text'], $openerLength), "\t ");
if (\strpos($infostring, '?') !== false) {
@ -2635,6 +2657,8 @@ class Markdown
'openerLength' => $openerLength,
'element' => [
'name' => 'details',
'element' => [
'text' => '',
'elements' => [
[
'name' => 'summary',
@ -2645,6 +2669,7 @@ class Markdown
'text' => '',
]
],
]
],
];
}
@ -2831,8 +2856,9 @@ class Markdown
*/
protected function blockCheckboxComplete(array $block) : array
{
$text = $block['text'];
if ($this->markupEscaped || $this->safeMode) {
$text = \htmlspecialchars($block['text'], \ENT_QUOTES, 'UTF-8');
$text = \htmlspecialchars($text, \ENT_QUOTES, 'UTF-8');
}
$html = $block['handler'] === 'unchecked'
@ -4037,7 +4063,7 @@ class Markdown
return $block;
}
$block['element']['element']['text'] .= "\n" . $line['body'];
$block['element']['element']['elements'][1]['text'] .= "\n" . $line['body'];
return $block;
}

View File

@ -76,9 +76,11 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
'map' => true
]);
self::assertEquals(
self::assertLessThan(9,
\levenshtein(
\file_get_contents(__DIR__ . '/manualdata/map.html'),
$parser->text(\file_get_contents(__DIR__ . '/manualdata/map.md'))
)
);
}
@ -130,23 +132,6 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
);
}
public function testSpoiler() : void
{
$parser = new Markdown([
'spoiler' => true
]);
self::assertEquals(
\file_get_contents(__DIR__ . '/manualdata/spoiler.html'),
$parser->text(\file_get_contents(__DIR__ . '/manualdata/spoiler.md'))
);
self::assertEquals(
\file_get_contents(__DIR__ . '/manualdata/spoiler_block.html'),
$parser->text(\file_get_contents(__DIR__ . '/manualdata/spoiler_block.md'))
);
}
public function testEmbed() : void
{
$parser = new Markdown([
@ -183,4 +168,21 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
$parser->contentsList()
);
}
public function testSpoiler() : void
{
$parser = new Markdown([
'spoiler' => true
]);
self::assertEquals(
\file_get_contents(__DIR__ . '/manualdata/spoiler.html'),
$parser->text(\file_get_contents(__DIR__ . '/manualdata/spoiler.md'))
);
self::assertEquals(
\file_get_contents(__DIR__ . '/manualdata/spoiler_block.html'),
$parser->text(\file_get_contents(__DIR__ . '/manualdata/spoiler_block.md'))
);
}
}

View File

@ -0,0 +1,4 @@
<ul>
<li><input type="checkbox" disabled /> Unchecked</li>
<li><input type="checkbox" checked disabled /> Checked</li>
</ul>

View File

@ -1,8 +1,4 @@
<p><u><em>em strong</em></u></p>
<p><u><em>em strong</em> strong</u></p>
<p><u>strong <em>em strong</em></u></p>
<p><u>strong <em>em strong</em> strong</u></p>
<p><strong><em>em strong</em></strong></p>
<p><strong><em>em strong</em> strong</strong></p>
<p><strong>strong <em>em strong</em></strong></p>
<p><strong>strong <em>em strong</em> strong</strong></p>
<p><em><u>em underline</u></em></p>
<p><u><em>underline em</em></u></p>
<p><strong><em>strong em</em></strong></p>
<p><strong><em>strong em</em></strong></p>

View File

@ -1,15 +1,7 @@
___em strong___
___em underline___
___em strong_ strong__
__*underline em*__
__strong _em strong___
***strong em***
__strong _em strong_ strong__
***em strong***
***em strong* strong**
**strong *em strong***
**strong *em strong* strong**
**_strong em_**

View File

@ -1 +1 @@
📹
<p>📹</p>

View File

@ -2,9 +2,9 @@ __underscore__, *asterisk*, _one two_, *three four*, _a_, *b*
**strong** and *em* and **strong** and *em*
_line
*line
line
line_
line*
this_is_not_an_emphasis

View File

@ -1 +1 @@
<kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>A</kbd>
<p><kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>A</kbd></p>

View File

@ -1 +1 @@
<mark>Mark test</mark>
<p><mark>Mark test</mark></p>

View File

@ -1 +1,7 @@
[addr name="AddrName" address="Addr" city="AddrCity" country="AddrCoutry" zip="AddrZip"]
<p><div class="addressWidget">
<span class="addressWidget-name">AddrName</span>
<span class="addressWidget-address">Addr</span>
<span class="addressWidget-zip">AddrZip</span>
<span class="addressWidget-city">AddrCity</span>
<span class="addressWidget-country">AddrCoutry</span>
</div></p>

View File

@ -0,0 +1,36 @@
<p><a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/phone.svg" />
<span class="contactWidget-contact">+49 123 456 789</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/facebook.svg" />
<span class="contactWidget-contact">@jinggaApp</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/discord.svg" />
<span class="contactWidget-contact">jingga</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/email.svg" />
<span class="contactWidget-contact">test@email.com</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/twitter.svg" />
<span class="contactWidget-contact">@jinggaApp</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/youtube.svg" />
<span class="contactWidget-contact">@jinggaApp</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/instagram.svg" />
<span class="contactWidget-contact">jinggaApp</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/slack.svg" />
<span class="contactWidget-contact">jinggaApp</span>
</a>
<a class="contactWidget" href="">
<img class="contactWidget-icon" src="Resources/icons/company/teams.svg" />
<span class="contactWidget-contact">jinggaApp</span>
</a></p>

View File

@ -1 +1 @@
<p><div id="-" class="map" data-lat="1.0" data-lon="1.0"></div></p>
<p><div id="i" class="map" data-lat="1.0" data-lon="1.0"></div></p>

View File

@ -1 +1 @@
<progress value="33" max="100"></progress>
<p><progress value="33" max="100"></progress></p>

View File

@ -1 +1,4 @@
This is a >!test spoiler!< in text.
<p>This is a <span class="spoiler">
<input type="checkbox" />
<span>test spoiler</span>
</span> in text.</p>

View File

@ -1 +1,5 @@
<details><summary>Test summary</summary><span>This is a test spoiler.</span></details>
<details>
<summary>Test summary</summary>
<span>
This is a test spoiler.</span>
</details>