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

@@ -8,7 +8,6 @@ import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph' import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text' import Text from '@tiptap/extension-text'
export default { export default {
components: { components: {
EditorContent, EditorContent,
@@ -22,7 +21,14 @@ export default {
mounted() { mounted() {
this.editor = new Editor({ this.editor = new Editor({
content: '<p>This is a radically reduced version of tiptap for minimalisits. It has only support for a document, paragraphs and text. Thats it.</p>', content: `
<p>
This is a radically reduced version of tiptap. It has only support for a document, paragraphs and text. Thats it. Its probably too much for real minimalists though.
</p>
<p>
The paragraph extension is not literally required, but you need at least one node. That node can be something different, for example to render a task list and only that task list.
</p>
`,
extensions: [ extensions: [
Document(), Document(),
Paragraph(), Paragraph(),

View File

@@ -1,7 +1,7 @@
# Blockquote # Blockquote
The Blockquote extension enables you to use the `<blockquote>` HTML tag in the editor. This is great you might have guessed to use quotes in the editor. The Blockquote extension enables you to use the `<blockquote>` HTML tag in the editor. This is great you might have guessed to use quotes in the editor.
Type `> ` at the beginning of a new line and it will be magically transformed to a blockquote. Type `> ` at the beginning of a new line and it will be magically transformed to a blockquote.
## Options ## Options
| Option | Type | Default | Description | | Option | Type | Default | Description |

View File

@@ -1,3 +1,3 @@
# Simple # Simple
<demo name="Examples/Simple" highlight="7-9,27-29" /> <demo name="Examples/Simple" highlight="7-9,26-28" />

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: 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 * HTML and JSON can both have deeply nested structures, Markdown cant have those
* Tables are not part of the Markdown standard, and cant be easily stored and restored from Markdown * 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.

View File

@@ -58,3 +58,20 @@ const CustomExtension = …
:::warning Breaking Change :::warning Breaking Change
Currently, blockquotes must not be nested anymore. That said, were working on bringing it back. If you use nested blockquotes in your app, dont upgrade yet. Currently, blockquotes must not be nested anymore. That said, were working on bringing it back. If you use nested blockquotes in your app, dont upgrade yet.
::: :::
### 5. Renamed API methods
[We renamed a lot of commands](/api/commands), hopefully you can migrate to the new API with search & replace. Here is a list of what changed:
| Old method name | New method name |
| --------------- | --------------- |
| ~~`getHTML`~~ | `html` |
| ~~`getJSON`~~ | `json` |
### 6. .focus() isnt called on every command anymore
We tried to hide the `.focus()` command from you with tiptap 1 and executed that on every other command. That led to issues in specific use cases, where you want to run a command, but dont want to focus the editor. With tiptap 2.x you have to explicitly call the `focus()` and you probably want to do that in a lot of places. Here is an example:
```js
editor.focus().bold()
```

View File

@@ -20,10 +20,8 @@
draft: true draft: true
- title: Custom styling - title: Custom styling
link: /guide/custom-styling link: /guide/custom-styling
draft: true
- title: Get content - title: Get content
link: /guide/get-content link: /guide/get-content
draft: true
- title: Custom extensions - title: Custom extensions
link: /guide/custom-extensions link: /guide/custom-extensions
draft: true draft: true