Strip comments from toc section lines

Change-Id: Ide4462b9df5d02b088bf2f1c83a3c5f119366a95
This commit is contained in:
Arlo Breault 2024-02-19 13:04:39 -05:00
parent 87e257dd27
commit abf45611d7
2 changed files with 28 additions and 0 deletions

View file

@ -170,6 +170,11 @@ class ParserFileProcessingHookHandlers implements
$parserOutput->setIndicator( $id, $stripped );
}
}
// Strip comments from TOC data
$tocData = $parserOutput->getTOCData();
foreach ( ( $tocData ? $tocData->getSections() : [] ) as $section ) {
$section->line = trim( preg_replace( self::CANDIDATE_REGEX, '', $section->line ) );
}
}
/**

View file

@ -37,6 +37,8 @@ PageImages with best excluded by wgPageImagesLeadSectionOnly
!! options
property=page_image_free
disabled
!! config
wgParserEnableLegacyMediaDOM=false
!! metadata
property[page_image_free]=Thumb.png
!! wikitext
@ -52,3 +54,24 @@ property[page_image_free]=Thumb.png
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a>
</p>
!! end
!! test
PageImages with toc and image in heading
!! options
property=page_image_free
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
__TOC__
== Hello [[File:Foobar.jpg]] ==
!! metadata
property[page_image_free]=Foobar.jpg
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext">Hello</span></a></li>
</ul>
</div>
<h2><span class="mw-headline" id="Hello">Hello <span class="mw-default-size" typeof="mw:File"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" class="mw-file-element" /></a></span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Hello">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end