Skip to content

Commit

Permalink
fix: do not add empty lines in the path d attribute
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aalemayhu committed Dec 28, 2023
1 parent e059cd3 commit 95892e5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/lib/parser/DeckParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,35 @@ export class DeckParser {
}
}

removeNewlinesInSVGPathAttributeD(html: string): string {
const dom = cheerio.load(html);
const pathElements = dom('path');

for (const pathElement of pathElements) {
if ('attribs' in pathElement && 'd' in pathElement.attribs) {
const dAttribute = pathElement.attribs.d;
const newDAttribute = dAttribute.replace(/\n/g, '').trim();
dom(pathElement).attr('d', newDAttribute);
}
}

return dom.html();
}

handleHTML(
fileName: string,
contents: string,
deckName: string,
decks: Deck[]
) {
const dom = cheerio.load(
this.settings.noUnderline
? contents.replace(/border-bottom:0.05em solid/g, '')
: contents
let dom = cheerio.load(
this.removeNewlinesInSVGPathAttributeD(
this.settings.noUnderline
? contents.replace(/border-bottom:0.05em solid/g, '')
: contents
)
);

let name = deckName || dom('title').text();
let style = dom('style').html();
if (style) {
Expand Down

0 comments on commit 95892e5

Please sign in to comment.