mirror of
https://github.com/zadam/trilium.git
synced 2025-01-18 04:59:56 +08:00
indent JSON when saving
This commit is contained in:
parent
3f1e73d06b
commit
7ca0445bae
1 changed files with 6 additions and 2 deletions
|
@ -16,6 +16,10 @@ function ScriptContext(noteId, dataKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serializePayload(payload) {
|
||||||
|
return JSON.stringify(payload, null, '\t');
|
||||||
|
}
|
||||||
|
|
||||||
this.getNoteById = async function(noteId) {
|
this.getNoteById = async function(noteId) {
|
||||||
const note = await notes.getNoteById(noteId, this.dataKey);
|
const note = await notes.getNoteById(noteId, this.dataKey);
|
||||||
|
|
||||||
|
@ -35,7 +39,7 @@ function ScriptContext(noteId, dataKey) {
|
||||||
this.createNote = async function (parentNoteId, name, payload, extraOptions = {}) {
|
this.createNote = async function (parentNoteId, name, payload, extraOptions = {}) {
|
||||||
const note = {
|
const note = {
|
||||||
note_title: name,
|
note_title: name,
|
||||||
note_text: extraOptions.json ? JSON.stringify(payload) : payload,
|
note_text: extraOptions.json ? serializePayload(payload) : payload,
|
||||||
target: 'into',
|
target: 'into',
|
||||||
is_protected: extraOptions.isProtected !== undefined ? extraOptions.isProtected : false,
|
is_protected: extraOptions.isProtected !== undefined ? extraOptions.isProtected : false,
|
||||||
type: extraOptions.type,
|
type: extraOptions.type,
|
||||||
|
@ -65,7 +69,7 @@ function ScriptContext(noteId, dataKey) {
|
||||||
|
|
||||||
this.updateNote = async function (note) {
|
this.updateNote = async function (note) {
|
||||||
if (note.type === 'code' && note.mime === 'application/json') {
|
if (note.type === 'code' && note.mime === 'application/json') {
|
||||||
note.note_text = JSON.stringify(note.payload);
|
note.note_text = serializePayload(note.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("new note text: ", note.note_text);
|
log.info("new note text: ", note.note_text);
|
||||||
|
|
Loading…
Reference in a new issue