add morrre content

This commit is contained in:
Hans Pagel
2020-09-16 17:01:47 +02:00
parent 80682bbffb
commit c307171295
7 changed files with 160 additions and 14 deletions

View File

@@ -1 +1,58 @@
# Custom Styling
# Custom styling
Tiptap is renderless, that doesnt mean there is no styling provided. You can decided how your editor should look like.
## Option 1: Styling the plain HTML
The content is rendered as HTML, so you can just use that to add styling:
```css
p {
margin: 1em 0;
}
```
## Option 2: Adding custom classes everywhere
Every node has a `class` option, that you can use to add a custom class to the rendered HTML tag.
```js
new Editor({
extensions: [
Document(),
Paragraph({
class: 'my-custom-paragraph',
}),
Heading({
class: 'my-custom-heading',
}),
Text(),
]
})
```
This will be the result then:
```html
<h1 class="my-custom-heading">Example Text</p>
<p class="my-custom-paragraph">Wow, thats really custom.</p>
```
## Option 3: Customizing the HTML markup
You can even customize the markup for every extension. This will make a custom bold extension that doesnt render a `<strong>` tag, but a `<b>` tag:
```js
import Bold from '@tiptap/extension-bold'
const CustomBold = Bold
.schema(() => ({
toDOM: () => ['b', 0],
}))
.create()
new Editor({
extensions: [
// …
CustomBold(),
]
})
```
You should put your custom extensions in separate files though, but I think youve got the idea.

View File

@@ -1,14 +1,82 @@
# Get Content
# Get content
You can store your content as JSON or you can get a good old HTML string. Both work fine. And of course, you can pass both formats to the editor to restore your content.
## Working with JSON
Funfact: You can store your content as JSON and restore the content from HTML, or the other way around. I dont know why you would want to do that, but tiptap wouldnt care.
## Working with HTML
## Option 1: Work with JSON
JSON is probably easier to loop through, for example to look for a mention and its more like what tiptap uses under the hood. Anyway, if you want to use JSON to store the content we provide a method to retrieve JSON:
## tiptap doesnt work with Markdown
```js
const json = editor.json()
```
You can store that in your database or send it to an API and restore the document initially like that:
```js
new Editor({
// …
content: {
"type": "document",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Example Text"
}
]
}
]
},
})
```
Or if you need to wait for something, you can do it later through the editor instance:
```js
editor.setContent({
"type": "document",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Example Text"
}
]
}
]
})
```
## Option 2: Work with HTML
HTML can be easily rendered in other places, for example in emails and its wildly used, so its probably easier to switch the editor at some point. Anyway, every editor instance provides a method to get HTML from the current document:
```js
const html = editor.html()
```
This can then be used to restore the document initially:
```js
new Editor({
// …
content: `<p>Example Text</p>`,
})
```
Or if you want to restore the content later (e. g. after an API call has finished), you can do that too:
```js
editor.setContent(`<p>Example Text</p>`)
```
## Not an option: Markdown
Unfortunately, tiptap doesnt support Markdown as input/output format. We considered to add support for it, but there are a few limitations:
* HTML or JSON can have deeply nested structures, Markdown not
* Tables are not part of the Markdown standard, and cant be easily stored and restored from Markdown
* HTML and JSON can both have deeply nested structures, Markdown cant have those
* Tables are not part of the Markdown standard, and cant easily be stored and restored from Markdown
You should really consider to work with HTML or JSON to store your content. If you still think you need Markdown, Nextcloud uses tiptap to work with Markdown. There code is open source, so maybe you can learn from them.
You should really consider to work with HTML or JSON to store your content. If you still think you need Markdown, [Nextcloud Text](https://github.com/nextcloud/text) uses tiptap to work with Markdown. Their code is open source, so maybe you can learn from them.