Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add markdown export from synced doc block #7405

Merged

Conversation

L-Sun
Copy link
Contributor

@L-Sun L-Sun commented Jun 24, 2024

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

Copy link

vercel bot commented Jun 24, 2024

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) Visit Preview Jun 24, 2024 11:29am

Copy link

graphite-app bot commented Jun 24, 2024

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.

Copy link
Contributor Author

L-Sun commented Jun 24, 2024

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

Copy link

graphite-app bot commented Jun 24, 2024

Computer Reaction GIF by GitHub (Added via Giphy)

Copy link

graphite-app bot commented Jun 24, 2024

Merge activity

  • Jun 24, 7:26 AM EDT: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jun 24, 7:27 AM EDT: L-Sun added this pull request to the Graphite merge queue.
  • Jun 24, 7:38 AM EDT: L-Sun merged this pull request with the Graphite merge queue.

Closes: [BS-665](https://linear.app/affine-design/issue/BS-665/%E6%94%AF%E6%8C%81-embed-synced-doc-%E7%9A%84-markdown-%E5%AF%BC%E5%87%BA)

### TL;DR

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

### Example
```ts
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`
```md
# 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](https://linear.app/affine-design/issue/BS-632/synced-block-%E6%96%87%E6%A1%A3%E6%94%AF%E6%8C%81%EF%BC%9A%E8%AF%BB%E5%8F%96%E6%96%87%E6%A1%A3%E5%86%85%E5%AE%B9%E4%BD%9C%E4%B8%BA-ai-%E7%9A%84%E4%B8%8A%E4%B8%8B%E6%96%87-cotent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants