diff --git a/docs/src/demos/Examples/ExportHtmlOrJson/index.spec.js b/docs/src/demos/Examples/ExportHtmlOrJson/index.spec.js index 396e4bb5..482e30c2 100644 --- a/docs/src/demos/Examples/ExportHtmlOrJson/index.spec.js +++ b/docs/src/demos/Examples/ExportHtmlOrJson/index.spec.js @@ -11,7 +11,7 @@ context('/examples/export-html-or-json', () => { it('should return json', () => { cy.get('.ProseMirror').then(([{ editor }]) => { - const json = editor.json() + const json = editor.getJSON() expect(json).to.deep.equal({ type: 'document', @@ -32,7 +32,7 @@ context('/examples/export-html-or-json', () => { it('should return html', () => { cy.get('.ProseMirror').then(([{ editor }]) => { - const html = editor.html() + const html = editor.getHTML() expect(html).to.equal('
Example Text
') }) diff --git a/docs/src/demos/Examples/ExportHtmlOrJson/index.vue b/docs/src/demos/Examples/ExportHtmlOrJson/index.vue index aa89a0d8..b20e1907 100644 --- a/docs/src/demos/Examples/ExportHtmlOrJson/index.vue +++ b/docs/src/demos/Examples/ExportHtmlOrJson/index.vue @@ -50,13 +50,13 @@ export default { }) // Get the initial content … - this.json = this.editor.json() - this.html = this.editor.html() + this.json = this.editor.getJSON() + this.html = this.editor.getHTML() // … and get the content after every change. this.editor.on('update', () => { - this.json = this.editor.json() - this.html = this.editor.html() + this.json = this.editor.getJSON() + this.html = this.editor.getHTML() }) }, diff --git a/docs/src/demos/Extensions/Blockquote/index.spec.js b/docs/src/demos/Extensions/Blockquote/index.spec.js index b9c93d8b..d6e0cc7d 100644 --- a/docs/src/demos/Extensions/Blockquote/index.spec.js +++ b/docs/src/demos/Extensions/Blockquote/index.spec.js @@ -13,14 +13,14 @@ context('/api/extensions/blockquote', () => { it('should parse blockquote tags correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('should parse blockquote tags without paragraphs correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text') - expect(editor.html()).to.eq('
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/Extensions/Bold/index.spec.js b/docs/src/demos/Extensions/Bold/index.spec.js index 39ae2df1..dbdbba45 100644 --- a/docs/src/demos/Extensions/Bold/index.spec.js +++ b/docs/src/demos/Extensions/Bold/index.spec.js @@ -13,30 +13,30 @@ context('/api/extensions/bold', () => { it('should transform b tags to strong tags', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('sould omit b tags with normal font weight inline style', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('should transform any tag with bold inline style to strong tags', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/Extensions/BulletList/index.spec.js b/docs/src/demos/Extensions/BulletList/index.spec.js index 80824278..28f9a815 100644 --- a/docs/src/demos/Extensions/BulletList/index.spec.js +++ b/docs/src/demos/Extensions/BulletList/index.spec.js @@ -13,14 +13,14 @@ context('/api/extensions/bullet-list', () => { it('should parse unordered lists correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text')
- expect(editor.html()).to.eq('Example Text
Example Text
Example Text')
- expect(editor.html()).to.eq('Example Text')
+ expect(editor.getHTML()).to.eq('Example Text')
})
})
it('should parse code blocks with language correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('Example Text')
- expect(editor.html()).to.eq('Example Text')
+ expect(editor.getHTML()).to.eq('Example Text')
})
})
diff --git a/docs/src/demos/Extensions/Document/index.spec.js b/docs/src/demos/Extensions/Document/index.spec.js
index 66a973e6..0231d33c 100644
--- a/docs/src/demos/Extensions/Document/index.spec.js
+++ b/docs/src/demos/Extensions/Document/index.spec.js
@@ -11,7 +11,7 @@ context('/api/extensions/document', () => {
it('should return the document in as json', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
- const json = editor.json()
+ const json = editor.getJSON()
expect(json).to.deep.equal({
type: 'document',
diff --git a/docs/src/demos/Extensions/HardBreak/index.spec.js b/docs/src/demos/Extensions/HardBreak/index.spec.js
index 03120666..00586450 100644
--- a/docs/src/demos/Extensions/HardBreak/index.spec.js
+++ b/docs/src/demos/Extensions/HardBreak/index.spec.js
@@ -12,14 +12,14 @@ context('/api/extensions/hard-break', () => {
it('should parse hard breaks correctly', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setContent('Example
Text
Example
Text
Example
Text
Example
Text
Example
Text
Example
Text
Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/Extensions/HorizontalRule/index.spec.js b/docs/src/demos/Extensions/HorizontalRule/index.spec.js index 8273c7ef..30e962be 100644 --- a/docs/src/demos/Extensions/HorizontalRule/index.spec.js +++ b/docs/src/demos/Extensions/HorizontalRule/index.spec.js @@ -12,14 +12,14 @@ context('/api/extensions/horizontal-rule', () => { it('should parse horizontal rules correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('i tags with normal font style should be omitted', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('generic tags with italic style should be transformed to strong tags', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/Extensions/Link/index.spec.js b/docs/src/demos/Extensions/Link/index.spec.js index f9102b53..6f7f89c1 100644 --- a/docs/src/demos/Extensions/Link/index.spec.js +++ b/docs/src/demos/Extensions/Link/index.spec.js @@ -13,21 +13,21 @@ context('/api/extensions/link', () => { it('should parse a tags correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('') - expect(editor.html()).to.eq('') + expect(editor.getHTML()).to.eq('') }) }) it('should parse a tags with target attribute correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('') - expect(editor.html()).to.eq('') + expect(editor.getHTML()).to.eq('') }) }) it('should parse a tags with rel attribute correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('') - expect(editor.html()).to.eq('') + expect(editor.getHTML()).to.eq('') }) }) diff --git a/docs/src/demos/Extensions/OrderedList/index.spec.js b/docs/src/demos/Extensions/OrderedList/index.spec.js index d1cbafb2..acab83cc 100644 --- a/docs/src/demos/Extensions/OrderedList/index.spec.js +++ b/docs/src/demos/Extensions/OrderedList/index.spec.js @@ -13,14 +13,14 @@ context('/api/extensions/ordered-list', () => { it('should parse ordered lists correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') editor.setContent('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/Extensions/Strike/index.spec.js b/docs/src/demos/Extensions/Strike/index.spec.js index dd7140dd..f43f91d6 100644 --- a/docs/src/demos/Extensions/Strike/index.spec.js +++ b/docs/src/demos/Extensions/Strike/index.spec.js @@ -13,28 +13,28 @@ context('/api/extensions/strike', () => { it('should parse s tags correctly', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
Example Text
') - expect(editor.html()).to.eq('Example Text
Example Text
Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) it('should transform any tag with text decoration underline to u tags', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('Example Text
') - expect(editor.html()).to.eq('Example Text
') + expect(editor.getHTML()).to.eq('Example Text
') }) }) diff --git a/docs/src/demos/React/components/Editor.jsx b/docs/src/demos/React/components/Editor.jsx index 7700616b..8eec95cd 100644 --- a/docs/src/demos/React/components/Editor.jsx +++ b/docs/src/demos/React/components/Editor.jsx @@ -19,7 +19,7 @@ export const Editor = ({ content: value, ...props, }).on('transaction', () => { - onChange(e.json()) + onChange(e.getJSON()) }) setEditor(e) diff --git a/docs/src/docPages/api/commands.md b/docs/src/docPages/api/commands.md index 90818b41..3192ed56 100644 --- a/docs/src/docPages/api/commands.md +++ b/docs/src/docPages/api/commands.md @@ -34,7 +34,7 @@ Have a look at all of the core commands listed below. They should give you a goo | Command | Description | | --------------- | ----------------------------------------------------------- | | .clearContent() | Clear the whole document. | -| .insertHTML() | Insert a string of HTML at the currently selected position. | +| .insertgetHTML() | Insert a string of HTML at the currently selected position. | | .insertText() | Insert a string of text at the currently selected position. | | .setContent() | Replace the whole document with new content. | diff --git a/docs/src/docPages/api/editor.md b/docs/src/docPages/api/editor.md index 7067849a..1e0f0c73 100644 --- a/docs/src/docPages/api/editor.md +++ b/docs/src/docPages/api/editor.md @@ -20,13 +20,13 @@ This class is a central building block of tiptap. It does most of the heavy lift | `onBlur` | `Function` | `undefined` | Returns an object with the `event` and current `state` and `view` of Prosemirror on blur. | | `onFocus` | `Function` | `undefined` | Returns an object with the `event` and current `state` and `view` of Prosemirror on focus. | | `onInit` | `Function` | `undefined` | Returns an object with the current `state` and `view` of Prosemirror on init. | -| `onUpdate` | `Function` | `undefined` | Returns an object with the current `state` of Prosemirror, a `json()` and `html()` function and the `transaction` on every change. | +| `onUpdate` | `Function` | `undefined` | Returns an object with the current `state` of Prosemirror, a `getJSON()` and `getHTML()` function and the `transaction` on every change. | ## Methods | Method | Parameters | Description | | -------------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | -| `html()` | – | Returns the current content as HTML. | -| `json()` | – | Returns the current content as JSON. | +| `getHTML()` | – | Returns the current content as HTML. | +| `getJSON()` | – | Returns the current content as JSON. | | `destroy()` | – | Stops the editor instance and unbinds all events. | | `chain()` | - | Create a command chain to call multiple commands at once. | | `setOptions()` | `options` A list of options | Update editor options. | diff --git a/docs/src/docPages/api/schema.md b/docs/src/docPages/api/schema.md index 46f00a5c..37a4b3fc 100644 --- a/docs/src/docPages/api/schema.md +++ b/docs/src/docPages/api/schema.md @@ -128,7 +128,7 @@ const schema = getSchema([ If you need to render the content on the server side, e. g. for a blog post that was written with tiptap, you’ll probably need a way to do just that without an actual editor instance. -That’s what `generateHtml()` is for. It’s a utility function that renders HTML without an actual editor instance. +That’s what `generategetHTML()` is for. It’s a utility function that renders HTML without an actual editor instance. :::warning Work in progress Currently, that works only in the browser (client side), but we plan to bring this to Node.js (to use it on the server side). diff --git a/docs/src/docPages/guide/store-content.md b/docs/src/docPages/guide/store-content.md index 92c0497e..d69d267f 100644 --- a/docs/src/docPages/guide/store-content.md +++ b/docs/src/docPages/guide/store-content.md @@ -11,7 +11,7 @@ You can store your content as JSON and restore the content from HTML, or the oth JSON is probably easier to loop through, for example to look for a mention and it’s 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 the content as JSON: ```js -const json = editor.json() +const json = editor.getJSON() ``` You can store that in your database (or send it to an API) and restore the document initially like that: @@ -59,7 +59,7 @@ editor.setContent({ HTML can be easily rendered in other places, for example in emails and it’s wildly used, so it’s 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() +const html = editor.getHTML() ``` This can then be used to restore the document initially: diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 85ef9e64..9c69418e 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -376,14 +376,14 @@ export class Editor extends EventEmitter { /** * Get the document as JSON. */ - public json() { + public getJSON() { return this.state.doc.toJSON() } /** * Get the document as HTML. */ - public html() { + public getHTML() { return getHtmlFromFragment(this.state.doc, this.schema) }