Skip to content

Commit 95892e5

Browse files
committed
fix: do not add empty lines in the path d attribute
These are coming directly from Notion. No idea why they are doing it this way. It was not like this before. What basically happens is that our `preserveNewlinesIfApplicable` function will add `<br />` to the tag and it will totally break the KaTex. Fixes: #1382
1 parent e059cd3 commit 95892e5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/lib/parser/DeckParser.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,35 @@ export class DeckParser {
139139
}
140140
}
141141

142+
removeNewlinesInSVGPathAttributeD(html: string): string {
143+
const dom = cheerio.load(html);
144+
const pathElements = dom('path');
145+
146+
for (const pathElement of pathElements) {
147+
if ('attribs' in pathElement && 'd' in pathElement.attribs) {
148+
const dAttribute = pathElement.attribs.d;
149+
const newDAttribute = dAttribute.replace(/\n/g, '').trim();
150+
dom(pathElement).attr('d', newDAttribute);
151+
}
152+
}
153+
154+
return dom.html();
155+
}
156+
142157
handleHTML(
143158
fileName: string,
144159
contents: string,
145160
deckName: string,
146161
decks: Deck[]
147162
) {
148-
const dom = cheerio.load(
149-
this.settings.noUnderline
150-
? contents.replace(/border-bottom:0.05em solid/g, '')
151-
: contents
163+
let dom = cheerio.load(
164+
this.removeNewlinesInSVGPathAttributeD(
165+
this.settings.noUnderline
166+
? contents.replace(/border-bottom:0.05em solid/g, '')
167+
: contents
168+
)
152169
);
170+
153171
let name = deckName || dom('title').text();
154172
let style = dom('style').html();
155173
if (style) {

0 commit comments

Comments
 (0)