rename HTML function names
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { generateHtml } from '@tiptap/core'
|
import { generateHTML } from '@tiptap/core'
|
||||||
import { generateHtml as generateHtmlWithoutEditor } from '@tiptap/html'
|
import { generateHTML as generateHTMLWithoutEditor } from '@tiptap/html'
|
||||||
import Document from '@tiptap/extension-document'
|
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'
|
||||||
@@ -31,13 +31,13 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.html = generateHtml(this.json, [
|
this.html = generateHTML(this.json, [
|
||||||
Document(),
|
Document(),
|
||||||
Paragraph(),
|
Paragraph(),
|
||||||
Text(),
|
Text(),
|
||||||
])
|
])
|
||||||
|
|
||||||
this.otherHtml = generateHtmlWithoutEditor(this.json, [
|
this.otherHtml = generateHTMLWithoutEditor(this.json, [
|
||||||
Document(),
|
Document(),
|
||||||
Paragraph(),
|
Paragraph(),
|
||||||
Text(),
|
Text(),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export { default as markPasteRule } from './src/pasteRules/markPasteRule'
|
|||||||
|
|
||||||
export { default as capitalize } from './src/utils/capitalize'
|
export { default as capitalize } from './src/utils/capitalize'
|
||||||
export { default as getSchema } from './src/utils/getSchema'
|
export { default as getSchema } from './src/utils/getSchema'
|
||||||
export { default as generateHtml } from './src/utils/generateHtml'
|
export { default as generateHTML } from './src/utils/generateHTML'
|
||||||
export { default as getHtmlFromFragment } from './src/utils/getHtmlFromFragment'
|
export { default as getHTMLFromFragment } from './src/utils/getHTMLFromFragment'
|
||||||
export { default as getMarkAttrs } from './src/utils/getMarkAttrs'
|
export { default as getMarkAttrs } from './src/utils/getMarkAttrs'
|
||||||
export { default as mergeAttributes } from './src/utils/mergeAttributes'
|
export { default as mergeAttributes } from './src/utils/mergeAttributes'
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import getNodeAttrs from './utils/getNodeAttrs'
|
|||||||
import getMarkAttrs from './utils/getMarkAttrs'
|
import getMarkAttrs from './utils/getMarkAttrs'
|
||||||
import removeElement from './utils/removeElement'
|
import removeElement from './utils/removeElement'
|
||||||
import getSchemaTypeNameByName from './utils/getSchemaTypeNameByName'
|
import getSchemaTypeNameByName from './utils/getSchemaTypeNameByName'
|
||||||
import getHtmlFromFragment from './utils/getHtmlFromFragment'
|
import getHTMLFromFragment from './utils/getHTMLFromFragment'
|
||||||
import createStyleTag from './utils/createStyleTag'
|
import createStyleTag from './utils/createStyleTag'
|
||||||
import CommandManager from './CommandManager'
|
import CommandManager from './CommandManager'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
@@ -384,7 +384,7 @@ export class Editor extends EventEmitter {
|
|||||||
* Get the document as HTML.
|
* Get the document as HTML.
|
||||||
*/
|
*/
|
||||||
public getHTML() {
|
public getHTML() {
|
||||||
return getHtmlFromFragment(this.state.doc, this.schema)
|
return getHTMLFromFragment(this.state.doc, this.schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Node } from 'prosemirror-model'
|
import { Node } from 'prosemirror-model'
|
||||||
import getSchema from './getSchema'
|
import getSchema from './getSchema'
|
||||||
import getHtmlFromFragment from './getHtmlFromFragment'
|
import getHTMLFromFragment from './getHTMLFromFragment'
|
||||||
import { Extensions } from '../types'
|
import { Extensions } from '../types'
|
||||||
|
|
||||||
export default function generateHtml(doc: object, extensions: Extensions): string {
|
export default function generateHTML(doc: object, extensions: Extensions): string {
|
||||||
const schema = getSchema(extensions)
|
const schema = getSchema(extensions)
|
||||||
const contentNode = Node.fromJSON(schema, doc)
|
const contentNode = Node.fromJSON(schema, doc)
|
||||||
|
|
||||||
return getHtmlFromFragment(contentNode, schema)
|
return getHTMLFromFragment(contentNode, schema)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
|
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
|
||||||
|
|
||||||
export default function getHtmlFromFragment(doc: Node, schema: Schema): string {
|
export default function getHTMLFromFragment(doc: Node, schema: Schema): string {
|
||||||
const fragment = DOMSerializer
|
const fragment = DOMSerializer
|
||||||
.fromSchema(schema)
|
.fromSchema(schema)
|
||||||
.serializeFragment(doc.content)
|
.serializeFragment(doc.content)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { generateHtml } from '@tiptap/html'
|
import { generateHTML } from '@tiptap/html'
|
||||||
|
|
||||||
import Document from '@tiptap/extension-document'
|
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'
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const html = generateHtml({
|
const html = generateHTML({
|
||||||
type: 'document',
|
type: 'document',
|
||||||
content: [{
|
content: [{
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Node, DOMSerializer, Schema } from 'prosemirror-model'
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { createHTMLDocument } from 'hostic-dom'
|
import { createHTMLDocument } from 'hostic-dom'
|
||||||
|
|
||||||
export default function getHtmlFromFragment(doc: Node, schema: Schema): string {
|
export default function getHTMLFromFragment(doc: Node, schema: Schema): string {
|
||||||
return DOMSerializer
|
return DOMSerializer
|
||||||
.fromSchema(schema)
|
.fromSchema(schema)
|
||||||
.serializeFragment(doc.content, {
|
.serializeFragment(doc.content, {
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Extensions, getSchema } from '@tiptap/core'
|
import { Extensions, getSchema } from '@tiptap/core'
|
||||||
import { Node } from 'prosemirror-model'
|
import { Node } from 'prosemirror-model'
|
||||||
import getHtmlFromFragment from './getHtmlFromFragment'
|
import getHTMLFromFragment from './getHTMLFromFragment'
|
||||||
|
|
||||||
export function generateHtml(doc: object, extensions: Extensions): string {
|
export function generateHTML(doc: object, extensions: Extensions): string {
|
||||||
const schema = getSchema(extensions)
|
const schema = getSchema(extensions)
|
||||||
const contentNode = Node.fromJSON(schema, doc)
|
const contentNode = Node.fromJSON(schema, doc)
|
||||||
|
|
||||||
return getHtmlFromFragment(contentNode, schema)
|
return getHTMLFromFragment(contentNode, schema)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/// <reference types="cypress" />
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
import generateHtml from '@tiptap/html'
|
import { generateHTML } from '@tiptap/html'
|
||||||
import Document from '@tiptap/extension-document'
|
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'
|
||||||
|
|
||||||
describe('generateHtml', () => {
|
describe('generateHTML', () => {
|
||||||
it('generate HTML from JSON without an editor instance', () => {
|
it('generate HTML from JSON without an editor instance', () => {
|
||||||
const json = {
|
const json = {
|
||||||
type: 'document',
|
type: 'document',
|
||||||
@@ -18,7 +18,7 @@ describe('generateHtml', () => {
|
|||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
const html = generateHtml(json, [
|
const html = generateHTML(json, [
|
||||||
Document(),
|
Document(),
|
||||||
Paragraph(),
|
Paragraph(),
|
||||||
Text(),
|
Text(),
|
||||||
Reference in New Issue
Block a user