-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml.js
92 lines (81 loc) · 2.34 KB
/
html.js
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
// modify start point & end point from Selection anchor node & focus node
// and middle section can modified by accessing range element fff
/*
//apam-check
function handleReiteration(htmlCode) {
var origin = htmlCode;
var regex = /<span class='apam-[a-z]+?'>(.+?)<\/span>/g;
htmlCode = htmlCode.replace(regex, "$1");
if (htmlCode != origin) {
console.log('Changed (nested) : ' + htmlCode);
}
origin = htmlCode;
var regex = /<span class='apam-([a-z]+?)'>(.+)/g;
htmlCode = htmlCode.replace(regex, '$2<span class="apam-$1">');
if (htmlCode != origin) {
console.log("Changed (override) : " + htmlCode);
}
origin = htmlCode;
var regex = /(.*?)<\/span>(.*?)/g;
htmlCode = htmlCode.replace(regex, '$2<span class="apam-$1">');
if (htmlCode != origin) {
console.log('Changed (override) : ' + htmlCode);
}
return htmlCode;
}
function injectSpanTag(htmlCode, tagClass) {
//injection span
var result;
var regex = /<\/p>/gi;
result = htmlCode.replace(regex, '</span></p>');
return result;
}
function removeBothEnd(htmlCode) {
var startIndex = 0;
var endIndex = htmlCode.length;
if(htmlCode[0] == '<')
{
for(startIndex; startIndex < htmlCode.length; startIndex++)
{
if(htmlCode[startIndex] == '>')
{
startIndex++;
break;
}
}
}
if(htmlCode[htmlCode.length - 1] == '>')
{
for(endIndex; endIndex > startIndex; endIndex--)
{
if(htmlCode[endIndex] == '<')
{
break;
}
}
}
return htmlCode.substring(startIndex, endIndex);
}
function getSelectedHtml() {
var userSelection;
userSelection = window.getSelection();
var range = userSelection.getRangeAt(0);
var clone = range.cloneContents();
var span = document.createElement('span');
console.log(clone);
span.appendChild(clone);
//range.surroundContents(span);
}
function getSelectedHtml_backup() {
var userSelection;
userSelection = window.getSelection ();
var range = document.createRange ();
range.setStart (userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd (userSelection.focusNode, userSelection.focusOffset);
console.log(range);
var clonedSelection = range.cloneContents ();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
return div.innerHTML;
}
*/