MNNote
MNNote是用于操作卡片的核心对象,提供卡片读取、定位、修改、内容提取和关联管理等功能,访问和管理卡片数据。
new MNNote(note:MNNote|MbBookNote|string|NoteConfig,alert?:boolean)构造一个新的MNNote实例。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
note | MNNote|MbBookNote|string|NoteConfig | 是 | 可传MNNote、MbBookNote、卡片id、marginnote4app://note/...链接、current等关键字、或建卡配置对象。 |
alert | boolean | 否 | 保留参数,当前实现中不会改变返回逻辑。 |
类成员(Class members)
Section titled “类成员(Class members)”| 字段名 | 类型 | 说明 |
|---|---|---|
noteCache | Record<string,MNNote> | 缓存已包装过的卡片实例,避免重复创建。 |
getNoteFromCache
Section titled “getNoteFromCache”static getNoteFromCache(noteId:string):MNNote|undefined按noteId直接读缓存。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
noteId | string | 是 | 目标卡片id。 |
- 类型:
MNNote|undefined - 语义:返回缓存中的MNNote实例或undefined。
noteFromId
Section titled “noteFromId”static noteFromId(noteId:string):MNNote|undefined按id获取MNNote,命中缓存就复用,未命中就创建并写回缓存。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
noteId | string | 是 | 目标卡片id。 |
- 类型:
MNNote|undefined - 语义:返回MNNote实例或undefined。
noteFromNote
Section titled “noteFromNote”static noteFromNote(note:MbBookNote):MNNote|undefined把原生MbBookNote包装成MNNote并接入缓存。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
note | MbBookNote | 是 | 原生卡片对象。 |
- 类型:
MNNote|undefined - 语义:返回MNNote实例或undefined。
实例成员(Instance members)
Section titled “实例成员(Instance members)”| 字段名 | 类型 | 说明 |
|---|---|---|
note | MbBookNote | 当前包装对象对应的原生卡片。 |
noteId | string | 当前卡片id。 |
id | string | noteId别名。 |
type | `“textNote" | "blankTextNote" |
isBlankNote | boolean | 判断是否为空白摘录卡。 |
notebookId | string | 当前卡片所在学习集id。 |
notebook | MNNotebook | 当前卡片所在学习集包装对象。 |
originNoteId | `string | undefined` |
originNote | `MNNote | undefined` |
groupNoteId | `string | undefined` |
groupNote | `MNNote | undefined` |
groupMode | number | 返回分组模式值。 |
mindmapBranchClose | boolean | 返回脑图分支折叠状态。 |
childNotes | MNNote[] | 返回直接子卡数组。 |
parentNote | `MNNote | undefined` |
parentNoteId | `string | undefined` |
childMindMap | `MNNote | undefined` |
descendantNodes | {descendant:MNNote[],treeIndex:number[][]} | 返回所有后代卡及其树路径索引。 |
ancestorNodes | MNNote[] | 返回从当前卡向上的祖先链。 |
brotherNotes | MNNote[] | 返回同级卡片数组。 |
indexInBrotherNotes | number | 返回当前卡在同级中的索引。 |
titles | string[] | 读写分号分隔的标题集合,写入时会去重。 |
title | string | 主标题视图,读取时会去掉{{...}}来源标题。 |
noteTitle | string | 原始标题字符串,不过滤{{...}}片段。 |
titlesFromMarkdown | string[] | 返回标题中{{...}}片段。 |
titlesWithoutMarkdownSource | string[] | 返回去掉{{...}}后的标题集合。 |
excerpt | {type:string,text?:string,textFirst?:boolean,isBlankNote?:boolean,imageHash?:string,audioHash?:string,videoHash?:string,pageNos?:number[]} | 返回摘录聚合信息,包含类型、文本、媒体hash和页码。 |
_excerptCache | `{info:{type:string,text?:string,textFirst?:boolean,isBlankNote?:boolean,imageHash?:string,audioHash?:string,videoHash?:string,pageNos?:number},refreshTime:number} | undefined` |
excerptType | `“text" | "image" |
isOCR | boolean | 判断当前摘录是否按OCR文本优先处理。 |
textFirst | boolean | 控制摘录以文本优先还是图片优先。 |
excerptText | `string | undefined` |
excerptTextMarkdown | `boolean | undefined` |
mainExcerptText | string | 带空字符串兜底的摘录文本访问入口。 |
excerptPic | `ExcerptPic | undefined` |
excerptPicData | `NSData | undefined` |
excerptVideoData | `NSData | undefined` |
excerptAudioData | `NSData | undefined` |
image | `UIImage | undefined` |
imageId | `string | undefined` |
imageData | `NSData | undefined` |
images | `UIImage[] | undefined` |
imageDatas | `NSData[] | undefined` |
hasVideo | boolean | 判断是否包含视频摘录。 |
videoId | `string | undefined` |
videoData | `NSData | undefined` |
comments | NoteComment[] | 返回原生评论数组。 |
MNComments | MNComment[] | 返回评论包装对象数组。 |
tags | string[] | 读取标签名数组,写入时会覆盖旧标签。 |
linkedNotes | object[] | 返回卡片链接关系集合。 |
summaryLinks | object[] | 返回摘要链接集合。 |
mediaList | object[] | 返回媒体列表。 |
excerptsTextPic | {ocr:string[],html:string[],md:string[]} | 聚合当前卡及其链接卡的摘录文本和图片转写结果。 |
commentsTextPic | {html:string[],md:string[]} | 聚合评论里的文本和绘图内容。 |
excerptsText | string[] | 收集当前卡和链接卡里的摘录文本。 |
commentsText | string[] | 收集评论文本,过滤标签和卡片链接。 |
allTextPic | {html:string,ocr:string,md:string} | 返回整卡文本和图片信息的拼接结果。 |
allText | string | 返回整卡纯文本长字符串。 |
excerptsCommentsText | string[] | 返回摘录与评论文本数组,过滤链接和标签噪音。 |
colorIndex | number | 读写卡片颜色索引。 |
color | string | 用颜色名读写卡片颜色。 |
getNoteColorHex | string | 返回当前颜色的Hex值。 |
colorHex | string | getNoteColorHex别名。 |
fillIndex | number | 读写填充样式索引。 |
createDate | string | 创建时间字符串。 |
createDateNumber | number | 创建时间时间戳。 |
modifiedDate | string | 最后修改时间字符串。 |
modifiedDateNumber | number | 最后修改时间时间戳。 |
noteURL | string | 返回卡片链接。 |
url | string | noteURL别名。 |
notes | MNNote[] | 返回当前卡与它的链接卡集合。 |
docMd5 | `string | undefined` |
startPage | `number | undefined` |
endPage | `number | undefined` |
pageNos | number[] | 返回当前卡及关联卡涉及的页码集合。 |
document | MNDocument | 返回当前卡关联文档对象。 |
exist | boolean | 判断底层卡片是否仍存在。 |
getExcerptInfo
Section titled “getExcerptInfo”getExcerptInfo():object|undefined返回摘录细节对象,包括类型、hash、选区、页码等。
- 类型:
object|undefined - 语义:返回摘录细节对象或undefined。
open():void在MarginNote中打开当前卡片。
- 类型:
void - 语义:无返回值。
appendExcerptText
Section titled “appendExcerptText”appendExcerptText(text:string):void在摘录正文末尾追加文本。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
text | string | 是 | 要追加的文本。 |
- 类型:
void - 语义:无返回值。
prependExcerptText
Section titled “prependExcerptText”prependExcerptText(text:string):void在摘录正文开头插入文本。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
text | string | 是 | 要插入的文本。 |
- 类型:
void - 语义:无返回值。
copy():void复制当前卡的关键信息到剪贴板。
- 类型:
void - 语义:无返回值。
config
Section titled “config”config(opt?:{first?:boolean}):object按配置导出卡片对象。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
opt | {first?:boolean} | 否 | 导出选项,默认{first:true}。 |
- 类型:
object - 语义:返回卡片配置对象。
realGroupNoteIdForTopicId
Section titled “realGroupNoteIdForTopicId”realGroupNoteIdForTopicId(nodebookid?:string):string返回当前卡在指定学习集下的真实组卡id。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
nodebookid | string | 否 | 目标学习集id,默认当前学习集。 |
- 类型:
string - 语义:返回真实组卡id。
realGroupNoteForTopicId
Section titled “realGroupNoteForTopicId”realGroupNoteForTopicId(nodebookid?:string):MNNote返回指定学习集下的真实组卡对象。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
nodebookid | string | 否 | 目标学习集id,默认当前学习集。 |
- 类型:
MNNote - 语义:返回真实组卡对象。
noteInDocForTopicId
Section titled “noteInDocForTopicId”noteInDocForTopicId(nodebookid?:string):MNNote按学习集映射返回对应卡片对象。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
nodebookid | string | 否 | 目标学习集id,默认当前学习集。 |
- 类型:
MNNote - 语义:返回映射后的卡片对象。
processMarkdownBase64Images
Section titled “processMarkdownBase64Images”processMarkdownBase64Images():void处理正文里Base64图片引用。
- 类型:
void - 语义:无返回值。
allNoteText
Section titled “allNoteText”allNoteText():string返回标题、正文、评论拼接文本,不含链接和标签。
- 类型:
string - 语义:返回拼接后的文本。
setTitle
Section titled “setTitle”setTitle(title:string):MNNote设置标题并返回自身,便于链式调用。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
title | string | 是 | 新标题。 |
- 类型:
MNNote - 语义:返回自身,便于链式调用。
setTtiles
Section titled “setTtiles”setTtiles(titles:string[]):MNNote设置多标题并返回自身。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
titles | string[] | 是 | 标题数组。 |
- 类型:
MNNote - 语义:返回自身,便于链式调用。
setTitleAndUpdateFromMarkdown
Section titled “setTitleAndUpdateFromMarkdown”setTitleAndUpdateFromMarkdown(title:string|string[]):MNNote先设置标题,再把正文Markdown标题补进{{...}}来源标题。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
title | `string | string[]` | 是 |
- 类型:
MNNote - 语义:返回自身,便于链式调用。
updateTitleFromMarkdown
Section titled “updateTitleFromMarkdown”updateTitleFromMarkdown():MNNote仅根据现有Markdown内容刷新来源标题片段。
- 类型:
MNNote - 语义:返回自身,便于链式调用。
_getMDContent
Section titled “_getMDContent”_getMDContent():string提取正文与评论中的Markdown内容。
- 类型:
string - 语义:返回Markdown内容。
getMDContent
Section titled “getMDContent”getMDContent(withBase64?:boolean):string把当前卡转换成完整Markdown文本。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
withBase64 | boolean | 否 | 为true时会把图片内容转成Base64文本嵌入。 |
- 类型:
string - 语义:返回完整的Markdown文本。