Skip to content

Commit 05cbdd7

Browse files
authored
fix: support string and object for token.htmlStyle (#28)
* fix: support string and object for htmlStyle * chore: update shiki
1 parent e89f689 commit 05cbdd7

16 files changed

+510
-30
lines changed

bin/renderer.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,27 @@ const renderToHtml = function (lines, options = {}) {
9696
l.forEach((token) => {
9797
const cssDeclarations = [];
9898
if (theme) {
99-
cssDeclarations.push(`color: ${token.color || theme.theme.fg}`);
99+
cssDeclarations.push(`color:${token.color || theme.theme.fg}`);
100100
} else if (themes) {
101-
cssDeclarations.push(token.htmlStyle);
101+
/**
102+
* The `htmlStyle` property can be a `string` or an `object`. The `string` representation is deprecated.
103+
* @see https://github.com/search?q=repo%3Ashikijs%2Fshiki+htmlStyle&type=code
104+
*/
105+
if (typeof token.htmlStyle === "string") {
106+
cssDeclarations.push(token.htmlStyle);
107+
} else if (typeof token.htmlStyle === "object") {
108+
for (const [key, value] of Object.entries(
109+
token.htmlStyle
110+
)) {
111+
cssDeclarations.push(`${key}:${value}`);
112+
}
113+
}
102114
}
103115

104116
if (token.fontStyle > FontStyle.None) {
105117
cssDeclarations.push(FONT_STYLE_TO_CSS[token.fontStyle]);
106118
}
107-
html += `<span style="${cssDeclarations.join("; ")}">${escapeHtml(
119+
html += `<span style="${cssDeclarations.join(";")}">${escapeHtml(
108120
token.content
109121
)}</span>`;
110122
});

0 commit comments

Comments
 (0)