-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve the toggle rendering on the back
Fixes a regression due to changes in the Notion style.
- Loading branch information
Showing
4 changed files
with
67 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import cheerio from 'cheerio'; | ||
import { extractStyles } from './extractStyles'; | ||
|
||
describe('extractStyles', () => { | ||
|
||
it('should remove list-style-type changes', () => { | ||
const page = cheerio.load(` | ||
<style>.toggle { | ||
\tpadding-inline-start: 0em; | ||
\tlist-style-type: none; | ||
}</style> | ||
`); | ||
|
||
const result = extractStyles(page); | ||
expect(result?.trim()).toEqual(`.toggle { | ||
\tpadding-inline-start: 0em; | ||
\t | ||
}`.trim()); | ||
}); | ||
|
||
it('should remove white-space: pre-wrap', () => { | ||
const page = cheerio.load(` | ||
<style>.toggle { | ||
\tpadding-inline-start: 0em; | ||
\twhite-space: pre-wrap; | ||
}</style>`); | ||
const result = extractStyles(page); | ||
expect(result?.trim()).toEqual(`.toggle { | ||
\tpadding-inline-start: 0em; | ||
\t | ||
}`.trim()); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import cheerio from 'cheerio'; | ||
|
||
/** | ||
* Extracts the styles from the page and removes formatting issues. | ||
* | ||
* Removing list-style-type changes (makes nested toggles work) | ||
* Removing white-space: pre-wrap (don't remember why) | ||
* | ||
* @param page | ||
*/ | ||
export function extractStyles(page: cheerio.Root) { | ||
let style = page('style').html(); | ||
if (!style) { | ||
return null; | ||
} | ||
|
||
return style | ||
.replace(/white-space: pre-wrap;/g, '') | ||
.replace(/list-style-type: none;/g, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function withFontSize(style: string | null, fontSize?: string) { | ||
if (style && fontSize && fontSize !== '20px') { | ||
// For backwards compatability, don't touch the font-size if it's 20px | ||
fontSize = fontSize.trim().endsWith('px') ? fontSize : `${fontSize}px`; | ||
style += '\n' + `* { font-size:${fontSize}}`; | ||
} | ||
return style; | ||
} |