-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Markdown Link Extractor with WeChat Link Exclusion</title> | ||
<style> | ||
#inputMarkdown, #outputMarkdown { | ||
width: 90%; | ||
height: 150px; | ||
margin: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<h2>Markdown Link Extractor with WeChat Link Exclusion</h2> | ||
<textarea id="inputMarkdown" placeholder="输入Markdown内容..."></textarea><br> | ||
<button onclick="extractAndAppendLinks()">提取并追加链接</button><br> | ||
<textarea id="outputMarkdown" readonly placeholder="处理后的结果..."></textarea> | ||
|
||
<script> | ||
function extractAndAppendLinks() { | ||
let inputText = document.getElementById('inputMarkdown').value; | ||
let output = document.getElementById('outputMarkdown'); | ||
|
||
// 分段处理,以换行符分割文本 | ||
let paragraphs = inputText.split('\n\n'); | ||
let processedParagraphs = paragraphs.map(paragraph => { | ||
// 正则表达式匹配Markdown链接格式 | ||
const linkRegex = /\[([^\]]+)\]\((https?:\/\/[^\s)]+)(?: "[^"]*")?\)/g; | ||
let links = []; | ||
let result; | ||
let processedText = paragraph; | ||
|
||
// 循环匹配并收集所有链接,跳过微信链接 | ||
while ((result = linkRegex.exec(paragraph)) !== null) { | ||
if (!result[2].includes('mp.weixin.qq.com')) { | ||
links.push({ | ||
title: result[1], | ||
url: result[2] | ||
}); | ||
} | ||
} | ||
|
||
// 构建并追加链接到当前段落 | ||
if (links.length > 0) { | ||
let linksString = links.map(link => `- ${link.title}\n<url>${link.url}</url>`).join('\n'); | ||
processedText += '\n\n' + linksString; // 追加链接到当前段落下面 | ||
} | ||
|
||
return processedText; | ||
}); | ||
|
||
// 将处理后的段落重新拼接成一个字符串,并显示在输出框中 | ||
output.value = processedParagraphs.join('\n\n'); | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |