diff --git a/extension.json b/extension.json index 190f6ca..2eaebc2 100644 --- a/extension.json +++ b/extension.json @@ -40,6 +40,17 @@ "CodeEditorGetPageLanguage": "ProfessionalWiki\\NativeMarkdown\\EntryPoints\\NativeMarkdownHooks::onCodeEditorGetPageLanguage" }, + "ResourceFileModulePaths": { + "localBasePath": "resources", + "remoteExtPath": "NativeMarkdown" + }, + + "ResourceModules": { + "ext.nativeMarkdown.styles": { + "styles": [ "ext.nativeMarkdown.styles.css" ] + } + }, + "config": { "NativeMarkdownNamespaces": { "description": "Namespaces (IDs) in which new pages default to the markdown content model.", diff --git a/resources/ext.nativeMarkdown.styles.css b/resources/ext.nativeMarkdown.styles.css new file mode 100644 index 0000000..25c0c81 --- /dev/null +++ b/resources/ext.nativeMarkdown.styles.css @@ -0,0 +1,9 @@ +/* Skins style the bare `code` element for inline code (background, border, + padding). CommonMark nests `code` inside `pre` for fenced code blocks, a + combination wikitext never produces, so that inline styling paints a pill + per line there. Reset it; the `pre` container provides the block styling. */ +.mw-parser-output pre > code { + background-color: transparent; + border: 0; + padding: 0; +} diff --git a/src/EntryPoints/MarkdownContentHandler.php b/src/EntryPoints/MarkdownContentHandler.php index 514eb23..4f43ff1 100644 --- a/src/EntryPoints/MarkdownContentHandler.php +++ b/src/EntryPoints/MarkdownContentHandler.php @@ -136,6 +136,7 @@ protected function fillParserOutput( Content $content, ContentParseParams $cpoPa ); $output->setFromParserOptions( $cpoParams->getParserOptions() ); + $output->addModuleStyles( [ 'ext.nativeMarkdown.styles' ] ); $this->registerLinks( $output, $rendered ); $this->registerCategories( $output, $rendered ); diff --git a/tests/phpunit/EntryPoints/MarkdownContentHandlerTest.php b/tests/phpunit/EntryPoints/MarkdownContentHandlerTest.php index 363db02..8cf254c 100644 --- a/tests/phpunit/EntryPoints/MarkdownContentHandlerTest.php +++ b/tests/phpunit/EntryPoints/MarkdownContentHandlerTest.php @@ -34,6 +34,12 @@ public function testRendersMarkdownAsHtml(): void { $this->assertStringContainsString( 'bold', $output->getRawText() ); } + public function testAddsCodeBlockStyleModule(): void { + $output = $this->getParserOutput( "```python\nprint(42)\n```" ); + + $this->assertContains( 'ext.nativeMarkdown.styles', $output->getModuleStyles() ); + } + public function testRegistersInternalLinks(): void { $output = $this->getParserOutput( 'See [[Linked Page]] and [[Another One|label]]' );