-
-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathmarkdown.html
More file actions
216 lines (200 loc) · 7.68 KB
/
Copy pathmarkdown.html
File metadata and controls
216 lines (200 loc) · 7.68 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Markdown- Phoenix</title>
<style>
{{{BOOTSTRAP_LIB_CSS}}}
</style>
<style>
{{{HIGHLIGHT_JS_CSS}}}
</style>
<script>
{{{HIGHLIGHT_JS}}}
</script>
<style>
{{{GFM_CSS}}}
</style>
<script>
{{{TRUSTED_ORIGINS_EMBED}}}
// this is for managing who am i context in iframes embedded in phoenix to have special handling.
window.addEventListener('message', function(event) {
if (!TRUSTED_ORIGINS_EMBED[event.origin]) {
return; // Ignore messages from unexpected origins
}
if(event.data.type === "WHO_AM_I_RESPONSE") {
window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri,
platform: event.data.platform,
isPhoenixEmbeddedIframe: event.data.isPhoenixEmbeddedIframe
};
} else if(event.data.type === "_TEST_FOCUS_CLICK") { // for integ tests
document.body.click();
} else if(event.data.type === "_TEST_SELECT_TEXT_AND_CLICK") { // for integ tests
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(document.body);
selection.removeAllRanges(); // Clear any existing selections
selection.addRange(range);
document.body.click();
} else if(event.data.type === "_TEST_UNSELECT_TEXT_AND_CLICK") { // for integ tests
window.getSelection().removeAllRanges();
document.body.click();
}
});
if(window.self !== window.parent){
// in an iframe
window.parent.postMessage({
handlerName: "ph-liveServer",
eventName: 'whoAmIframePhoenix',
href: location.href
}, "{{{PARENT_ORIGIN}}}");
}
</script>
<script type="text/javascript">
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if(inIframe()) {
// inside iframes, we disable ctrl-s browser save page workflow as it may be inside the phoenix window
// It will confuse the use seeing the browser save dialog inside phoenix.
document.savePageCtrlSDisabledByPhoenix = true;
document.addEventListener("keydown", function(e) {
if (window.__PHOENIX_EMBED_INFO &&
e.key === 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
// we only do this in iframes embedded directly inside phoenix, in popped out iframes
// we don't need to capture anything.
e.preventDefault();
}
}, false);
function getAbsoluteUrl(url) {
// Check if the URL is already absolute
if (new RegExp("^(?:[a-z]+:)?\\/\\/", "i").test(url)) {
return url; // The URL is already absolute
}
// If not, create an absolute URL using the current page's location as the base
const absoluteUrl = new URL(url, window.location.href);
return absoluteUrl.href;
}
document.addEventListener('click', function(event) {
// Get the user's current selection
const selection = window.getSelection();
// Check if there is a selection
if (selection.toString().length === 0) {
// there may be selection like text or others Eg: user may select some text
// in live preview to copy, in which case we should not treat it as a live select.
// if there is no selection, then we have set the focus to the editor
window.parent.postMessage({
handlerName: "ph-liveServer",
eventName: 'embeddedIframeFocusEditor',
href: location.href
}, "{{{PARENT_ORIGIN}}}");
}
let target = event.target;
// Traverse up the DOM tree to find if the target is within an <a> tag
while (target && target.tagName !== 'A') {
target = target.parentNode;
}
// in desktop phoenix builds, tauri will not open anchor tags in browser if it is in
// an iframe(except for the intel mac bug)
// in normal browsers, we dont need to do this.
if (window.__PHOENIX_EMBED_INFO && window.__PHOENIX_EMBED_INFO.isTauri &&
target.tagName === 'A' && (target.target === '_blank')) {
const href = getAbsoluteUrl(target.getAttribute('href'));
window.parent.postMessage({
handlerName: "ph-liveServer",
eventName: 'embeddedIframeHrefClick',
href: href
}, "{{{PARENT_ORIGIN}}}");
// in intel mac desktop, tauri seems to open in browser
// causing 2 tabs to open. in m1 macs its not there. so we prevent default behavior.
event.stopImmediatePropagation();
event.preventDefault();
}
}, true);
}
window.addEventListener('scroll', function () {
// save scroll position
sessionStorage.setItem("saved-scroll-" + location.href, JSON.stringify({
scrollX: window.scrollX,
scrollY: window.scrollY
}));
});
function scrollToLastPosition() {
let saved = JSON.parse(sessionStorage.getItem("saved-scroll-" + location.href));
if(saved){
window.scrollTo({
left: saved.scrollX,
top: saved.scrollY,
behavior: "instant"
});
}
}
</script>
<style>
*{
margin:0;
padding: 0;
}
html{height:100%;}
body{
height:100%;
}
.header{
height:6%;
width:100%;
background-color:#444444;
}
.contain{
width:100%;
height:99%;
}
.input{
width:50%;
height:93%;
float:left;
background-color: #F9F9F5;
}
#text-input{
height:100%;
width:90%;
border:0px;
font-size:15px;
background-color: #F9F9F5;
resize:none;
outline:none;
}
#preview{
width:50%;
height: 93%;
float: right;
font-size:16px;
background-color: #F9F9F5;
overflow:scroll;
overflow-x: hidden;
}
table { border-collapse: collapse; }
tr { border-bottom: solid 1px black; }
tr:nth-child(even) {background-color: #f2f2f2;}
/* srcollbar */
::-webkit-scrollbar{
width:12px;
}
::-webkit-scrollbar-thumb{
/* border-radius:10px; */
background-color:#DEE4E4;
}
::-webkit-scrollbar-track{
/* border-radius:10px; */
background-color:#EBEEEC;
}
</style>
</head>
<body onload="scrollToLastPosition();hljs.highlightAll();">
{{{markdownContent}}}
</body>
</html>