Skip to content

Commit

Permalink
Add support for extended syntax markdown
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
JeroenDeDauw committed Dec 2, 2021
1 parent 398b966 commit bcc7995
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -200,6 +200,10 @@ Alternatively, you can execute commands from the MediaWiki root directory:

## Release notes

### Version 1.2.0 - 2021-12-02

* Added support for [extended syntax markdown](https://www.markdownguide.org/extended-syntax/)

### Version 1.1.0 - 2021-11-01

* Added normalization for github.com URLs to the `#embed` parser function
Expand Down
2 changes: 1 addition & 1 deletion extension.json
@@ -1,6 +1,6 @@
{
"name": "External Content",
"version": "1.1.0",
"version": "1.2.0",
"license-name": "GPL-2.0-or-later",

"author": [
Expand Down
3 changes: 2 additions & 1 deletion src/Domain/ContentRenderer/MarkdownRenderer.php
Expand Up @@ -5,6 +5,7 @@
namespace ProfessionalWiki\ExternalContent\Domain\ContentRenderer;

use Michelf\Markdown;
use Michelf\MarkdownExtra;
use ProfessionalWiki\ExternalContent\Domain\ContentRenderer;

class MarkdownRenderer implements ContentRenderer {
Expand All @@ -16,7 +17,7 @@ public function render( string $content, string $contentUrl ): string {
}

private function newMarkdownParser( string $contentUrl ): Markdown {
$parser = new Markdown();
$parser = new MarkdownExtra();
$urlExpander = new UrlExpander();

$parser->url_filter_func = fn( string $url ) => $urlExpander->expand( $url, $contentUrl );
Expand Down
22 changes: 20 additions & 2 deletions tests/Integration/Domain/MarkdownRendererTest.php
Expand Up @@ -20,9 +20,9 @@ public function testRendersSimpleMarkdown(): void {
}

public function testPurifiesContent(): void {
$this->assertSame(
$this->assertRendersAs(
'<p>I am </p><br />',
( new MarkdownRenderer() )->render( 'I am <script>evil</script><div><br></div>', '' )
'I am <script>evil</script><div><br></div>'
);
}

Expand Down Expand Up @@ -50,4 +50,22 @@ public function linkProvider(): iterable {
];
}

public function testRendersFencedCodeBlock(): void {
$this->assertRendersAs(
'<pre><code>Some codeMore code</code></pre>',
"~~~\nSome code\nMore code\n~~~"
);
}

private function assertRendersAs( string $expectedHtml, string $markdown ): void {
$this->assertSame(
$expectedHtml,
preg_replace(
'/\n+/', // Replace newlines since they get inserted pretty randomly between HTML tags
'',
( new MarkdownRenderer() )->render( $markdown, '' )
)
);
}

}

0 comments on commit bcc7995

Please sign in to comment.