Skip to content

Commit f394554

Browse files
committed
encode with json, remove debugs
1 parent d6fd3f6 commit f394554

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

templates/devtest/gitea-ui.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{template "base/head" .}}
22
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/devtest.css?v={{AssetVersion}}">
3-
<div class="page-content devtest ui container" data-foo="{{print "a\r\nb"}}">
4-
<script>console.log(JSON.stringify(document.querySelector('.page-content').getAttribute('data-foo')))</script>
3+
<div class="page-content devtest ui container">
54
<div>
65
<h1>Button</h1>
76
<div>

templates/repo/editor/edit.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
data-url="{{.Repository.Link}}/markup"
3939
data-context="{{.RepoLink}}"
4040
data-previewable-extensions="{{.PreviewableExtensions}}"
41-
data-value="{{.FileContent}}"
42-
data="{{.FileContent}}"
43-
data-foo="{{.FileContent}}"
44-
data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}</textarea>
41+
data-initial-value="{{JsonUtils.EncodeToString .FileContent}}"
42+
data-line-wrap-extensions="{{.LineWrapExtensions}}"></textarea>
4543
<div class="editor-loading is-loading"></div>
4644
</div>
4745
<div class="ui bottom attached tab segment markup" data-tab="preview">

web_src/js/features/codeeditor.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,19 @@ export async function createMonaco(textarea, filename, editorOpts) {
105105
monaco.languages.register({id: 'vs.editor.nullLanguage'});
106106
monaco.languages.setLanguageConfiguration('vs.editor.nullLanguage', {});
107107

108+
// The initial is encoded in JSON by the backend to prevent browsers from
109+
// discarding \r during HTML parsing.
110+
const value = JSON.parse(textarea.getAttribute('data-initial-value') || '""');
111+
textarea.value = value;
112+
textarea.removeAttribute('data-initial-value');
113+
108114
const editor = monaco.editor.create(container, {
109-
value: textarea.value,
115+
value,
110116
theme: 'gitea',
111117
language,
112118
...other,
113119
});
114120

115-
console.log(JSON.stringify(textarea.value));
116-
console.log(JSON.stringify(textarea.getAttribute('data')));
117-
console.log(JSON.stringify(textarea.getAttribute('data-foo')));
118-
119121
const model = editor.getModel();
120122

121123
// Monaco performs auto-detection of dominant EOL in the file, biased towards LF for

0 commit comments

Comments
 (0)