Skip to content

Commit

Permalink
Merge pull request #125 from ar0x4/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
secure-77 authored Sep 23, 2024
2 parents cc77a73 + 51e3e4f commit d4ca81e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 12 additions & 1 deletion perlite/.styles/perlite.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,25 @@ img {
max-width: 100%;
}

.images.center {
display: block !important;
margin-left: auto;
margin-right: auto;
}

.images.right {
display: block !important;
margin-left: auto;
margin-right: 0;
}

.popup-icon {
padding-bottom: 1px;
top: -6px;
position: relative;
left: 3px;
}


#loading-text {
position: absolute;
top: 8px;
Expand Down
8 changes: 8 additions & 0 deletions perlite/Demo/Demo Documents/Images.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Image with a alternate text and size

![[background.png|This is a description|100]]

Centered image

![[background.png|center]]

Right aligned image with a custom size

![[background.png|right|200]]

## External images


Expand Down
15 changes: 15 additions & 0 deletions perlite/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ function parseContent($requestFile)
$pattern = array('/(\!?\[\[)(.*?)(.png|.jpg|.jpeg|.svg|.gif|.bmp|.tif|.tiff)\|?(\d*)x?(\d*)(\]\])/');
$content = preg_replace($pattern, $replaces, $content);

// centerise or right align images with "center"/"right" directive
$pattern = '/(\!?\[\[)(.*?)(.png|.jpg|.jpeg|.svg|.gif|.bmp|.tif|.tiff)\|?(center|right)\|?(\d*)x?(\d*)(\]\])/';
$replaces = function ($matches) use ($path) {
$class = "images"; // Default class for all images
if (strpos($matches[4], 'center') !== false) {
$class .= " center"; // Add 'center' class
} elseif (strpos($matches[4], 'right') !== false) {
$class .= " right"; // Add 'right' class
}
$width = $matches[5] ?? 'auto';
$height = $matches[6] ?? 'auto';
return '<p><a href="#" class="pop"><img class="' . $class . '" src="' . $path . '/' . $matches[2] . $matches[3] . '" width="' . $width . '" height="' . $height . '"/></a></p>';
};
$content = preg_replace_callback($pattern, $replaces, $content);

// img links with captions and size
$replaces = '<p><a href="#" class="pop"><img class="images" width="\\5" height="\\6" alt="\\4" src="' . $path . '/\\2\\3' . '"/></a></p>';
$pattern = array('/(\!?\[\[)(.*?)(.png|.jpg|.jpeg|.svg|.gif|.bmp|.tif|.tiff)\|?(.+\|)\|?(\d*)x?(\d*)(\]\])/');
Expand Down

0 comments on commit d4ca81e

Please sign in to comment.