用一次提交写完一张卡
const r = await mn.api('/notes/' + noteid + '/edits', {
method: 'POST',
body: {
ops: [
// 删批注必须排在摘标签之前,否则 422 INVALID_ORDER
{ op: 'deleteComment', index: 2, expectedPrefix: '旧释义' },
{ op: 'setTitle', text: 'photosynthesis', expectedPrefix: 'photo' },
{ op: 'appendComment', text: '光合作用:植物把光能转成化学能的过程。' },
{ op: 'removeHashtags', hashtags: ['#VocabPending'] },
// addon 由 MarginNote 设为本面板的 owner
{ op: 'setAddonValues', values: { status: 'done' } }
],
confirm: true,
syncReview: false
}
});
if (r.error) mn.log(r.error.code);
// 探测 MarginNote 是否注册了该接口
if (r.error && r.error.code === 'NOT_FOUND') {
// 旧版 MarginNote 上改用逐条写入的接口
}{
"noteid": "5880F73A-3A6D-4464-9D6F-88F60285401E",
"applied": 2,
"title": "photosynthesis"
}卡片与摘录
一次提交多步卡片改动
一个动作要改动多项时使用该接口:改标题、加批注、删批注、摘标签、记插件字段,写在一次提交里 提交,在撤销栈上只占一步。
MarginNote 先按顺序模拟整批操作,任何一步不通过,整批操作都不写入。一批最多 32 步。删批注必须排在
摘标签之前,否则返回 422 INVALID_ORDER。写入之后 MarginNote 重新读取核对,不一致就把改动过的卡
整体恢复并返回 500。
syncReview 打开时,写完照摘录那一刻的自动入组规则把该卡补进复习卡组,与本次写入同一步撤销。
这是插件唯一的原子多步写入口。旧版 MarginNote 没有注册该接口时返回 404,可以用作能力探测。
POST
/
notes
/
{noteid}
/
edits
用一次提交写完一张卡
const r = await mn.api('/notes/' + noteid + '/edits', {
method: 'POST',
body: {
ops: [
// 删批注必须排在摘标签之前,否则 422 INVALID_ORDER
{ op: 'deleteComment', index: 2, expectedPrefix: '旧释义' },
{ op: 'setTitle', text: 'photosynthesis', expectedPrefix: 'photo' },
{ op: 'appendComment', text: '光合作用:植物把光能转成化学能的过程。' },
{ op: 'removeHashtags', hashtags: ['#VocabPending'] },
// addon 由 MarginNote 设为本面板的 owner
{ op: 'setAddonValues', values: { status: 'done' } }
],
confirm: true,
syncReview: false
}
});
if (r.error) mn.log(r.error.code);
// 探测 MarginNote 是否注册了该接口
if (r.error && r.error.code === 'NOT_FOUND') {
// 旧版 MarginNote 上改用逐条写入的接口
}{
"noteid": "5880F73A-3A6D-4464-9D6F-88F60285401E",
"applied": 2,
"title": "photosynthesis"
}路径参数
卡片的 noteid。取自卡片命令响应的 noteid、POST /notes/batch-get 响应里 items[].noteid,或 GET /ui-state 的 state.focusnoteid。
请求体
application/json
一次提交里对同一张卡做的多步写入。MarginNote 先按顺序模拟整批操作,任何一步不通过,整串都不 写入;写入之后重新读取核对,不一致就把改动过的卡整体恢复。一批最多 32 步,撤销栈上 只占一步。