toeverything / blocksuite

🧩 Content editing tech stack for the web - BlockSuite is a toolkit for building editors and collaborative applications.
https://blocksuite.io
Mozilla Public License 2.0
4.09k stars 353 forks source link

feat: add markdown export from synced doc block #7405

Closed L-Sun closed 1 week ago

L-Sun commented 1 week ago

Closes: BS-665

TL;DR

This PR adds support for exporting synced documents using embedSyncedDocMiddleware with MakrdownAdapter.

Example

const job = new Job({
  collection,
  middlewares: [embedSyncedDocMiddleware('content')],
});
const adapter = new MarkdownAdapter(job);
// Do what you want to exporting here using markdown adapter
const content = adapter.fromSliceSnapshot({snapshot});

There is a output example that export doc -> synced doc -> nested synced doc

# Doc

Hello, I' m Doc

// Begin: Embed synced doc block, export all content of synced doc
# Synced Doc

Hello, I'm Synced Doc

// Begin: Nested embed synced doc block, just export it's title
Nested Doc
// End: Nested embed synced doc block 
// End: Embed synced doc block

What changed?

  1. Transformers: Updated middlewares to include embedSyncedDocMiddleware.
  2. MarkdownAdapter: Added logic to handle 'embedSyncedDoc' nodes.
  3. Job Class: Added collection getter.
  4. Tests: Added unit tests for the synced-doc export logic.
  5. Uint Test Utilities: Modified createJob to accept middlewares and initialize with AffineSchemas.

Why make this change?

To enable loading content of embed-synced-doc for AI context. Related issue: BS-632

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 11:29am
1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **blocksuite-docs** | ⬜️ Ignored ([Inspect](https://vercel.com/toeverything/blocksuite-docs/EC83e1mRST3GF4QX4nJCuFF5qWTk)) | [Visit Preview](https://blocksuite-docs-git-06-24-feataddmarkdownex-1274cc-toeverything.vercel.app) | | Jun 24, 2024 11:29am |
graphite-app[bot] commented 1 week ago

Your org has enabled the Graphite merge queue for merging into master

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

L-Sun commented 1 week ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @L-Sun and the rest of your teammates on Graphite Graphite

graphite-app[bot] commented 1 week ago
Computer Reaction GIF by GitHub (Added via Giphy)
graphite-app[bot] commented 1 week ago

Merge activity