secure-77 / Perlite

A web-based markdown viewer optimized for Obsidian

Home Page:https://perlite.secure77.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support image resizing

JohnnyHenver opened this issue · comments

Is your feature request related to a problem? Please describe.

Obsidian established the following syntax to rescale images:
![[og-image.png|200]]
This currently breaks the image links in Perlite.

Describe the solution you'd like

It would be great if Perlite could support scaled images the way Obsidian does.

Describe alternatives you've considered

Scaling the images outside of obsidian is valid, but kind of a hassle.

This would be great. As an example, currently ![[image.png|100]] is parsed as a plaintext ! followed by the renamed wikilink to image.png:

image

We can convert all images beforehand, but it'd be awesome to have them rescale in Perlite. And if not, it'd be nice if the image itself still appeared.

I'm taking guesses because of my unfamiliarity with the codebase, but is this issue occurring in Parsedown.php at the inlineImage call?

Perlite/perlite/Parsedown.php

Lines 1224 to 1238 in ac8c431

protected function inlineImage($Excerpt)
{
if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
{
return;
}
$Excerpt['text']= substr($Excerpt['text'], 1);
$Link = $this->inlineLink($Excerpt);
if ($Link === null)
{
return;
}

And thus does it stem from the regex calls in the inlineLink function in PerliteParsedown.php?

protected function inlineLink($Excerpt)
{
$Element = array(
'name' => 'a',
'handler' => 'line',
'nonNestables' => array('Url', 'Link'),
'text' => null,
'attributes' => array(
'href' => null,
'title' => null,
'class' => 'external-link perlite-external-link',
'target' => '_blank',
'rel' => 'noopener noreferrer',
),
);
$extent = 0;
$remainder = $Excerpt['text'];
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) {
$Element['text'] = $matches[1];
$extent += strlen($matches[0]);
$remainder = substr($remainder, $extent);
} else {
return;
}
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) {
$Element['attributes']['href'] = $matches[1];
if (isset($matches[2])) {
$Element['attributes']['title'] = substr($matches[2], 1, -1);
}
$extent += strlen($matches[0]);
} else {
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) {
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);
$extent += strlen($matches[0]);
} else {
$definition = strtolower($Element['text']);
}
if (!isset($this->DefinitionData['Reference'][$definition])) {
return;
}
$Definition = $this->DefinitionData['Reference'][$definition];
$Element['attributes']['href'] = $Definition['url'];
$Element['attributes']['title'] = $Definition['title'];
}
return array(
'extent' => $extent,
'element' => $Element,
);
}

Trying to wrap my head around it...

commented

This is fixed in version 1.5.3