Create new Markdown class, add strikethrough

This commit is contained in:
Belle Aerni 2023-01-05 20:17:07 -08:00
parent 23b05394b4
commit a6be3d7b2c
4 changed files with 82 additions and 6 deletions

View file

@ -1,5 +1,6 @@
<?php
use Michelf\Markdown;
namespace AntCMS;
use AntCMS\AntMarkdown;
class AntCMS {
public function renderPage($page, $params = null){
@ -7,14 +8,14 @@ class AntCMS {
if(!$content){
$this->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;
}
}
}

13
src/AntCMS/Markdown.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace AntCMS;
use Michelf\Markdown;
class AntMarkdown{
public static function renderMarkdown($md)
{
$result = Markdown::defaultTransform($md);
$result = preg_replace('/(?:~~)([^~~]*)(?:~~)/', '<s>$1</s>', $result);
echo $result;
}
}
?>

View file

@ -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:

View file

@ -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)) {