-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (79 loc) · 2.66 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
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PartyRock Mindmap</title>
<style>
svg.markmap {
width: 100%;
height: 100vh;
}
</style>
<style>
svg.markmap {
width: 100%;
height: 100vh;
}
#inputForm {
position: absolute;
top: 0;
left: 0;
right: 0;
background-color: white;
z-index: 1000;
padding: 20px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<div class="markmap">
</div>
<div id="inputForm" style="display:none;">
<h2>Create Your Mindmap</h2>
<p>Enter your markdown content from <b>PartyRock</b> below:</p>
<form id="markdownForm">
<textarea id="markdownText" style="width:100%; height:580px; overflow:auto;"></textarea>
<br>
<input type="submit" value="Generate Mindmap">
</form>
</div>
</body>
<script>
document.getElementById('markdownForm').onsubmit = function(event) {
event.preventDefault();
const text = document.getElementById('markdownText').value;
const base64Encoded = btoa(text);
window.location.search = '?base64=' + base64Encoded;
};
function getBase64Param() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('base64');
}
const base64String = getBase64Param();
if (base64String) {
let markdownContent = atob(base64String).replace(/[\s\S]*?(# [a-zA-Z0-9 ]+)/, '$1');
// Remove leading spaces from the first line
markdownContent = markdownContent.replace(/^\s+/, '');
let lines = markdownContent.split('\n');
markdownContent = lines.map((line, index) => {
if (index === 0) {
return line.startsWith('# ') ? line : `# ${line}`;
}
return /^[A-Za-z]/.test(line) ? '## ' + line : line;
}).join('\n');
const markmapFrontmatter = "---\nmarkmap:\n maxWidth: 380\n colorFreezeLevel: 2\n---\n";
markdownContent = markmapFrontmatter + markdownContent;
const scriptElement = document.createElement('script');
scriptElement.type = 'text/template';
scriptElement.textContent = markdownContent;
const markmap_div = document.getElementsByClassName("markmap");
markmap_div[0].appendChild(scriptElement);
} else {
document.getElementById('inputForm').style.display = 'block';
}
</script>
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@0.16"></script>
</html>