CodeViewer - how to auto-format JSON code when pasting or setting content #4597
Unanswered
benryanwilliams
asked this question in
Q&A
Replies: 1 comment 1 reply
-
By using the CodeMirror in the core you should be able to auto-format html/css/js by using something like this: viewerEditor.autoFormatRange({ line:0, ch:0 }, { line: viewerEditor.lineCount() }); but for the JSON is generally enough |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If I paste code that is already formatted correctly into the
codeViewer
then it is displayed properly. However, if I paste an unformatted block of code into the codeViewer (or set the content of the codeViewer using a stringified JSON object), it just appears as one block of text:Screen.Recording.2022-09-16.at.16.42.49-1.mov
My code:
Even if I use the third parameter of JSON.stringify e.g.
codeViewer.setContent(JSON.stringify(thisData, null, '\t'))
, there is no indentation:Is there any built-in (or other) way of implementing this? I can't see much information regarding the
codeViewer
in the docs.Beta Was this translation helpful? Give feedback.
All reactions