-
-
Notifications
You must be signed in to change notification settings - Fork 341
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: support add custom inline nodes #5909
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Briefing the API surface in PR description will be very helpful :)
How to view the demo in playground? |
c7d0834
to
7641be4
Compare
done @doodlewind @Saul-Mirone |
de0455b
to
3ba5779
Compare
There are more features in AFFiNE requires us to extend the default blocksutie doc editor. For example, we want to let the inline page reference to have different ui/ux in some cases - like localization for journal pages. If we try to extend "LinkedPage" reference, this is what we can do right now based on the changes in this PR:
It looks to me that this approach is still not mature enough for use in affine yet.
|
If it's just about changing the UI, maybe more reasonable to provide some kind of interface directly in |
After this PR is merged, externals can implement customization for inline elements by overriding the service for specific blocks.
InlineSpec
InlineSpec
is a format for defining inline elements. Externals can describe the rendering method and corresponding data structure for a particular inline element using this format.Renderer
The renderer in
InlineSpec
needs to return aTemplateResult
to implement the rendering of inline elements. For its implementation, you can refer to the following link:affine-text
is the most common non-embed type of inline node in blocksuite, responsible for bolding, underlining, and other basic styles.blocksuite/packages/blocks/src/_common/inline/presets/nodes/affine-text.ts
Lines 45 to 78 in 8fd0f98
latex-node
is an embed-type node used as an example in this PR, capable of rendering mathematical formulas.blocksuite/packages/playground/apps/default/specs-examples/latex/latex-node.ts
Lines 17 to 65 in 8fd0f98
InlineMarkdownMatch
Currently, we have preset a mechanism to trigger inline formatting changes using markdown syntax. For example, in "abc", if you want to change "b" to bold, you need to enter 'a' + '**b**' + space + 'c'.
InlineMarkdownMatch
is a format that describes such shortcuts. Apart from realizing inline formatting transformations through these preset shortcuts, it is more common to achieve this through extending theformat-bar
. However, this goes beyond the scope of this PR, so no further description will be provided.Latex Example
This PR uses new API to write a simplified example, which can be experienced at branch playground, and the main core code is as follows:
blocksuite/packages/playground/apps/default/specs-examples/latex/latex.ts
Lines 20 to 121 in 8fd0f98
CleanShot.2024-01-03.at.11.22.00.mp4