|
| 1 | +# BlockNote Formats |
| 2 | + |
| 3 | +Right now, there are several formats supported by BlockNote: |
| 4 | + |
| 5 | +- internal html (serialized html from the editor's schema) for things like clipboard handling |
| 6 | +- external html (a "normal" html format) for things like rendering to a blog |
| 7 | +- markdown |
| 8 | +- exported formats: docx, pdf, react |
| 9 | + |
| 10 | +There is a relationship between all of these formats: |
| 11 | + |
| 12 | +```ts |
| 13 | +/** The editor content */ |
| 14 | +type Model = Block[] | InternalEditorState; |
| 15 | + |
| 16 | +type InternalHTML = string; |
| 17 | +function toInternalHTML(model: Model): InternalHTML; |
| 18 | +function fromInternalHTML(html: InternalHTML): Model; |
| 19 | + |
| 20 | +type ExternalHTML = string; |
| 21 | +function toExternalHTML(model: Model): ExternalHTML; |
| 22 | +function fromExternalHTML(html: ExternalHTML): Model; |
| 23 | + |
| 24 | +type Markdown = string; |
| 25 | +function toMarkdown(model: ExternalHTML): Markdown; |
| 26 | +function fromMarkdown(markdown: Markdown): Model; |
| 27 | + |
| 28 | +type Docx = Buffer; |
| 29 | +function toDocx(model: Model): Docx; |
| 30 | + |
| 31 | +type PDF = Buffer; |
| 32 | +function toPDF(model: Model): PDF; |
| 33 | +``` |
| 34 | + |
| 35 | +You'll notice that the formats are all derived from the model. |
| 36 | + |
| 37 | +This gives us a unidirectional flow of data. Any other direction is potentially lossy (e.g. markdown -> model). |
| 38 | + |
| 39 | +## Internal vs. External HTML |
| 40 | + |
| 41 | +There are two representations of HTML: |
| 42 | + |
| 43 | +- The internal HTML format which is a serialized version of the editor's schema, without regard for normalization (e.g. list items will be nested oddly) |
| 44 | + - Used for clipboard handling |
| 45 | +- The external HTML format which is a normalized version of the editor's schema, with list items nested "normally" |
| 46 | + |
| 47 | +The internal HTML format is "lossless", whereas the external HTML format is not |
| 48 | + |
| 49 | +Ideally we could avoid having to convert between the two formats, and just use the external HTML format as an output format. |
| 50 | + |
| 51 | +One idea to get closer to this, would be to have the clipboard instead use the model as the "internal" format, and then have the external HTML be a fallback for when the model would not be interpretable (such as by other applications). |
| 52 | + |
| 53 | +In an ideal world, we would only have a single html format, and it would be what is currently the "external" html format. |
| 54 | + |
| 55 | +See some earlier discussion about this: <https://github.com/TypeCellOS/BlockNote/issues/1583> |
0 commit comments