Skip to content

Commit cb74a9c

Browse files
committed
Add link handling to rich-text-to-markdown
Convert <a href="url">text</a> elements to [text](url) markdown syntax in the htmlToMarkdown function. https://claude.ai/code/session_018q9Arxy2HrpsyNB13wpwxQ
1 parent 70393ec commit cb74a9c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

rich-text-to-markdown.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<h1>Rich Text to Markdown</h1>
116116

117117
<div class="instructions">
118-
<strong>Instructions:</strong> Paste rich text below. Bold text will be converted to <code>**markdown bold**</code> and leading spaces will be removed.
118+
<strong>Instructions:</strong> Paste rich text below. Bold text will be converted to <code>**markdown bold**</code>, links will be converted to <code>[text](url)</code>, and leading spaces will be removed.
119119
</div>
120120

121121
<textarea class="paste-area" placeholder="Click here and paste your rich text (Cmd+V or Ctrl+V)..."></textarea>
@@ -345,6 +345,15 @@ <h1>Rich Text to Markdown</h1>
345345
return `${leadingSpace}**${trimmed}**${trailingSpace}`;
346346
}
347347

348+
// Handle links
349+
if (tag === 'a') {
350+
const href = node.getAttribute('href');
351+
if (href && childContent.trim()) {
352+
return `[${childContent.trim()}](${href})`;
353+
}
354+
return childContent;
355+
}
356+
348357
// Handle line breaks
349358
if (tag === 'br') {
350359
return '\n';

0 commit comments

Comments
 (0)