From 373ed0112314588c4a45896cb88e6418f6ccab38 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Wed, 23 Oct 2024 13:03:01 +0200 Subject: [PATCH] Parsoid wiring for footnote mark formatting After this patch, Parsoid-rendered pages will include the same footnote markers as the legacy parser for custom group markers. The divergent CSS implementation is left intact, for a soft migration. Bug: T377454 Change-Id: I576dfff4155fb8c2f91ef0d28a65b319aa5bbb07 --- src/Parsoid/References.php | 7 ++++++- tests/parser/citeParserTests.txt | 12 +++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 122449896..49dae62b0 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -6,8 +6,10 @@ declare( strict_types = 1 ); namespace Cite\Parsoid; +use Cite\MarkSymbolRenderer; use Closure; use MediaWiki\Config\Config; +use MediaWiki\MediaWikiServices; use stdClass; use Wikimedia\Parsoid\Core\DomSourceRange; use Wikimedia\Parsoid\DOM\DocumentFragment; @@ -29,9 +31,12 @@ use Wikimedia\Parsoid\Utils\DOMCompat; */ class References extends ExtensionTagHandler { private Config $mainConfig; + private MarkSymbolRenderer $markSymbolRenderer; public function __construct( Config $mainConfig ) { $this->mainConfig = $mainConfig; + + $this->markSymbolRenderer = MediaWikiServices::getInstance()->getService( 'Cite.MarkSymbolRenderer' ); } private static function hasRef( Node $node ): bool { @@ -411,7 +416,7 @@ class References extends ExtensionTagHandler { $refLinkSpan = $doc->createElement( 'span' ); $refLinkSpan->setAttribute( 'class', 'mw-reflink-text' ); $refLinkSpan->appendChild( $doc->createTextNode( - '[' . ( $ref->group ? $ref->group . ' ' : '' ) . $ref->groupIndex . ']' + '[' . $this->markSymbolRenderer->makeLabel( $ref->group, $ref->groupIndex ) . ']' ) ); $refLink->appendChild( $refLinkSpan ); diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt index 495240b36..3874fe7d3 100644 --- a/tests/parser/citeParserTests.txt +++ b/tests/parser/citeParserTests.txt @@ -1039,11 +1039,6 @@ MediaWiki:cite_link_label_group-klingon wa' cha' wej loS vagh jav Soch chorgh Hut wa'maH !! endarticle -## Parsoid doesn't use messages for i18n. It relies on Cite-specific CSS rules -## to localize. This CSS is expected to be added to a wiki's -## MediaWiki:Common.css page. -## As such, Parsoid's output will differ for klingon i18n label tests. -## T308094: document this transition. !! test with custom group link with number names in Klingon !! wikitext @@ -1058,12 +1053,11 @@ Wikipedia rocks!Proceeds of Rockology, vol. XXI !! html/parsoid -

Wikipedia rocks![klingon 1]

+

Wikipedia rocks![wa']

  1. Proceeds of Rockology, vol. XXI
!! end -# See above: Parsoid uses a different mechanism for custom link labels !! test Consecutive whitespace in custom link label message should not create empty [] !! wikitext @@ -1081,8 +1075,8 @@ Consecutive whitespace in custom link label message should not create empty [] !! html/parsoid -

[klingon 1] -[klingon 2]

+

[wa'] +[cha']

  1. 1st
  2. 2nd
!! end