Skip to content

Commit f5149dc

Browse files
committed
Add parsing for GitHub-style hashtags without breaking single-quotes.
2 parents ff2c832 + 9232da2 commit f5149dc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/parser.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ export class MarkdownParser {
172172
return html;
173173
}
174174

175+
/**
176+
* Parse GitHub-style issue/PR references
177+
* @param {string} html - HTML with potential GitHub references
178+
* @returns {string} HTML with styled GitHub references
179+
*/
180+
static parseHashtagNumerals(html) {
181+
// Match #123 patterns with word boundaries
182+
// (?<![&#\w]) ensures # is not in the middle of a word or part of an HTML entity
183+
// (?!\w) ensures the number is followed by a non-word character or end
184+
return html.replace(
185+
/(?<![&#\w])(#\d+)(?!\w)/g,
186+
'<span class="hashtag">$1</span>'
187+
);
188+
}
189+
175190
/**
176191
* Parse strikethrough text
177192
* Supports both single (~) and double (~~) tildes, but rejects 3+ tildes
@@ -385,9 +400,10 @@ export class MarkdownParser {
385400

386401
// Transform link sanctuary to HTML
387402
// URL should NOT be processed for markdown - use it as-is
403+
// Note: sanctuary.url is already escaped since it came from escaped HTML
388404
const anchorName = `--link-${this.linkIndex++}`;
389405
const safeUrl = this.sanitizeUrl(sanctuary.url);
390-
replacement = `<a href="${safeUrl}" style="anchor-name: ${anchorName}"><span class="syntax-marker">[</span><span class="link-text">${processedLinkText}</span><span class="syntax-marker">](</span><span class="url-part">${this.escapeHtml(sanctuary.url)}</span><span class="syntax-marker">)</span></a>`;
406+
replacement = `<a href="${safeUrl}" style="anchor-name: ${anchorName}"><span class="syntax-marker">[</span><span class="link-text">${processedLinkText}</span><span class="syntax-marker">](</span><span class="url-part">${sanctuary.url}</span><span class="syntax-marker">)</span></a>`;
391407
}
392408

393409
html = html.replace(placeholder, replacement);
@@ -411,6 +427,7 @@ export class MarkdownParser {
411427
html = this.parseStrikethrough(html);
412428
html = this.parseBold(html);
413429
html = this.parseItalic(html);
430+
html = this.parseHashtagNumerals(html);
414431

415432
// Step 3: Restore and transform sanctuaries
416433
html = this.restoreAndTransformSanctuaries(html, sanctuaries);

src/styles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ export function generateStyles(options = {}) {
364364
color: rgb(142, 182, 241);
365365
}
366366
367+
.overtype-preview .hashtag {
368+
color: var(--link, #0066cc) !important;
369+
text-decoration: underline !important;
370+
}
371+
367372
/* Lists - no list styling */
368373
.overtype-wrapper .overtype-preview ul,
369374
.overtype-wrapper .overtype-preview ol {

0 commit comments

Comments
 (0)