Skip to content

Commit

Permalink
feat: add spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglu authored Mar 11, 2024
1 parent 4af5501 commit 5527bcd
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions markdownUrls.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Markdown Link Extractor with WeChat Link Exclusion</title>
<title>Markdown Formatter and Link Extractor</title>
<style>
#inputMarkdown, #outputMarkdown {
width: 90%;
height: 150px;
height: 200px;
margin: 10px;
}
</style>
</head>
<body>

<h2>Markdown Link Extractor with WeChat Link Exclusion</h2>
<h2>Markdown Formatter and Link Extractor</h2>
<textarea id="inputMarkdown" placeholder="输入Markdown内容..."></textarea><br>
<button onclick="extractAndAppendLinks()">提取并追加链接</button><br>
<button onclick="formatAndExtractLinks()">格式化并提取链接</button><br>
<textarea id="outputMarkdown" readonly placeholder="处理后的结果..."></textarea>

<script>
function extractAndAppendLinks() {
function formatAndExtractLinks() {
let inputText = document.getElementById('inputMarkdown').value;
let output = document.getElementById('outputMarkdown');

// 保留代码块内容
let codeBlocks = [];
let codeBlockRegex = /```[\s\S]*?```/g;
inputText = inputText.replace(codeBlockRegex, match => {
codeBlocks.push(match);
return '\0'; // 使用空字符作为占位符
});

// 自动在数字和中文、中英文之间加入空格
inputText = inputText.replace(/([\u4e00-\u9fa5])([A-Za-z0-9])/g, '$1 $2');
inputText = inputText.replace(/([A-Za-z0-9])([\u4e00-\u9fa5])/g, '$1 $2');

// 转换全角括号并添加空格
inputText = inputText.replace(//g, '( ');
inputText = inputText.replace(//g, ' )');

// 分段处理,以换行符分割文本
let paragraphs = inputText.split('\n\n');
Expand Down Expand Up @@ -51,8 +67,14 @@ <h2>Markdown Link Extractor with WeChat Link Exclusion</h2>
return processedText;
});

// 将处理后的段落重新拼接成一个字符串,并显示在输出框中
output.value = processedParagraphs.join('\n\n');
// 将处理后的段落重新拼接成一个字符串
let formattedText = processedParagraphs.join('\n\n');

// 恢复代码块
formattedText = formattedText.replace(/\0/g, () => codeBlocks.shift());

// 显示在输出框中
output.value = formattedText;
}
</script>

Expand Down

0 comments on commit 5527bcd

Please sign in to comment.