Refactor prettier-markdown utilities for improved error handling and consistency in quote usage

This commit is contained in:
Luke Hagar
2025-11-10 17:37:54 +00:00
parent 8979826501
commit 95e48f6b71
3 changed files with 11 additions and 4 deletions

View File

@@ -53,7 +53,7 @@ if (!utils) {
const hasSingle = str.includes("'");
const hasDouble = str.includes('"');
if (hasSingle && !hasDouble) return '"';
return "'";
return '"';
},
};
}

View File

@@ -41,7 +41,6 @@ function createParse({ isMDX }) {
return processor.runSync(processor.parse(text));
};
}
}
function noop() {}

View File

@@ -186,9 +186,17 @@ function getOrderedListItemInfo(orderListItem, options) {
orderListItem.position.end.offset,
);
const { numberText, leadingSpaces } = text.match(
const m = text.match(
/^\s*(?<numberText>\d+)(\.|\))(?<leadingSpaces>\s*)/u,
).groups;
);
if (!m) {
throw new Error(
`Failed to parse ordered list item: expected pattern matching /^\\s*(?<numberText>\\d+)(\\.|\\))(?<leadingSpaces>\\s*)/u, but got: ${JSON.stringify(text)}`,
);
}
const { numberText, leadingSpaces } = m.groups;
return { number: Number(numberText), leadingSpaces };
}