Require a letter after each email domain dot and keep text joins linear

An address like _a_@b.-c.com is not a GFM bare email, so emitting it bare let the underscores become emphasis; it now uses the explicit mailto link. Joining split text no longer copies the previous node on every merge.

Co-authored-by: LDH1103 <ldh517525@gmail.com>
This commit is contained in:
Brennan Benson
2026-11-16 01:52:40 -08:00
co-authored by LDH1103
parent bb0e874d6d
commit b7fc6a56ad
3 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ function supportsBareAutolink(value: string): boolean {
const authority = /^(?:https?:\/\/|www\.)([^/?#]*)/i.exec(value)?.[1]
if (authority === undefined) {
// GFM's bare-email grammar is narrower than the angle-autolink local part the scanner accepts.
return /^[-.\w+]+@[-\w]+(?:\.[-\w]+)+$/.test(value) && !/[-\d_]$/.test(value)
return /^[-.\w+]+@[-\w]+(?:\.[A-Za-z0-9][-\w]*)+$/.test(value) && !/[-\d_]$/.test(value)
}
return /^[\p{L}\p{N}][\p{L}\p{N}.-]*(?::[0-9]+)?$/u.test(authority)
}
+5 -1
View File
@@ -160,7 +160,11 @@ function joinedTextRuns(children: unknown[]): Record<string, unknown>[] {
const previous = runs.at(-1)
const marks = typeof node.text === 'string' ? JSON.stringify(node.marks ?? []) : ''
if (marks && typeof previous?.text === 'string' && marks === previousMarks) {
runs[runs.length - 1] = { ...previous, text: previous.text + node.text }
runs[runs.length - 1] = {
type: 'text',
text: previous.text + node.text,
marks: previous.marks
}
} else {
runs.push(node)
}
+4 -3
View File
@@ -786,10 +786,11 @@ it('keeps ambiguous URL authorities active through real Markdown read-back', asy
href: 'http://www.foo_bar.com/'
},
{ text: 'http://-foo.com/', markdown: '<http://-foo.com/>', href: 'http://-foo.com/' },
{ text: '*a*@b.com', markdown: '[\\*a\\*@b.com](mailto:*a*@b.com)', href: 'mailto:*a*@b.com' },
{
text: '*foo*@example.com',
markdown: '[\\*foo\\*@example.com](mailto:*foo*@example.com)',
href: 'mailto:*foo*@example.com'
text: '_a_@b.-c.com',
markdown: '[\\_a\\_@b.-c.com](mailto:_a_@b.-c.com)',
href: 'mailto:_a_@b.-c.com'
},
{
text: ['https://example.com', '/docs'],