-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (69 loc) · 3.95 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MarkdownをSSMLに変換</title>
<link rel="icon" href="favicon.png" type="image/png">
<script src="https://cdn.tailwindcss.com"></script>
<script type="module">
import { remark } from 'https://esm.sh/remark@14'
import strip from 'https://esm.sh/strip-markdown@5'
window.remarkStrip = async (markdown) => {
console.log( markdown );
const file = await remark().use(strip).process(markdown)
return String(file)
}
</script>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="container mx-auto p-6 bg-white rounded-lg shadow-lg">
<h1 class="text-3xl font-bold mb-1 text-center text-gray-800">MarkdownをSSMLに変換</h1>
<p class="text-1xl font-bold mb-6 text-center text-gray-400">見出しの前で一呼吸入れます</p>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="input" class="block text-sm font-medium text-gray-700 mb-2">Markdownを記入</label>
<textarea id="input" class="w-full h-64 p-2 border border-gray-300 rounded-md resize-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Enter your Markdown text here..."></textarea>
<p class="text-center"><button id="convert" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">変換</button></p>
</div>
<div>
<label for="output" class="block text-sm font-medium text-gray-700 mb-2">これを貼り付けてください</label>
<textarea id="output" class="w-full h-64 p-2 border border-gray-300 rounded-md resize-none bg-gray-50"></textarea>
<p class="text-center"><button id="copy" class="ml-4 px-4 py-2 bg-green-500 text-white rounded-md hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2" disabled>クリップボードにコピー</button></p>
</div>
</div>
</div>
<script>
const copyButton = document.getElementById('copy');
const outputTextarea = document.getElementById('output');
document.getElementById('convert').addEventListener('click', async function() {
const input = document.getElementById('input').value;
// SSMLでエラーを引き起こす可能性のある文字をエスケープ
let ssml = input.replace(/&/g, '').replace(/</g, '').replace(/>/g, '').replace(/"/g, '').replace(/'/g, '');
// 見出しの前に空白を挿入するためのマークを入れる
ssml = ssml.replace(/^(#{1,6} )(.*)/gm, 'HHHHHHH'+"\n"+'$2');
// Markdownを平文に変換
ssml = await window.remarkStrip(ssml);
// 見出しの前に空白を挿入
ssml = ssml.replace(/^(HHHHHHH)/gm, '<break time="300ms"/>'+"\n");
// 最終的なSSMLを生成
document.getElementById('output').value = '<speak><prosody rate="120%">' + "\n" + ssml + "\n" + '</prosody></speak>';
// ボタンを有効化
copyButton.disabled = false;
});
copyButton.addEventListener('click', function() {
outputTextarea.select();
document.execCommand('copy');
const originalText = copyButton.textContent;
copyButton.textContent = 'Copied!';
copyButton.classList.remove('bg-green-500', 'hover:bg-green-600');
copyButton.classList.add('bg-gray-500', 'hover:bg-gray-600');
setTimeout(() => {
copyButton.textContent = originalText;
copyButton.classList.remove('bg-gray-500', 'hover:bg-gray-600');
copyButton.classList.add('bg-green-500', 'hover:bg-green-600');
}, 2000);
});
</script>
</body>
</html>