Skip to content

Commit 06ec767

Browse files
fix: πŸ› google doc paste (#1773)
* fix: πŸ› google doc paste βœ… Closes: #1209 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 66c465a commit 06ec767

File tree

1 file changed

+14
-1
lines changed
  • packages/plugins/preset-commonmark/src/mark

1 file changed

+14
-1
lines changed

Diff for: β€Žpackages/plugins/preset-commonmark/src/mark/strong.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@ export const strongSchema = $markSchema('strong', (ctx) => ({
2626
},
2727
},
2828
parseDOM: [
29-
{ tag: 'b' },
29+
// This works around a Google Docs misbehavior where
30+
// pasted content will be inexplicably wrapped in `<b>`
31+
// tags with a font-weight normal.
32+
{
33+
tag: 'b',
34+
getAttrs: (node: HTMLElement) =>
35+
node.style.fontWeight != 'normal' && null,
36+
},
3037
{ tag: 'strong' },
3138
{ style: 'font-style', getAttrs: (value) => (value === 'bold') as false },
39+
{ style: 'font-weight=400', clearMark: (m) => m.type.name == 'strong' },
40+
{
41+
style: 'font-weight',
42+
getAttrs: (value: string) =>
43+
/^(bold(er)?|[5-9]\d{2,})$/.test(value) && null,
44+
},
3245
],
3346
toDOM: (mark) => ['strong', ctx.get(strongAttr.key)(mark)],
3447
parseMarkdown: {

0 commit comments

Comments
Β (0)