From a6be3d7b2cb14630d9fe6d03008c007081e35b83 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Thu, 5 Jan 2023 20:17:07 -0800 Subject: [PATCH] Create new Markdown class, add strikethrough --- src/AntCMS/App.php | 10 +++--- src/AntCMS/Markdown.php | 13 ++++++++ src/Content/markdowntest.md | 62 +++++++++++++++++++++++++++++++++++++ src/index.php | 3 +- 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 src/AntCMS/Markdown.php create mode 100644 src/Content/markdowntest.md diff --git a/src/AntCMS/App.php b/src/AntCMS/App.php index 4cd0939..e61ec39 100644 --- a/src/AntCMS/App.php +++ b/src/AntCMS/App.php @@ -1,5 +1,6 @@ renderException("404"); } else { - echo Markdown::defaultTransform($content); + echo AntMarkdown::renderMarkdown($content); } } public function renderException($exceptionCode){ $content = "# Error"; $content .= "That request caused an $exceptionCode"; - echo Markdown::defaultTransform($content); + echo AntMarkdown::renderMarkdown($content); } public function getPage($page){ @@ -24,12 +25,11 @@ class AntCMS { try { $pageContents = file_get_contents($pagePath); return $pageContents; - } catch (Exception $e) { + } catch (\Exception $e) { return false; } } else { return false; } } - } diff --git a/src/AntCMS/Markdown.php b/src/AntCMS/Markdown.php new file mode 100644 index 0000000..6352016 --- /dev/null +++ b/src/AntCMS/Markdown.php @@ -0,0 +1,13 @@ +$1', $result); + echo $result; + } +} +?> diff --git a/src/Content/markdowntest.md b/src/Content/markdowntest.md new file mode 100644 index 0000000..14f8ff7 --- /dev/null +++ b/src/Content/markdowntest.md @@ -0,0 +1,62 @@ +# Heading 1 +## Heading 2 +### Heading 3 +#### Heading 4 +##### Heading 5 +###### Heading 6 + +Paragraphs are separated by a blank line. + +*Italic* or _italic_ text. + +**Bold** or __bold__ text. + +~~Strikethrough~~ text. + +Unordered lists: + +- Item 1 +- Item 2 +- Item 3 + +Ordered lists: + +1. Item 1 +2. Item 2 +3. Item 3 + +Nested lists: + +- Item 1 + - Subitem 1 + - Subitem 2 +- Item 2 + - Subitem 1 + - Subitem 2 + +Links: + +[Link text](http://example.com) + +Images: + +![Alt text](http://example.com/image.jpg) + +Inline code: `code` + +Blockquotes: + +> Lorem ipsum dolor sit amet, consectetur adipiscing elit. + +Tables: + +| Column 1 | Column 2 | Column 3 | +|----------|----------|----------| +| Cell 1 | Cell 2 | Cell 3 | +| Cell 4 | Cell 5 | Cell 6 | + +Horizontal rule: + +--- + +Emoji: :smile: :heart: :thumbsup: diff --git a/src/index.php b/src/index.php index 3e0f404..df5097e 100644 --- a/src/index.php +++ b/src/index.php @@ -6,9 +6,10 @@ ini_set('display_errors', 1); const appDir = __DIR__; require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/AntCMS/App.php'; +require_once __DIR__ . '/AntCMS/Markdown.php'; use \AntCMS; -$antCms = new AntCMS(); +$antCms = new AntCMS\AntCMS(); $requestedPage = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $indexes = ['/', '/index.php', '/index.html']; if (in_array($requestedPage, $indexes)) {