mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Update typings and test for markdown-draft-js (#43980)
Co-authored-by: irina.shasheva <irina.shasheva@jetbrains.com>
This commit is contained in:
46
types/markdown-draft-js/index.d.ts
vendored
46
types/markdown-draft-js/index.d.ts
vendored
@@ -4,8 +4,48 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
import { RawDraftContentState } from 'draft-js';
|
||||
import { RawDraftContentState, Entity } from 'draft-js';
|
||||
|
||||
export function markdownToDraft(markdown: string): RawDraftContentState;
|
||||
export interface BlockEntitiesParam {
|
||||
[key: string]: (item?: { [key: string]: any }) => Entity;
|
||||
}
|
||||
|
||||
export function draftToMarkdown(RawDraft: RawDraftContentState): string;
|
||||
export interface BlockTypesParam {
|
||||
[key: string]: (item?: {
|
||||
[key: string]: any;
|
||||
}) => {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MarkdownToDraftOptions {
|
||||
blockEntities?: BlockEntitiesParam;
|
||||
blockStyles?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
blockTypes?: BlockTypesParam;
|
||||
remarkableOptions?: {
|
||||
[key: string]: boolean | {};
|
||||
};
|
||||
remarkablePlugins?: any[];
|
||||
remarkablePreset?: string;
|
||||
}
|
||||
|
||||
export interface DraftToMarkdownOptions {
|
||||
entityItems?: {
|
||||
[key: string]: {
|
||||
open: (entity?: Entity) => string;
|
||||
close: (entity?: Entity) => string;
|
||||
};
|
||||
};
|
||||
styleItems?: {
|
||||
[key: string]: {
|
||||
open: () => string;
|
||||
close: () => string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function markdownToDraft(markdown: string, options?: MarkdownToDraftOptions): RawDraftContentState;
|
||||
|
||||
export function draftToMarkdown(RawDraft: RawDraftContentState, options?: DraftToMarkdownOptions): string;
|
||||
|
||||
@@ -4,5 +4,116 @@ import { draftToMarkdown, markdownToDraft } from 'markdown-draft-js';
|
||||
const rawContent = convertToRaw(EditorState.createEmpty().getCurrentContent());
|
||||
draftToMarkdown(rawContent);
|
||||
|
||||
// Handle options.styleItems
|
||||
draftToMarkdown(rawContent, {
|
||||
styleItems: {
|
||||
RED: {
|
||||
open() {
|
||||
return '<span style="color: red">';
|
||||
},
|
||||
|
||||
close() {
|
||||
return '</span>';
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Handle options.entityItems
|
||||
draftToMarkdown(rawContent, {
|
||||
entityItems: {
|
||||
mention: {
|
||||
open: () => {
|
||||
return '<span class="mention-item">';
|
||||
},
|
||||
|
||||
close: () => {
|
||||
return '</span>';
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Handle markdown param
|
||||
const rawDraft = markdownToDraft('# Test');
|
||||
convertFromRaw(rawDraft);
|
||||
|
||||
// Handle options.blockEntities without arguments and options.remarkablePlugins
|
||||
const rawDraftWithBlockEntities = markdownToDraft('# Test', {
|
||||
blockEntities: {
|
||||
link_open: () => {
|
||||
return {
|
||||
type: 'LINK',
|
||||
mutability: 'MUTABLE',
|
||||
};
|
||||
},
|
||||
},
|
||||
remarkablePlugins: [{}],
|
||||
});
|
||||
convertFromRaw(rawDraftWithBlockEntities);
|
||||
|
||||
// Handle options.blockEntities with argument
|
||||
const rawDraftWithBlockEntitiesArguments = markdownToDraft('# Test', {
|
||||
blockEntities: {
|
||||
link_open: item => {
|
||||
const data = item && {
|
||||
url: item.href,
|
||||
href: item.href,
|
||||
};
|
||||
return {
|
||||
type: 'LINK',
|
||||
mutability: 'MUTABLE',
|
||||
data,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
convertFromRaw(rawDraftWithBlockEntitiesArguments);
|
||||
|
||||
// Handle options.blockStyles
|
||||
const rawDraftWithBlockStyles = markdownToDraft('# Test', {
|
||||
blockStyles: {
|
||||
code: 'CODE',
|
||||
},
|
||||
});
|
||||
convertFromRaw(rawDraftWithBlockStyles);
|
||||
|
||||
// Handle options.blockTypes without arguments
|
||||
const rawDraftWithBlockTypes = markdownToDraft('# Test', {
|
||||
blockTypes: {
|
||||
paragraph_open: () => {
|
||||
return {
|
||||
type: 'unstyled',
|
||||
text: '',
|
||||
entityRanges: [],
|
||||
inlineStyleRanges: [],
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
convertFromRaw(rawDraftWithBlockTypes);
|
||||
|
||||
// Handle options.blockTypes with argument
|
||||
const rawDraftWithBlockTypesArguments = markdownToDraft('# Test', {
|
||||
blockTypes: {
|
||||
paragraph_open: item => {
|
||||
const text = item ? item.text : '';
|
||||
return {
|
||||
type: 'unstyled',
|
||||
text,
|
||||
entityRanges: [],
|
||||
inlineStyleRanges: [],
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
convertFromRaw(rawDraftWithBlockTypesArguments);
|
||||
|
||||
// Handle options.remarkablePreset and options.remarkableOptions
|
||||
const rawDraftWithRemarkablePreset = markdownToDraft('# Test', {
|
||||
remarkablePreset: 'commonmark',
|
||||
remarkableOptions: {
|
||||
html: true,
|
||||
},
|
||||
});
|
||||
convertFromRaw(rawDraftWithRemarkablePreset);
|
||||
|
||||
Reference in New Issue
Block a user