Added syntax highlighting for XML Tools #156
| @@ -241,6 +241,7 @@ | |||||||
|  |  | ||||||
|         if (document.queryCommandSupported('insertText')) { |         if (document.queryCommandSupported('insertText')) { | ||||||
|           document.execCommand('insertText', false, text); |           document.execCommand('insertText', false, text); | ||||||
|  |            | ||||||
|         } else { |         } else { | ||||||
|           // Insert text at the current position of caret |           // Insert text at the current position of caret | ||||||
|           const range = document.getSelection().getRangeAt(0); |           const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -255,6 +256,7 @@ | |||||||
|           selection.removeAllRanges(); |           selection.removeAllRanges(); | ||||||
|           selection.addRange(range); |           selection.addRange(range); | ||||||
|         } |         } | ||||||
|  |         highlightSyntax(editorEle.id); | ||||||
|       }); |       }); | ||||||
|     </script> |     </script> | ||||||
|   </body> |   </body> | ||||||
|   | |||||||
| @@ -74,6 +74,42 @@ | |||||||
|             function init() { |             function init() { | ||||||
|                 setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here'); |                 setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here'); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             const editorEle = document.getElementById('xmlArea'); | ||||||
|  |  | ||||||
|  |             // Handle the `paste` event | ||||||
|  |             editorEle.addEventListener('paste', function (e) { | ||||||
|  |                 // Prevent the default action | ||||||
|  |                 e.preventDefault(); | ||||||
|  |  | ||||||
|  |                 // Get the copied text from the clipboard | ||||||
|  |                 const text = e.clipboardData | ||||||
|  |                     ? (e.originalEvent || e).clipboardData.getData('text/plain') | ||||||
|  |                     : // For IE | ||||||
|  |                     window.clipboardData | ||||||
|  |                         ? window.clipboardData.getData('Text') | ||||||
|  |                         : ''; | ||||||
|  |  | ||||||
|  |                 if (document.queryCommandSupported('insertText')) { | ||||||
|  |                     document.execCommand('insertText', false, text); | ||||||
|  |                 } else { | ||||||
|  |                     // Insert text at the current position of caret | ||||||
|  |                     const range = document.getSelection().getRangeAt(0); | ||||||
|  |                     range.deleteContents(); | ||||||
|  |  | ||||||
|  |                     const textNode = document.createTextNode(text); | ||||||
|  |                     range.insertNode(textNode); | ||||||
|  |                     range.selectNodeContents(textNode); | ||||||
|  |                     range.collapse(false); | ||||||
|  |  | ||||||
|  |                     const selection = window.getSelection(); | ||||||
|  |                     selection.removeAllRanges(); | ||||||
|  |                     selection.addRange(range); | ||||||
|  |                  | ||||||
|  |                 } | ||||||
|  |                 highlightSyntax(editorEle.id); | ||||||
|  |                  | ||||||
|  |             }); | ||||||
|         </script> |         </script> | ||||||
|  |  | ||||||
|     </body> |     </body> | ||||||
|   | |||||||
| @@ -17274,7 +17274,6 @@ | |||||||
|  |  | ||||||
|             if (document.queryCommandSupported('insertText')) { |             if (document.queryCommandSupported('insertText')) { | ||||||
|                 document.execCommand('insertText', false, text); |                 document.execCommand('insertText', false, text); | ||||||
|                 highlightSyntax(editorEle.id); |  | ||||||
|             } else { |             } else { | ||||||
|                 // Insert text at the current position of caret |                 // Insert text at the current position of caret | ||||||
|                 const range = document.getSelection().getRangeAt(0); |                 const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -17288,9 +17287,8 @@ | |||||||
|                 const selection = window.getSelection(); |                 const selection = window.getSelection(); | ||||||
|                 selection.removeAllRanges(); |                 selection.removeAllRanges(); | ||||||
|                 selection.addRange(range); |                 selection.addRange(range); | ||||||
|  |  | ||||||
|              |  | ||||||
|             } |             } | ||||||
|  |             highlightSyntax(editorEle.id); | ||||||
|              |              | ||||||
|         }); |         }); | ||||||
|      |      | ||||||
|   | |||||||
| @@ -129,7 +129,6 @@ | |||||||
|  |  | ||||||
|             if (document.queryCommandSupported('insertText')) { |             if (document.queryCommandSupported('insertText')) { | ||||||
|                 document.execCommand('insertText', false, text); |                 document.execCommand('insertText', false, text); | ||||||
|                 highlightSyntax(editorEle.id); |  | ||||||
|             } else { |             } else { | ||||||
|                 // Insert text at the current position of caret |                 // Insert text at the current position of caret | ||||||
|                 const range = document.getSelection().getRangeAt(0); |                 const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -144,8 +143,8 @@ | |||||||
|                 selection.removeAllRanges(); |                 selection.removeAllRanges(); | ||||||
|                 selection.addRange(range); |                 selection.addRange(range); | ||||||
|  |  | ||||||
|              |  | ||||||
|             } |             } | ||||||
|  |             highlightSyntax(editorEle.id); | ||||||
|              |              | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -166,7 +165,7 @@ | |||||||
|  |  | ||||||
|             if (document.queryCommandSupported('insertText')) { |             if (document.queryCommandSupported('insertText')) { | ||||||
|                 document.execCommand('insertText', false, text); |                 document.execCommand('insertText', false, text); | ||||||
|                 highlightSyntax(transformEle.id); |                  | ||||||
|             } else { |             } else { | ||||||
|                 // Insert text at the current position of caret |                 // Insert text at the current position of caret | ||||||
|                 const range = document.getSelection().getRangeAt(0); |                 const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -180,9 +179,8 @@ | |||||||
|                 const selection = window.getSelection(); |                 const selection = window.getSelection(); | ||||||
|                 selection.removeAllRanges(); |                 selection.removeAllRanges(); | ||||||
|                 selection.addRange(range); |                 selection.addRange(range); | ||||||
|  |  | ||||||
|              |  | ||||||
|             } |             } | ||||||
|  |             highlightSyntax(transformEle.id); | ||||||
|              |              | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1243,7 +1243,6 @@ | |||||||
|  |  | ||||||
|             if (document.queryCommandSupported('insertText')) { |             if (document.queryCommandSupported('insertText')) { | ||||||
|                 document.execCommand('insertText', false, text); |                 document.execCommand('insertText', false, text); | ||||||
|                 highlightSyntax(editorEle.id); |  | ||||||
|             } else { |             } else { | ||||||
|                 // Insert text at the current position of caret |                 // Insert text at the current position of caret | ||||||
|                 const range = document.getSelection().getRangeAt(0); |                 const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -1257,10 +1256,8 @@ | |||||||
|                 const selection = window.getSelection(); |                 const selection = window.getSelection(); | ||||||
|                 selection.removeAllRanges(); |                 selection.removeAllRanges(); | ||||||
|                 selection.addRange(range); |                 selection.addRange(range); | ||||||
|  |  | ||||||
|              |  | ||||||
|             } |             } | ||||||
|              |             highlightSyntax(editorEle.id); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         const transformEle = document.getElementById('transformArea'); |         const transformEle = document.getElementById('transformArea'); | ||||||
| @@ -1280,7 +1277,6 @@ | |||||||
|  |  | ||||||
|             if (document.queryCommandSupported('insertText')) { |             if (document.queryCommandSupported('insertText')) { | ||||||
|                 document.execCommand('insertText', false, text); |                 document.execCommand('insertText', false, text); | ||||||
|                 highlightSyntax(transformEle.id); |  | ||||||
|             } else { |             } else { | ||||||
|                 // Insert text at the current position of caret |                 // Insert text at the current position of caret | ||||||
|                 const range = document.getSelection().getRangeAt(0); |                 const range = document.getSelection().getRangeAt(0); | ||||||
| @@ -1294,10 +1290,8 @@ | |||||||
|                 const selection = window.getSelection(); |                 const selection = window.getSelection(); | ||||||
|                 selection.removeAllRanges(); |                 selection.removeAllRanges(); | ||||||
|                 selection.addRange(range); |                 selection.addRange(range); | ||||||
|  |  | ||||||
|              |  | ||||||
|             } |             } | ||||||
|              |             highlightSyntax(transformEle.id); | ||||||
|         }); |         }); | ||||||
|     </script> |     </script> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user