Skip to content

Commit

Permalink
feat: add getHTML api #218
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Jul 25, 2023
1 parent 0bacc11 commit b12c6cc
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 420 deletions.
14 changes: 13 additions & 1 deletion docs/guide/command-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,16 @@ const {
用法:
```javascript
const catalog = await instance.command.getCatalog()
```
```

## getHTML
功能:获取HTML

用法:
```javascript
const {
header: string
main: string
footer: string
} = await instance.command.getHTML()
```
2 changes: 2 additions & 0 deletions src/editor/core/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class Command {
public getCatalog: CommandAdapt['getCatalog']
public getImage: CommandAdapt['getImage']
public getValue: CommandAdapt['getValue']
public getHTML: CommandAdapt['getHTML']
public getWordCount: CommandAdapt['getWordCount']
public getRangeText: CommandAdapt['getRangeText']
public getRangeContext: CommandAdapt['getRangeContext']
Expand Down Expand Up @@ -167,6 +168,7 @@ export class Command {
// 获取
this.getImage = adapt.getImage.bind(adapt)
this.getValue = adapt.getValue.bind(adapt)
this.getHTML = adapt.getHTML.bind(adapt)
this.getWordCount = adapt.getWordCount.bind(adapt)
this.getRangeText = adapt.getRangeText.bind(adapt)
this.getRangeContext = adapt.getRangeContext.bind(adapt)
Expand Down
17 changes: 16 additions & 1 deletion src/editor/core/command/CommandAdapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TableBorder } from '../../dataset/enum/table/Table'
import { TitleLevel } from '../../dataset/enum/Title'
import { VerticalAlign } from '../../dataset/enum/VerticalAlign'
import { ICatalog } from '../../interface/Catalog'
import { DeepRequired } from '../../interface/Common'
import {
IAppendElementListOption,
IDrawImagePayload,
Expand All @@ -25,6 +26,7 @@ import {
} from '../../interface/Draw'
import {
IEditorData,
IEditorHTML,
IEditorOption,
IEditorResult
} from '../../interface/Editor'
Expand All @@ -37,6 +39,7 @@ import { ITr } from '../../interface/table/Tr'
import { IWatermark } from '../../interface/Watermark'
import { deepClone, downloadFile, getUUID } from '../../utils'
import {
createDomFromElementList,
formatElementContext,
formatElementList,
isTextLikeElement,
Expand All @@ -61,7 +64,7 @@ export class CommandAdapt {
private historyManager: HistoryManager
private canvasEvent: CanvasEvent
private tableTool: TableTool
private options: Required<IEditorOption>
private options: DeepRequired<IEditorOption>
private control: Control
private workerManager: WorkerManager
private searchManager: Search
Expand Down Expand Up @@ -1680,6 +1683,18 @@ export class CommandAdapt {
return this.draw.getValue(options)
}

public getHTML(): IEditorHTML {
const options = this.options
const headerElementList = this.draw.getHeaderElementList()
const mainElementList = this.draw.getOriginalMainElementList()
const footerElementList = this.draw.getFooterElementList()
return {
header: createDomFromElementList(headerElementList, options).innerHTML,
main: createDomFromElementList(mainElementList, options).innerHTML,
footer: createDomFromElementList(footerElementList, options).innerHTML
}
}

public getWordCount(): Promise<number> {
return this.workerManager.getWordCount()
}
Expand Down
3 changes: 1 addition & 2 deletions src/editor/core/cursor/CursorAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { VIRTUAL_ELEMENT_TYPE } from '../../dataset/constant/Element'
import { ElementType } from '../../dataset/enum/Element'
import { IElement } from '../../interface/Element'
import { debounce } from '../../utils'
import { getElementListByHTML } from '../../utils/clipboard'
import { formatElementContext } from '../../utils/element'
import { formatElementContext, getElementListByHTML } from '../../utils/element'
import { Draw } from '../draw/Draw'
import { CanvasEvent } from '../event/CanvasEvent'

Expand Down
6 changes: 6 additions & 0 deletions src/editor/interface/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ export interface IEditorResult {
watermark?: IWatermark
data: IEditorData
}

export interface IEditorHTML {
header: string
main: string
footer: string
}
Loading

0 comments on commit b12c6cc

Please sign in to comment.