3 CodeMirror
.xmlHints
= [];
5 CodeMirror
.xmlHint = function(cm
) {
7 var cursor
= cm
.getCursor();
11 var text
= cm
.getRange(CodeMirror
.Pos(0, 0), cursor
);
14 for(var i
= text
.length
- 1; i
>= 0; i
--) {
15 if(text
[i
] == ' ' || text
[i
] == '<') {
20 typed
= text
[i
] + typed
;
24 text
= text
.slice(0, text
.length
- typed
.length
);
26 var path
= getActiveElement(text
) + simbol
;
27 var hints
= CodeMirror
.xmlHints
[path
];
29 if(typeof hints
=== 'undefined')
32 hints
= hints
.slice(0);
33 for (var i
= hints
.length
- 1; i
>= 0; i
--) {
34 if(hints
[i
].indexOf(typed
) != 0)
41 from: CodeMirror
.Pos(cursor
.line
, cursor
.ch
- typed
.length
),
47 var getActiveElement = function(text
) {
51 if(text
.length
>= 0) {
53 var regex
= new RegExp('<([^!?][^\\s/>]*)[\\s\\S]*?>', 'g');
57 while ((match
= regex
.exec(text
)) != null) {
60 selfclose
: (match
[0].slice(match
[0].length
- 2) === '/>')
64 for (var i
= matches
.length
- 1, skip
= 0; i
>= 0; i
--) {
66 var item
= matches
[i
];
68 if (item
.tag
[0] == '/')
72 else if (item
.selfclose
== false)
80 element
= '<' + item
.tag
+ '>' + element
;
85 element
+= getOpenTag(text
);
91 var getOpenTag = function(text
) {
93 var open
= text
.lastIndexOf('<');
94 var close
= text
.lastIndexOf('>');
98 text
= text
.slice(open
);
102 var space
= text
.indexOf(' ');
104 space
= text
.indexOf('\t');
106 space
= text
.indexOf('\n');
111 return text
.slice(0, space
);