mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-27 10:49:44 +00:00
Some checks are pending
CI / test (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { MarkupNode, markupToJSON } from '@hcengineering/text-core'
|
|
import { Extensions } from '@tiptap/core'
|
|
import { defaultExtensions } from '../extensions'
|
|
import { MarkdownParser } from './parser'
|
|
import { MarkdownState, storeMarks, storeNodes } from './serializer'
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export function parseMessageMarkdown (
|
|
message: string | undefined,
|
|
imageUrl: string,
|
|
refUrl: string = 'ref://',
|
|
extensions: Extensions = defaultExtensions
|
|
): MarkupNode {
|
|
const parser = new MarkdownParser(extensions, refUrl, imageUrl)
|
|
return parser.parse(message ?? '')
|
|
}
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export function serializeMessage (node: MarkupNode, refUrl: string, imageUrl: string): string {
|
|
const state = new MarkdownState(storeNodes, storeMarks, { tightLists: true, refUrl, imageUrl })
|
|
state.renderContent(node)
|
|
return state.out
|
|
}
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export async function markupToMarkdown (
|
|
markup: string,
|
|
refUrl: string = 'ref://',
|
|
imageUrl: string = 'http://localhost',
|
|
preprocessor?: (nodes: MarkupNode) => Promise<void>
|
|
): Promise<string> {
|
|
const json = markupToJSON(markup)
|
|
await preprocessor?.(json)
|
|
return serializeMessage(json, refUrl, imageUrl)
|
|
}
|