Skip to content

Commit

Permalink
🏷️ Label duplication warning (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Jan 6, 2025
1 parent c5e5158 commit 0d82810
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lucky-squids-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-common": patch
---

Improve label duplication warning
7 changes: 6 additions & 1 deletion packages/myst-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ export function createHtmlId(identifier?: string): string | undefined {
*/
export function transferTargetAttrs(sourceNode: GenericNode, destNode: GenericNode, vfile?: VFile) {
if (sourceNode.label) {
if (destNode.label && vfile) {
if (destNode.label && vfile && destNode.label !== sourceNode.label) {
fileWarn(vfile, `label "${destNode.label}" replaced with "${sourceNode.label}"`, {
node: destNode,
});
}
if (destNode.label && vfile && destNode.label === sourceNode.label) {
fileWarn(vfile, `duplicate label "${destNode.label}" replacement`, {
node: destNode,
});
}
destNode.label = sourceNode.label;
delete sourceNode.label;
}
Expand Down

0 comments on commit 0d82810

Please sign in to comment.