diff options
author | Christian Cleberg <hello@cleberg.net> | 2023-05-22 15:18:52 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2023-05-22 15:18:52 -0500 |
commit | deb20fdfca35c64066fe4e375099350dc77ea408 (patch) | |
tree | 8be0f7541652e4e8f89fc4dd603fae7accf4ee24 /_functions/parseMarkdown.php | |
download | php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.gz php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.bz2 php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.zip |
initial commit
Diffstat (limited to '_functions/parseMarkdown.php')
-rw-r--r-- | _functions/parseMarkdown.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/_functions/parseMarkdown.php b/_functions/parseMarkdown.php new file mode 100644 index 0000000..6ca15d8 --- /dev/null +++ b/_functions/parseMarkdown.php @@ -0,0 +1,21 @@ +<?php + +function parseMarkdown(string $fileName = null, string $fileContents = null) +{ + if ($fileName != null) { + // Get file contents + $fileContents = file_get_contents('/var/www/' . $GLOBALS['shortDomain'] . '/' . $fileName, FILE_USE_INCLUDE_PATH); + } + + // Parse the markdown to HTML + include_once('_classes/Parsedown.php'); + $md = Parsedown::instance()->text($fileContents); + $html = new DOMDocument(); + $html->loadHTML($md); + $html_links = $html->getElementsByTagName('a'); + foreach ($html_links as $html_ink) { + $html_ink->setAttribute('rel', 'noopener,noreferrer'); + $html_ink->setAttribute('target', '_blank'); + } + return $html->saveHTML(); +}
\ No newline at end of file |