Skip to content

Commit cfb3547

Browse files
committed
feat: avoid id clobbering
1 parent ba2fbc4 commit cfb3547

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/bytemd/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ export interface ViewerProps {
9797
*/
9898
plugins?: BytemdPlugin[];
9999
/**
100-
* An option to change the default sanitize schema.
100+
* Customize the default sanitize schema
101101
*
102-
* Defaults to GitHub style sanitation except that the `class` attribute is allowed
102+
* Defaults to GitHub style sanitation except:
103+
*
104+
* 1. `className` is allowed
105+
* 2. `id` is kept as is without clobbering
103106
*
104107
* https://github.com/syntax-tree/hast-util-sanitize/blob/main/lib/github.json
105108
*/

packages/bytemd/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function getProcessor({
2626

2727
let schema = JSON.parse(schemaStr);
2828
schema.attributes['*'].push('className'); // Add className
29+
schema.clobber = schema.clobber.filter((vs: string) => vs !== 'id'); // Keep id as is
2930
if (sanitize) schema = sanitize(schema);
3031

3132
p = p.use(rehypeSanitize, schema);

0 commit comments

Comments
 (0)