diff --git a/src/PageParser.php b/src/PageParser.php
index 8592e9a..8641bf8 100644
--- a/src/PageParser.php
+++ b/src/PageParser.php
@@ -442,8 +442,11 @@ private function cleanRedLinks() {
private function cleanReferenceLinks() {
$links = $this->xPath->query(
- '//*[@typeof="mw:Extension/ref"]/a | //a[@rel="mw:referencedBy"]'
+ '//*[contains(@typeof,"mw:Extension/ref")]/a | //a[@rel="mw:referencedBy"]'
);
+ if ( !$links ) {
+ return;
+ }
foreach ( $links as $link ) {
$href = $link->getAttribute( 'href' );
$pos = strpos( $href, '#' );
diff --git a/tests/Book/PageParserTest.php b/tests/Book/PageParserTest.php
index 957e2c3..1a9c561 100644
--- a/tests/Book/PageParserTest.php
+++ b/tests/Book/PageParserTest.php
@@ -233,4 +233,25 @@ public function provideGetPicturesList(): array {
],
];
}
+
+ /**
+ * @dataProvider provideCleanReferenceLinks
+ */
+ public function testCleanReferenceLinks( string $html, string $expected ) {
+ $pageParser1 = new PageParser( Util::buildDOMDocumentFromHtml( $html ) );
+ $this->assertStringContainsString( $expected, $pageParser1->getContent( false )->saveXML() );
+ }
+
+ public function provideCleanReferenceLinks() {
+ return [
+ 'no links to clean' => [
+ '[1]',
+ '',
+ ],
+ 'ref that is also transcluded' => [
+ '[1]',
+ '',
+ ],
+ ];
+ }
}