Sign in

    markdowns-in-graph-core

    MoonBit core engine for Markdowns In Graph: wikilink parsing, vault indexing, graph building, Barnes-Hut layout, and NoteQL — an incremental graph query engine with dependency-aware caching.

    markdown
    wikilink
    knowledge-graph
    force-directed
    query-language
    datalog
    vscode
    wasm
    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    4 hours ago
    Downloads
    2

    No dependencies

    #Markdowns In Graph · Core Engine (MoonBit)

    markdowns-in-graph-core 是 VS Code 扩展 Markdowns In Graph 的计算内核, 用 MoonBit 编写并编译为 WebAssembly(wasm-gc)与 JavaScript(js)两种产物。

    它负责扩展里全部「脏活」:

    包职责
    pathPOSIX 风格路径运算:dirname / basename / extname / normalize / URI 解码
    mdparseMarkdown 扫描器:双链 [[a]]、![[a]]、[t](a.md)、行内标签、Frontmatter 标签、代码围栏
    vault工作区索引、Obsidian「最短路径优先」链接解析、图谱构建与统计
    layoutBarnes-Hut 四叉树力导向布局 + 网格碰撞消解
    queryNoteQL:SQL 风格的图查询、关系物化、BFS/SCC、聚合、依赖感知缓存
    根包给宿主的 ABI:#export_name 导出的字符串 / 数值接口

    #构建

    moon check --target wasm-gc moon test --target wasm-gc # 41 个测试 moon build --target wasm-gc --release # _build/wasm-gc/release/build/markdowns-in-graph-core.wasm moon build --target js --release # _build/js/release/build/markdowns-in-graph-core.js

    在仓库根目录也可以:

    npm run core:check npm run core:test npm run core:build

    #宿主协议

    宿主(TypeScript)不解析任何 Markdown,也不维护链接索引,只做三件事: 读文件、把文本喂给内核、把内核吐出的 JSON 交给 Webview 渲染。

    vault_reset() vault_add_note(rel, size, mtime, text) vault_add_attachment(rel, size, mtime) vault_build_graph(max_tags, generated_at, root_name) -> JSON noteql_run(source, use_cache) -> JSON

    数值接口的布局 API 让 Webview 每帧只做 2N 次 layout_x / layout_y 调用, 避免把整张图的坐标反复序列化成字符串。

    #NoteQL

    note file link tag unresolved ambiguous orphan cycle distance reachable in_cycle indegree outdegree degree

    查询语言与语义见仓库的 docs/NOTEQL.md: https://github.com/L1r0gn/markdowns-in-graph-moonbit/blob/main/docs/NOTEQL.md

    core_selftest

    fn core_selftest() -> String

    自检:跑一遍「解析 -> 建索引 -> 构图」,返回 "ok:<节点数>"。 宿主用它判断当前运行时是否真的能把 Wasm 用起来。

    core_version

    fn core_version() -> String

    fn layout_add_link(a : Int, b : Int) -> Unit

    layout_add_node

    fn layout_add_node(degree : Int, radius : Double) -> Unit

    layout_count

    fn layout_count() -> Int

    layout_move

    fn layout_move(i : Int, x : Double, y : Double) -> Unit

    layout_pin

    fn layout_pin(i : Int, x : Double, y : Double) -> Unit

    layout_reset

    fn layout_reset() -> Unit

    layout_seed

    fn layout_seed(i : Int, x : Double, y : Double) -> Unit

    layout_step

    fn layout_step(alpha : Double, rest : Double, repulsion : Double) -> Unit

    layout_unpin

    fn layout_unpin(i : Int) -> Unit

    layout_x

    fn layout_x(i : Int) -> Double

    layout_y

    fn layout_y(i : Int) -> Double

    noteql_relations

    fn noteql_relations() -> String

    内置关系与列清单,供查询面板补全与文档展示。

    noteql_reset_cache

    fn noteql_reset_cache() -> Unit

    noteql_run

    fn noteql_run(source : String, use_cache : Int) -> String

    执行一条 NoteQL 查询。use_cache 非 0 时允许复用上次结果。

    noteql_selftest

    fn noteql_selftest() -> String

    查询引擎自检:独立构造一个临时 vault,不污染当前工作区索引。

    noteql_stats

    fn noteql_stats() -> String

    缓存命中率与变更序列,供基准测试与调试。

    parse_markdown_json

    fn parse_markdown_json(text : String) -> String

    解析单篇 Markdown,返回 { links: [...], tags: [...] }。 主要用于调试面板与契约测试。

    vault_add_attachment

    fn vault_add_attachment(rel : String, size : Int, mtime : Double) -> Unit

    写入 / 更新一个附件(不解析内容)。

    vault_add_note

    fn vault_add_note(rel : String, size : Int, mtime : Double, text : String) -> Unit

    写入 / 更新一篇笔记(MoonBit 内部完成解析)。

    vault_build_graph

    fn vault_build_graph(max_tags : Int, generated_at : Int, root_name : String) -> String

    构建图谱,产出与旧版 GraphData 完全一致的 JSON。

    vault_count

    fn vault_count() -> Int

    vault_folders

    fn vault_folders() -> String

    目录列表:[{ path, count }],供「文件夹图谱」命令使用。

    vault_note_count

    fn vault_note_count() -> Int

    vault_remove

    fn vault_remove(rel : String) -> Unit

    vault_reset

    fn vault_reset() -> Unit

    vault_resolve

    fn vault_resolve(from_rel : String, target : String) -> String

    诊断用:把链接目标解析成真实路径,解析失败返回空串。

    Source Files