-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
313 lines (292 loc) · 10.1 KB
/
Copy pathindex.html
File metadata and controls
313 lines (292 loc) · 10.1 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link href="images/favicon.ico" rel="shortcut icon"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Wikifier RT - Convert Confluence rich text editor HTML to wiki markup</title>
<style type="text/css">
/* <![CDATA[ */
*
{
box-sizing: border-box;
-moz-box-sizing: border-box;
}
html, body
{
height: 100%;
width: 100%;
font-family: sans-serif;
margin: 0;
padding: 0;
position: relative;
font-size: 1em;
line-height: 1em;
}
form,
form > fieldset,
form > fieldset > textarea
{
position: relative;
display: block;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
border: none;
}
form > fieldset > textarea
{
white-space: pre-wrap;
}
textarea.error
{
background-color: #FFC0C0;
}
textarea
{
overflow: auto;
resize: none;
}
button
{
margin-top: -0.3em; /* Kludge to vertically center button */
margin-left: 0.5em;
}
a, a:hover, a:active, a:focus
{
outline: 0;
text-decoration: none;
}
a:hover, a:focus
{
color: #000000;
}
a
{
float: right;
color: #606060;
font-weight: normal;
font-size: 0.8em;
display: block-inline;
margin-left: 2em;
}
iframe
{
border: none;
}
/* ]]> */
</style>
<script type="text/javascript">
// <![CDATA[
var xsl;
function initialize()
{
// Select default rich text
selectIframeContents(document.getElementById("richtext"));
// Set focus to the rich text
// (so that Paste replaces the default rich text)
document.getElementById("richtext").contentDocument.body.focus();
// Get XSLT stylesheet
if (window.ActiveXObject)
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.6.0");
else
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "rte-xhtml2wiki.xsl", false);
if (window.ActiveXObject)
{
xmlhttp.responseXML.async = false;
xmlhttp.responseXML.resolveExternals = true;
xmlhttp.responseXML.validateOnParse = false;
xmlhttp.responseXML.preserveWhiteSpace = true;
}
xmlhttp.send();
xsl = xmlhttp.responseXML;
if (window.ActiveXObject)
xsl.setProperty("AllowDocumentFunction", true);
wikify();
}
function selectIframeContents(ifm)
{
var range = ifm.contentDocument.createRange();
range.selectNodeContents(ifm.contentDocument.body);
var sel = ifm.contentWindow.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
function selectElementContents(el)
{
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
function keyup(e)
{
var keyPressed;
var KEY_CODE_PASTE = 86;
var KEY_CODE_ENTER = 13;
if (window.event)
keyPressed = window.event.keyCode; // IE
else
keyPressed = e.which; // Others
if (keyPressed==KEY_CODE_ENTER || keyPressed==KEY_CODE_PASTE)
{
wikify();
// Select wiki markup, ready for copying to the clipboard
document.getElementById("wikimarkup").focus();
}
}
// Updates the HTML source view from the rich text view
function richTextToHTML()
{
var source = document.getElementById("richtext").contentDocument.body.innerHTML;
// If innerHTML begins with a newline, strip it
if (source.substring(0, 1) == "\n")
source = source.substring(1);
document.getElementById("htmlsource").value = source;
}
// Updates the rich text view from the HTML source view
function HTMLToRichText()
{
var source = document.getElementById("htmlsource").value;
document.getElementById("richtext").contentDocument.body.innerHTML = source;
}
function wikify()
{
var strWrapperTop = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<body xmlns=\"http://www.w3.org/1999/xhtml\">";
var strWrapperBottom = "</body>";
// Copy the contents of the rich text view to the HTML (source) view
richTextToHTML();
// Wrap HTML snippet in a root element
var strRTEXHTMLDoc = strWrapperTop + document.getElementById("htmlsource").value + strWrapperBottom;
// Close <br>, <hr>, and <img> elements
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/<(br[^>]*)>/g, "<$1/>");
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/<(hr[^>]*)>/g, "<$1/>");
// More complex regular expression to allow for > in img attribute values
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/<(img(?:\s+\S+\s*=\s*"[^"]+")+)>/g, "<$1/>");
// Also <col> elements (these do not exist in RTE HTML this is just in case someone pastes in content from, say, Excel)
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/<(col\s+[^>]*)>/g, "<$1/>");
// Remove MSOffice-specific o: namespace prefix
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/<(\/?)o:([^>]*)>/g, "<$1$2>");
// Replace entity references (needs work!)
strRTEXHTMLDoc = strRTEXHTMLDoc.replace(/\ /g, " ");
// IE
if (window.ActiveXObject)
{
// Creating the new empty DOM tree:
var xml = new ActiveXObject("MSXML2.DOMDocument.6.0");
// No asynchronous load:
xml.async = false;
xml.preserveWhiteSpace = true;
xml.resolveExternals = true;
xml.setProperty("ProhibitDTD", false);
xml.loadXML(strRTEXHTMLDoc);
if (xml.parseError.errorCode == 0)
{
with (document.getElementById("wikimarkup"))
{
className = "";
}
} else
{
var errorPossibleFix = "";
if (xml.parseError.errorCode == -1072896763)
{
errorPossibleFix = "Check that your HTML source (except for elements such as <br>, which are expected to be specified just like that, with no end tag) is well-formed (no missing end tags).\n"
}
with (document.getElementById("wikimarkup"))
{
className = "error";
value = xml.parseError.reason + errorPossibleFix + "\nError code: " + xml.parseError.errorCode;
}
return;
}
var strWikiMarkup = xml.transformNode(xsl.documentElement);
}
// Other browers
else if (document.implementation && document.implementation.createDocument)
{
var strError = "";
var parser = new DOMParser();
var xml = parser.parseFromString(strRTEXHTMLDoc, "application/xml");
if (xml.documentElement.nodeName=="parsererror")
{
var strError=xml.documentElement.childNodes[0].nodeValue;
with (document.getElementById("wikimarkup"))
{
className = "error";
value = strError;
}
return;
} else {
var errors = xml.getElementsByTagName("parsererror");
if (errors.length > 0)
{
with (document.getElementById("wikimarkup"))
{
className = "error";
value = errors[0].textContent + "\n(No there isn't. Fix the error!)"
}
return;
}
}
with (document.getElementById("wikimarkup"))
{
className = "";
}
xsltProcessor= new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
strWikiMarkup = xsltProcessor.transformToFragment(xml,document).textContent;
}
document.getElementById("wikimarkup").value = strWikiMarkup;
}
// Clear content from all views
function clearContent()
{
document.getElementById("richtext").contentDocument.body.innerHTML = "";
document.getElementById("htmlsource").value = "";
document.getElementById("wikimarkup").value = "";
}
// Toggles the visibility of the HTML source view
function toggleHTML()
{
if (document.getElementById("htmlsource-container").style["visibility"] == "hidden")
{
richTextToHTML();
document.getElementById("richtext").style["height"] = "50%";
document.getElementById("htmlsource-container").style["visibility"] = "visible";
document.getElementById("htmlsource-banner").style["visibility"] = "visible";
document.getElementById("toggle-html").innerHTML = "Hide HTML";
document.getElementById("toggle-html").title = "Hide the HTML source of this rich text";
}
else
{
document.getElementById("htmlsource-container").style["visibility"] = "hidden";
document.getElementById("htmlsource-banner").style["visibility"] = "hidden";
document.getElementById("richtext").style["height"] = "100%";
document.getElementById("toggle-html").innerHTML = "Show HTML";
document.getElementById("toggle-html").title = "Show the HTML source of this rich text";
}
}
// ]]>
</script>
</head>
<body>
<!-- Rich text -->
<iframe src="sample-rt.html" style="position: absolute; width: 50%; height: 100%; overflow-y: auto; padding: 2em 0 0 0; margin: 0;" id="richtext"></iframe>
<div style="position: absolute; width: 50%; height: 2em; top: 0; left: 0; padding: 0.5em; background-color: #D0D0D0; font-weight: bold;"><a href="#" title="Convert to wiki markup" onclick="wikify(); return false;" accesskey="w">Wikify</a><a href="#" title="Clear content" onclick="clearContent(); return false;" accesskey="c">Clear</a><a href="#" id="toggle-html" title="Show the HTML source of this rich text" onclick="toggleHTML(); return false;" accesskey="h">Show HTML</a>Rich text</div>
<!-- HTML source -->
<form id="htmlsource-container" style="visibility: hidden; position: absolute; top: 50%; left: 0; height: 50%; width: 50%; padding-top: 2em;" action=""><fieldset><textarea style="padding-left: 0.5em;" id="htmlsource" rows="1" cols="1"><h1>Wikifier</h1>
<p>Or enter HTML source code here.</p>
</textarea>
</fieldset>
</form>
<div id="htmlsource-banner" style="visibility: hidden; position: absolute; top: 50%; left: 0; width: 50%; height: 2em; padding: 0.5em; background-color: #E0E0E0; font-weight: bold;"><a href="#" title="Update the rich text using this HTML (useful if you've edited the HTML, and want to paste it back into the Confluence editor)" onclick="HTMLToRichText(); return false;" accesskey="u">Update rich text</a>HTML</div>
<!-- Wiki markup -->
<form style="position: absolute; padding-top: 2em; top: 0; left: 50%; height: 100%; width: 50%;" action=""><fieldset><textarea style="padding-left: 0.5em; border-left: 1px solid #E0E0E0;" id="wikimarkup" rows="1" cols="1"></textarea></fieldset></form>
<div style="position: absolute; top: 0; left: 50%; width: 50%; height: 2em; padding: 0.5em; background-color: #E0E0E0; font-weight: bold;"><a href="help.html" title="Documentation and support details">Help</a>Wiki markup</div>
</body>
</html>