Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions DWtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,22 @@
$test11_p
MD;

$test = ltrim($test11_p);
$test12 = '## Image Alignment
![](test.jpg)

![](test.jpg?align=left)

![](test.jpg?align=right)

![](test.jpg?align=center)

![](test.jpg?align=right&400)
';

$test = ltrim($test12);
echo $test . "\n\n=========================\n\n";
$result = Commonmark::RendtoDW($test);
echo $result;
//$frontmatter = Commonmark::ExtractFrontmatter($test);
//print_r($frontmatter);
?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public function render(Node $node, ChildNodeRendererInterface $DWRenderer): stri
{
Image::assertInstanceOf($node);

$args = null;
$attrs = $node->data->get('attributes');

$forbidUnsafeLinks = !$this->config->get('allow_unsafe_links');
if ($forbidUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl())) {
$attrs['src'] = '';
} else {
$attrs['src'] = $node->getUrl();
\parse_str(\parse_url($node->getUrl(), PHP_URL_QUERY), $args);
}

$alt = $DWRenderer->renderNodes($node->children());
Expand All @@ -58,8 +60,12 @@ public function render(Node $node, ChildNodeRendererInterface $DWRenderer): stri
$attrs['title'] = $node->data['title'];
}

$result = '{{' . $attrs['src'];
$attrs['alt'] ? $result.= '|' . $attrs['alt'] . '}}' : $result.= '}}';
$result = '{{' . (isset($args['align']) && ($args['align'] === 'right' || $args['align'] === 'center') ? ' ' : '');
$result.= $attrs['src'] . (isset($args['align']) && ($args['align'] === 'left' || $args['align'] === 'center') ? ' ' : '');
if ($attrs['alt']) {
$result.= '|' . trim($attrs['alt']);
}
$result.= '}}';

return $result;
}
Expand Down