monaco html hinting

This commit is contained in:
Kyle Drake 2024-10-01 13:36:02 -05:00
parent a40defb927
commit 0daaf69e25
2 changed files with 32 additions and 1 deletions

1
public/js/htmlhint.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -80,6 +80,10 @@
<script src="/js/chat.js"></script> <script src="/js/chat.js"></script>
<% end %> <% end %>
--> -->
<script src="/js/htmlhint.min.js"></script>
<div class="row editor"> <div class="row editor">
<div class="col left-col" style="display: <% current_site.supporter? ? 'none' : 'block' %>; margin-left: 20px;"> <div class="col left-col" style="display: <% current_site.supporter? ? 'none' : 'block' %>; margin-left: 20px;">
<div id="editor"><h3>Loading...</h3></div> <div id="editor"><h3>Loading...</h3></div>
@ -164,7 +168,6 @@
$('#editorUpdates').removeClass('hidden') $('#editorUpdates').removeClass('hidden')
}, },
success: function(response, textStatus, xhr){ success: function(response, textStatus, xhr){
console.log(xhr.status)
if(xhr.status == 200) { if(xhr.status == 200) {
unsavedChanges = false unsavedChanges = false
if(quit === true) { if(quit === true) {
@ -221,6 +224,33 @@
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function() { editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function() {
saveTextFile(false); saveTextFile(false);
}); });
// Function to set markers based on HTMLHint validation
function setHTMLMarkers() {
const code = editor.getValue();
const results = HTMLHint.HTMLHint.verify(code);
const markers = results.map((error) => {
return {
startLineNumber: error.line,
startColumn: error.col,
endLineNumber: error.line,
endColumn: error.col + 1,
message: error.message,
severity: monaco.MarkerSeverity.Error,
};
});
monaco.editor.setModelMarkers(editor.getModel(), 'htmlhint', markers);
}
// Register event listener to validate and set markers on content change
editor.onDidChangeModelContent(() => {
setHTMLMarkers();
});
// Initial validation
setHTMLMarkers();
} }
}); });
}); });