aboutsummaryrefslogtreecommitdiff
path: root/_functions/parseMarkdown.php
diff options
context:
space:
mode:
Diffstat (limited to '_functions/parseMarkdown.php')
-rw-r--r--_functions/parseMarkdown.php21
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