diff --git a/.gitignore b/.gitignore index 3c76c1ec..973a22b0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ coverage mwo-test-* .vscode .tool-versions +output/ diff --git a/src/renderers/wikimedia-mobile.renderer.ts b/src/renderers/wikimedia-mobile.renderer.ts index b1e8b950..b3c64047 100644 --- a/src/renderers/wikimedia-mobile.renderer.ts +++ b/src/renderers/wikimedia-mobile.renderer.ts @@ -37,6 +37,7 @@ export class WikimediaMobileRenderer extends MobileRenderer { this.INTERNAL.convertLazyLoadToImages, this.removeEditContainer, this.removeHiddenClass, + this.INTERNAL.unhideSections, async (doc) => { const { finalHTML, subtitles, mediaDependencies } = await super.processHtml( doc.documentElement.outerHTML, @@ -130,6 +131,16 @@ export class WikimediaMobileRenderer extends MobileRenderer { return doc } + private unhideSectionsImpl(doc: DominoElement) { + const sections = doc.querySelectorAll('section') + Array.from(sections).forEach((section: DominoElement) => { + // Domino doesn't allow us to easily manipulate specific styles. Rather than trying to parse + // the style attribute and remove display: none, we just clobber the whole thing. + section.style = '' + }) + return doc + } + private restoreLinkDefaults(doc: DominoElement) { const supElements = doc.querySelectorAll('sup') @@ -159,5 +170,6 @@ export class WikimediaMobileRenderer extends MobileRenderer { public readonly INTERNAL = { convertLazyLoadToImages: this.convertLazyLoadToImagesImpl, + unhideSections: this.unhideSectionsImpl, } } diff --git a/test/unit/renderers/mobile.renderer.test.ts b/test/unit/renderers/mobile.renderer.test.ts index e11aa661..44f6487c 100644 --- a/test/unit/renderers/mobile.renderer.test.ts +++ b/test/unit/renderers/mobile.renderer.test.ts @@ -5,6 +5,45 @@ import { WikimediaMobileRenderer } from '../../../src/renderers/wikimedia-mobile describe('mobile renderer', () => { let window + describe('unhiding sections', () => { + beforeEach(() => { + // Snippet of an article with nested hidden sections. + window = domino.createWindow( + ` +
+
+

Dugu kilatogo

+ + + +
+

Mali kila ...

+ +

Nafasɔrɔsira

+
+
  • Bagan kumaba là millions mugan ni fila dɛ fɛrɛ san kɔnɔ.
  • +
  • Sanu bɛ Mali la fa ni dɛ diɔyɔrɔ filana dɛ farifina diɔrɔ ka ni cory ni mangoro yɛ u ka fin fɛrɛ ta yɛ Mali kɔnɔ.
+
+ +

Mali

+
+ `, + 'https://bm.wikipedia.org/api/rest_v1/page/mobile-html/Mali', + ) + }) + + test('it removes the hidden class from sections', async () => { + const mobileRenderer = new WikimediaMobileRenderer() + + const actual = mobileRenderer.INTERNAL.unhideSections(window.document) + const sections = actual.querySelectorAll('section') + + expect(sections.length).toBe(2) + expect(sections[0].style.display).toBe('') + expect(sections[1].style.display).toBe('') + }) + }) + describe('image converter', () => { beforeEach(() => { window = domino.createWindow(