Skip to content

Commit a8ae68c

Browse files
committed
docs: udpate API generator
1 parent 68a6c8c commit a8ae68c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

packages/docs/build/api.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,28 @@ const TEXT_REPLACEMENTS = {
9595
* @param {string} text - The text to escape.
9696
* @returns {string} - The escaped text.
9797
*/
98+
const escInsideCode = (s) =>
99+
s
100+
.replaceAll(/\\/g, '\\\\')
101+
.replaceAll(/`/g, '\\`')
102+
.replaceAll(/\$\{/g, '\\${')
103+
.replaceAll(/[{}]/g, (m) => '\\' + m)
104+
98105
const escapeMarkdown = (text) => {
99106
if (typeof text !== 'string') return text
100-
return text
101-
.replaceAll(/(<)/g, String.raw`\$1`)
102-
.replaceAll('\n', '<br/>')
103-
.replaceAll(/`([^`]+)`/g, '<code>{`$1`}</code>')
107+
108+
let out = text
109+
110+
// 1) przypadek template literal: `... `...``
111+
out = out.replace(/`([\s\S]*?)``/g, (_, raw) => {
112+
const safe = escInsideCode(raw)
113+
return `<code>{\`${safe}\`}</code>`
114+
})
115+
116+
// 2) przypadek listowych wartości: `...` przed przecinkiem albo końcem
117+
out = out.replace(/`([^`]+?)`(?=\s*,|\s*$)/g, '<code>{`$1`}</code>')
118+
119+
return out
104120
}
105121

106122
/**

0 commit comments

Comments
 (0)