diff --git a/src/plugin.ts b/src/plugin.ts index a65345f2..27ef8340 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -229,3 +229,17 @@ export function fragment(section: Section): Section { section.body = $.html(); return section; } + +export function unsetBlackOrWhiteFont(section: Section): Section { + const $ = cheerio.load(section.body); + const spans = $('span'); + spans.map((_i, el) => { + const span = $(el); + const color = span.css('color'); + if (color === 'rgb(255,255,255)' || color === 'rgb(0,0,0)') { + span.css('color', ''); + } + }); + section.body = $.html(); + return section; +} diff --git a/src/routes/index.ts b/src/routes/index.ts index edf6e821..a8abf43a 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -4,7 +4,7 @@ import * as querystring from 'querystring'; import * as _ from 'lodash'; import { Section, host, splitPinnedPages } from '../util'; -import { attached, backgroundImage, mermaid, gliffy, link, code, fragment, emoticon } from '../plugin'; +import { attached, backgroundImage, mermaid, gliffy, link, code, fragment, emoticon, unsetBlackOrWhiteFont } from '../plugin'; const context = process.env.CONTEXT; const username = process.env.USERNAME; @@ -64,7 +64,8 @@ router.get('/page/:id', (req, res, next) => { mermaid, link, code, - fragment + fragment, + unsetBlackOrWhiteFont ]; return middlewares.reduce((section, middleware) => middleware(section), section); } diff --git a/src/spec/index.spec.ts b/src/spec/index.spec.ts index daf1b698..29da504c 100644 --- a/src/spec/index.spec.ts +++ b/src/spec/index.spec.ts @@ -1,5 +1,5 @@ import { convertImageSrcSet, sanitizeImageSrc, setHost, splitPinnedPages, parseParams } from '../util'; -import { fragment } from '../plugin'; +import { fragment, unsetBlackOrWhiteFont } from '../plugin'; function html(inner) { return { body: '' + inner + '' }; @@ -66,5 +66,24 @@ describe('miniseminar', () => { '' )); }); - }) + }); +}); + +describe('trouble shooting', () => { + it('should clear format if the span colored with real black', () => { + const body = 'abc'; + expect(unsetBlackOrWhiteFont({ body })).toEqual(html('abc')); + }); + it('should clear format if the span colored with real white', () => { + const body = 'abc'; + expect(unsetBlackOrWhiteFont({ body })).toEqual(html('abc')); + }); + it('should not clear format if the span colored with real white or real black', () => { + const body = 'abc'; + expect(unsetBlackOrWhiteFont({ body })).toEqual(html('abc')); + }); + it('should clear format if the span colored with real white having children', () => { + const body = 'abc google'; + expect(unsetBlackOrWhiteFont({ body })).toEqual(html('abc google')); + }); });