Skip to content

Commit

Permalink
dm - dumb-ly hand the font you receive to html (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
danialm authored Jul 19, 2022
1 parent 1a98f54 commit 2aa81a2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/MinimalHTML.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`generators/MinimalHTML algorithm escapes HTML syntax 1`] = `
`;
exports[`generators/MinimalHTML algorithm handles fonts 1`] = `
"<!DOCTYPE html><html><body style=\\"color:#303030;font-weight:400;white-space:pre-wrap;font-family:sans-serif\\"><div><span style=\\"font-family:'Courier New'\\">Hello</span>, <span style=\\"font-family:serif\\">world</span>; do <span style=\\"font-weight:bold;font-family:monospace\\">you</span> like my fonts?
"<!DOCTYPE html><html><body style=\\"color:#303030;font-weight:400;white-space:pre-wrap;font-family:sans-serif\\"><div><span style=\\"font-family:'Courier New', monospace\\">Hello</span>, <span style=\\"font-family:serif\\">world</span>; do <span style=\\"font-weight:bold;font-family:monospace\\">you</span> like my fonts?
</div></body></html>"
`;
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/QuillHTML.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`generators/QuillHTML algorithm escapes HTML syntax 1`] = `
`;
exports[`generators/QuillHTML algorithm handles fonts 1`] = `
"<!DOCTYPE html><html><body><p><span style=\\"font-family:'Courier New'\\">Hello</span>, <span style=\\"font-family:serif\\">world</span>; do <span style=\\"font-weight:bold;font-family:monospace\\">you</span> like my fonts?
"<!DOCTYPE html><html><body><p><span style=\\"font-family:'Courier New', monospace\\">Hello</span>, <span style=\\"font-family:serif\\">world</span>; do <span style=\\"font-weight:bold;font-family:monospace\\">you</span> like my fonts?
</p></body></html>"
`;
Expand Down
4 changes: 1 addition & 3 deletions src/generators/MinimalHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const TEXTS: Record<string, TextFormatter> = {
span.styles.push(`color:${color}`);
},
font: (span, font) => {
const fontFamily =
typeof font === 'string' && font.includes(' ') ? `'${font}'` : font;
span.styles.push(`font-family:${fontFamily}`);
span.styles.push(`font-family:${font}`);
},
italic: (span) => {
span.styles.push('font-style:italic');
Expand Down
4 changes: 1 addition & 3 deletions src/generators/QuillHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const TEXTS: Record<string, TextFormatter> = {
span.styles.push(`color:${color}`);
},
font: (span, font) => {
const fontFamily =
typeof font === 'string' && font.includes(' ') ? `'${font}'` : font;
span.styles.push(`font-family:${fontFamily}`);
span.styles.push(`font-family:${font}`);
},
italic: (span) => {
span.styles.push('font-style:italic');
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/font.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"attributes": {
"font": "Courier New"
"font": "'Courier New', monospace"
},
"insert": "Hello"
},
Expand All @@ -27,4 +27,4 @@
{
"insert": " like my fonts?\n"
}
]
]

0 comments on commit 2aa81a2

Please sign in to comment.