2019-01-16 22:07:52 +08:00
|
|
|
// This file is based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/simplemde/index.d.ts,
|
|
|
|
// which is written by Scalesoft <https://github.com/Scalesoft> and licensed under the MIT license:
|
2019-07-15 11:37:22 +02:00
|
|
|
//
|
2019-01-16 22:07:52 +08:00
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
2019-07-15 11:37:22 +02:00
|
|
|
//
|
2019-01-16 22:07:52 +08:00
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
2019-07-15 11:37:22 +02:00
|
|
|
//
|
2019-01-16 22:07:52 +08:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
/// <reference types="codemirror"/>
|
2022-01-14 23:23:54 +01:00
|
|
|
|
|
|
|
import { marked } from 'marked';
|
2019-01-16 21:32:41 +08:00
|
|
|
|
2020-01-29 15:57:28 +01:00
|
|
|
interface ArrayOneOrMore<T> extends Array<T> {
|
2021-10-05 22:28:22 +02:00
|
|
|
0: T;
|
2020-01-29 15:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ToolbarButton =
|
2020-04-06 14:07:24 +02:00
|
|
|
'bold'
|
|
|
|
| 'italic'
|
|
|
|
| 'quote'
|
|
|
|
| 'unordered-list'
|
|
|
|
| 'ordered-list'
|
|
|
|
| 'link'
|
|
|
|
| 'image'
|
2023-01-12 14:44:10 +02:00
|
|
|
| 'upload-image'
|
2020-04-06 14:07:24 +02:00
|
|
|
| 'strikethrough'
|
2020-01-29 15:57:28 +01:00
|
|
|
| 'code'
|
|
|
|
| 'table'
|
|
|
|
| 'redo'
|
|
|
|
| 'heading'
|
|
|
|
| 'undo'
|
|
|
|
| 'heading-bigger'
|
|
|
|
| 'heading-smaller'
|
|
|
|
| 'heading-1'
|
|
|
|
| 'heading-2'
|
|
|
|
| 'heading-3'
|
|
|
|
| 'clean-block'
|
|
|
|
| 'horizontal-rule'
|
|
|
|
| 'preview'
|
|
|
|
| 'side-by-side'
|
|
|
|
| 'fullscreen'
|
|
|
|
| 'guide';
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
declare namespace EasyMDE {
|
2020-03-20 14:35:24 +01:00
|
|
|
|
|
|
|
interface TimeFormatOptions {
|
|
|
|
locale?: string | string[];
|
|
|
|
format?: Intl.DateTimeFormatOptions;
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
interface AutoSaveOptions {
|
|
|
|
enabled?: boolean;
|
|
|
|
delay?: number;
|
2020-01-27 10:26:36 +01:00
|
|
|
submit_delay?: number;
|
2019-01-16 21:32:41 +08:00
|
|
|
uniqueId: string;
|
2020-03-20 14:35:24 +01:00
|
|
|
timeFormat?: TimeFormatOptions;
|
|
|
|
text?: string;
|
2019-01-16 21:32:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface BlockStyleOptions {
|
|
|
|
bold?: string;
|
|
|
|
code?: string;
|
|
|
|
italic?: string;
|
|
|
|
}
|
|
|
|
|
2022-01-11 21:38:36 +01:00
|
|
|
interface CustomAttributes {
|
|
|
|
[key: string]: string;
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
interface InsertTextOptions {
|
2019-01-16 22:07:52 +08:00
|
|
|
horizontalRule?: ReadonlyArray<string>;
|
|
|
|
image?: ReadonlyArray<string>;
|
|
|
|
link?: ReadonlyArray<string>;
|
|
|
|
table?: ReadonlyArray<string>;
|
2019-01-16 21:32:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ParsingOptions {
|
|
|
|
allowAtxHeaderWithoutSpace?: boolean;
|
|
|
|
strikethrough?: boolean;
|
|
|
|
underscoresBreakWords?: boolean;
|
|
|
|
}
|
|
|
|
|
2019-11-03 17:11:41 +01:00
|
|
|
interface PromptTexts {
|
|
|
|
image?: string;
|
|
|
|
link?: string;
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
interface RenderingOptions {
|
2019-11-03 17:11:41 +01:00
|
|
|
codeSyntaxHighlighting?: boolean;
|
|
|
|
hljs?: any;
|
2025-02-21 22:31:16 +01:00
|
|
|
markedOptions?: marked.MarkedExtension;
|
2020-03-06 00:43:08 +01:00
|
|
|
sanitizerFunction?: (html: string) => string;
|
2019-01-16 21:32:41 +08:00
|
|
|
singleLineBreaks?: boolean;
|
|
|
|
}
|
|
|
|
|
2019-01-16 22:07:52 +08:00
|
|
|
interface Shortcuts {
|
2019-01-16 21:32:41 +08:00
|
|
|
[action: string]: string | undefined | null;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
toggleBlockquote?: string | null;
|
|
|
|
toggleBold?: string | null;
|
|
|
|
cleanBlock?: string | null;
|
|
|
|
toggleHeadingSmaller?: string | null;
|
|
|
|
toggleItalic?: string | null;
|
|
|
|
drawLink?: string | null;
|
|
|
|
toggleUnorderedList?: string | null;
|
|
|
|
togglePreview?: string | null;
|
|
|
|
toggleCodeBlock?: string | null;
|
|
|
|
drawImage?: string | null;
|
|
|
|
toggleOrderedList?: string | null;
|
|
|
|
toggleHeadingBigger?: string | null;
|
|
|
|
toggleSideBySide?: string | null;
|
|
|
|
toggleFullScreen?: string | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface StatusBarItem {
|
|
|
|
className: string;
|
|
|
|
defaultValue: (element: HTMLElement) => void;
|
|
|
|
onUpdate: (element: HTMLElement) => void;
|
|
|
|
}
|
|
|
|
|
2020-01-29 15:57:28 +01:00
|
|
|
interface ToolbarDropdownIcon {
|
|
|
|
name: string;
|
|
|
|
children: ArrayOneOrMore<ToolbarIcon | ToolbarButton>;
|
|
|
|
className: string;
|
|
|
|
title: string;
|
|
|
|
noDisable?: boolean;
|
|
|
|
noMobile?: boolean;
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
interface ToolbarIcon {
|
|
|
|
name: string;
|
2019-02-27 13:54:57 +01:00
|
|
|
action: string | ((editor: EasyMDE) => void);
|
2019-01-16 21:32:41 +08:00
|
|
|
className: string;
|
|
|
|
title: string;
|
2019-02-20 01:59:54 +01:00
|
|
|
noDisable?: boolean;
|
|
|
|
noMobile?: boolean;
|
2021-02-26 09:06:01 -06:00
|
|
|
icon?: string;
|
2022-01-11 21:38:36 +01:00
|
|
|
attributes?: CustomAttributes;
|
2019-01-16 21:32:41 +08:00
|
|
|
}
|
|
|
|
|
2019-07-18 12:35:14 +02:00
|
|
|
interface ImageTextsOptions {
|
|
|
|
sbInit?: string;
|
|
|
|
sbOnDragEnter?: string;
|
|
|
|
sbOnDrop?: string;
|
|
|
|
sbProgress?: string;
|
|
|
|
sbOnUploaded?: string;
|
|
|
|
sizeUnits?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ImageErrorTextsOptions {
|
|
|
|
noFileGiven?: string;
|
2019-07-18 12:56:51 +02:00
|
|
|
typeNotAllowed?: string;
|
|
|
|
fileTooLarge?: string;
|
|
|
|
importError?: string;
|
2019-07-18 12:35:14 +02:00
|
|
|
}
|
|
|
|
|
2020-09-16 12:31:35 -07:00
|
|
|
interface OverlayModeOptions {
|
2021-10-05 22:28:22 +02:00
|
|
|
mode: CodeMirror.Mode<any>;
|
|
|
|
combine?: boolean;
|
2020-09-29 22:36:48 +02:00
|
|
|
}
|
2020-09-16 12:31:35 -07:00
|
|
|
|
2021-05-18 16:05:40 -07:00
|
|
|
interface SpellCheckerOptions {
|
2021-10-05 22:28:22 +02:00
|
|
|
codeMirrorInstance: CodeMirror.Editor;
|
2021-05-18 16:05:40 -07:00
|
|
|
}
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
interface Options {
|
|
|
|
autoDownloadFontAwesome?: boolean;
|
|
|
|
autofocus?: boolean;
|
|
|
|
autosave?: AutoSaveOptions;
|
2022-01-14 23:23:54 +01:00
|
|
|
autoRefresh?: boolean | { delay: number; };
|
2019-01-16 21:32:41 +08:00
|
|
|
blockStyles?: BlockStyleOptions;
|
|
|
|
element?: HTMLElement;
|
|
|
|
forceSync?: boolean;
|
2022-07-27 17:58:51 +01:00
|
|
|
hideIcons?: ReadonlyArray<ToolbarButton>;
|
2019-01-16 21:32:41 +08:00
|
|
|
indentWithTabs?: boolean;
|
|
|
|
initialValue?: string;
|
|
|
|
insertTexts?: InsertTextOptions;
|
2020-11-11 22:40:51 +01:00
|
|
|
lineNumbers?: boolean;
|
2019-01-16 21:32:41 +08:00
|
|
|
lineWrapping?: boolean;
|
2019-10-16 23:20:50 +11:00
|
|
|
minHeight?: string;
|
2020-06-03 22:45:59 +03:00
|
|
|
maxHeight?: string;
|
2019-01-16 21:32:41 +08:00
|
|
|
parsingConfig?: ParsingOptions;
|
|
|
|
placeholder?: string;
|
2019-07-15 11:37:22 +02:00
|
|
|
previewClass?: string | ReadonlyArray<string>;
|
2020-09-29 22:36:48 +02:00
|
|
|
previewImagesInEditor?: boolean;
|
2022-03-07 10:58:09 -05:00
|
|
|
imagesPreviewHandler?: (src: string) => string,
|
2022-06-07 19:55:27 +02:00
|
|
|
previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string | null;
|
2019-01-16 21:32:41 +08:00
|
|
|
promptURLs?: boolean;
|
|
|
|
renderingConfig?: RenderingOptions;
|
2019-01-16 22:07:52 +08:00
|
|
|
shortcuts?: Shortcuts;
|
2020-04-06 14:07:24 +02:00
|
|
|
showIcons?: ReadonlyArray<ToolbarButton>;
|
2021-05-18 16:05:40 -07:00
|
|
|
spellChecker?: boolean | ((options: SpellCheckerOptions) => void);
|
2020-01-27 10:26:36 +01:00
|
|
|
inputStyle?: 'textarea' | 'contenteditable';
|
|
|
|
nativeSpellcheck?: boolean;
|
2020-06-03 12:55:27 +02:00
|
|
|
sideBySideFullscreen?: boolean;
|
2019-02-27 13:54:57 +01:00
|
|
|
status?: boolean | ReadonlyArray<string | StatusBarItem>;
|
2019-01-16 21:32:41 +08:00
|
|
|
styleSelectedText?: boolean;
|
|
|
|
tabSize?: number;
|
2020-01-29 15:57:28 +01:00
|
|
|
toolbar?: boolean | ReadonlyArray<'|' | ToolbarButton | ToolbarIcon | ToolbarDropdownIcon>;
|
2019-01-16 21:32:41 +08:00
|
|
|
toolbarTips?: boolean;
|
2022-09-17 23:07:24 +02:00
|
|
|
toolbarButtonClassPrefix?: string;
|
2019-01-16 23:04:19 +08:00
|
|
|
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
|
|
|
|
theme?: string;
|
2020-10-04 06:38:01 +00:00
|
|
|
scrollbarStyle?: string;
|
2022-01-11 19:49:39 +01:00
|
|
|
unorderedListStyle?: '*' | '-' | '+';
|
2019-07-18 12:35:14 +02:00
|
|
|
|
|
|
|
uploadImage?: boolean;
|
|
|
|
imageMaxSize?: number;
|
|
|
|
imageAccept?: string;
|
2019-07-24 14:26:11 +02:00
|
|
|
imageUploadFunction?: (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => void;
|
2019-07-18 12:35:14 +02:00
|
|
|
imageUploadEndpoint?: string;
|
2021-03-11 12:09:09 -07:00
|
|
|
imagePathAbsolute?: boolean;
|
2019-07-18 12:35:14 +02:00
|
|
|
imageCSRFToken?: string;
|
2022-01-24 12:05:00 +08:00
|
|
|
imageCSRFName?: string;
|
|
|
|
imageCSRFHeader?: boolean;
|
2019-07-18 12:35:14 +02:00
|
|
|
imageTexts?: ImageTextsOptions;
|
2023-12-18 10:57:48 +01:00
|
|
|
imageInputName?: string
|
2019-07-18 12:35:14 +02:00
|
|
|
errorMessages?: ImageErrorTextsOptions;
|
|
|
|
errorCallback?: (errorMessage: string) => void;
|
2019-11-03 17:11:41 +01:00
|
|
|
|
|
|
|
promptTexts?: PromptTexts;
|
|
|
|
syncSideBySidePreviewScroll?: boolean;
|
2020-09-16 12:31:35 -07:00
|
|
|
|
2021-10-05 22:28:22 +02:00
|
|
|
overlayMode?: OverlayModeOptions;
|
2021-10-28 11:33:17 +02:00
|
|
|
|
|
|
|
direction?: 'ltr' | 'rtl';
|
2019-01-16 21:32:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
declare class EasyMDE {
|
|
|
|
constructor(options?: EasyMDE.Options);
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
value(): string;
|
|
|
|
value(val: string): void;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
codemirror: CodeMirror.Editor;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2021-06-10 16:18:35 +09:00
|
|
|
cleanup(): void;
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
toTextArea(): void;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
isPreviewActive(): boolean;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
isSideBySideActive(): boolean;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
isFullscreenActive(): boolean;
|
2019-02-27 13:54:57 +01:00
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
clearAutosavedValue(): void;
|
|
|
|
|
2023-01-12 14:38:17 +02:00
|
|
|
updateStatusBar(itemName: string, content: string): void;
|
|
|
|
|
2019-01-16 21:32:41 +08:00
|
|
|
static toggleBold: (editor: EasyMDE) => void;
|
|
|
|
static toggleItalic: (editor: EasyMDE) => void;
|
|
|
|
static toggleStrikethrough: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeadingSmaller: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeadingBigger: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeading1: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeading2: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeading3: (editor: EasyMDE) => void;
|
2022-05-17 23:17:04 +02:00
|
|
|
static toggleHeading4: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeading5: (editor: EasyMDE) => void;
|
|
|
|
static toggleHeading6: (editor: EasyMDE) => void;
|
2019-01-16 21:32:41 +08:00
|
|
|
static toggleCodeBlock: (editor: EasyMDE) => void;
|
|
|
|
static toggleBlockquote: (editor: EasyMDE) => void;
|
|
|
|
static toggleUnorderedList: (editor: EasyMDE) => void;
|
|
|
|
static toggleOrderedList: (editor: EasyMDE) => void;
|
|
|
|
static cleanBlock: (editor: EasyMDE) => void;
|
|
|
|
static drawLink: (editor: EasyMDE) => void;
|
|
|
|
static drawImage: (editor: EasyMDE) => void;
|
2020-08-16 19:30:31 +02:00
|
|
|
static drawUploadedImage: (editor: EasyMDE) => void;
|
2019-01-16 21:32:41 +08:00
|
|
|
static drawTable: (editor: EasyMDE) => void;
|
|
|
|
static drawHorizontalRule: (editor: EasyMDE) => void;
|
|
|
|
static togglePreview: (editor: EasyMDE) => void;
|
|
|
|
static toggleSideBySide: (editor: EasyMDE) => void;
|
|
|
|
static toggleFullScreen: (editor: EasyMDE) => void;
|
|
|
|
static undo: (editor: EasyMDE) => void;
|
|
|
|
static redo: (editor: EasyMDE) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export as namespace EasyMDE;
|
|
|
|
export = EasyMDE;
|