diff --git a/README.md b/README.md index dc093267..4731ac1a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ You can use several variables to modify extension's behaviour: - `$wgPortableInfoboxResponsiblyOpenCollapsed` (bool) - open collapsed groups when the screen is narrow. (default: true) - `$wgPortableInfoboxUseFileDescriptionPage` (bool) - control whether or not embedded images in the infobox will link to their file description page instead of directly to the file. (default: false) +### Parsoid +PortableInfobox has support for displaying infoboxes when rendering an article using Parsoid. This has been tested against MediaWiki 1.45 and is not guaranteed to work in earlier versions. + +There are still some issues, and the implementation is not bug free, however it should display most infoboxes - infoboxes will also display in the VisualEditor. + +When using PortableInfoboxes and Parsoid, you **must** set `$wgPortableInfoboxUseHeadings = false` otherwise Parsoid will wrap the headings in the infobox in section tags which will break formatting and styling. ## Usage See: https://community.fandom.com/wiki/Help:Infoboxes diff --git a/extension.json b/extension.json index 349d9bbd..5f3e1818 100644 --- a/extension.json +++ b/extension.json @@ -7,7 +7,7 @@ ], "url": "https://github.com/Universal-Omega/PortableInfobox", "descriptionmsg": "portable-infobox-desc", - "version": "0.8", + "version": "1.0", "type": "parserhook", "license-name": "GPL-3.0-or-later", "requires": { @@ -15,7 +15,11 @@ }, "config": { "AllInfoboxesExcludedSubpages": { - "value": [ "doc", "draft", "test" ] + "value": [ + "doc", + "draft", + "test" + ] }, "PortableInfoboxCacheRenderers": { "value": false @@ -125,5 +129,6 @@ "APIListModules": { "allinfoboxes": "PortableInfobox\\Controllers\\ApiQueryAllInfoboxes" }, + "ParsoidModules": [ "PortableInfobox\\Parsoid\\InfoboxTag" ], "manifest_version": 2 -} +} \ No newline at end of file diff --git a/includes/Parsoid/InfoboxTag.php b/includes/Parsoid/InfoboxTag.php new file mode 100644 index 00000000..686b9363 --- /dev/null +++ b/includes/Parsoid/InfoboxTag.php @@ -0,0 +1,52 @@ + 'PortableInfobox', + 'tags' => [ + [ + 'name' => 'infobox', + 'handler' => self::class + ] + ], + 'domProcessors' => [ + 'PortableInfobox\\Parsoid\\PortableInfoboxDOMProcessor' + ] + ]; + } + + /** + * @inheritDoc + */ + public function sourceToDom( ParsoidExtensionAPI $api, string $src, array $args ) { + $domFragments = $api->extTagToDOM( $args, $src, [ + 'wrapperTag' => 'aside', + 'parseOpts' => [ + 'extTag' => 'infobox', + 'context' => 'inline' + ] + ] ); + + // this is a bit messed up as these methods are deprecated, but the documentation + // for the replacement methods doesn't exist or make sense + // this is commented out at present, as these scripts and styles will be added + // by the legacy parser (might need it here to stick these in the parser cache also?) + $api->getMetadata()->addModules( [ 'ext.PortableInfobox.scripts' ] ); + $api->getMetadata()->addModuleStyles( [ 'ext.PortableInfobox.styles' ] ); + + // return this back. At this point, we have constructed the outer tag (