-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements code mirror which creates a code editor that allows proper inputting of metadata in json tree format Signed-off-by: ianmuchyri <[email protected]>
- Loading branch information
1 parent
071500b
commit c6e0269
Showing
15 changed files
with
426 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ var ( | |
"tablefooter", | ||
"error", | ||
"breadcrumb", | ||
"metadatamodal", | ||
|
||
"bootstrap", | ||
"bootstraps", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
function syntaxHighlight(json) { | ||
json = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); | ||
return json.replace( | ||
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, | ||
function (match) { | ||
var cls = "number"; | ||
if (/^"/.test(match)) { | ||
if (/:$/.test(match)) { | ||
cls = "key"; | ||
} else { | ||
cls = "string"; | ||
} | ||
} else if (/true|false/.test(match)) { | ||
cls = "boolean"; | ||
} else if (/null/.test(match)) { | ||
cls = "null"; | ||
} | ||
return '<span class="' + cls + '">' + match + "</span>"; | ||
}, | ||
); | ||
} | ||
|
||
function attachFormatJsonWithPrettifyListener(config) { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
var meta = JSON.parse(config.metadata); | ||
document.getElementById(config.id).innerHTML = syntaxHighlight(JSON.stringify(meta, null, 2)); | ||
}); | ||
} | ||
|
||
function codeMirrorEditor(config) { | ||
var editor = CodeMirror.fromTextArea(document.getElementById(config.textArea), { | ||
mode: "application/json", | ||
matchBrackets: true, | ||
autoCloseBrackets: true, | ||
lineWrapping: true, | ||
lineNumbers: true, | ||
lint: true, | ||
gutters: ["CodeMirror-lint-markers"], | ||
autoRefresh: true, | ||
}); | ||
editor.setValue(JSON.stringify(config.value, null, 2)); | ||
editor.setSize("100%", 200); | ||
document.getElementById(config.button).addEventListener("click", function () { | ||
document.getElementById(config.textArea).value = editor.getValue(); | ||
console.log(document.getElementById(config.textArea)); | ||
console.log(document.getElementById(config.textArea).value); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.