2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-06-27 13:11:01 -06:00
easy-markdown-editor/types/easymde-test.ts

239 lines
6.3 KiB
TypeScript
Raw Permalink Normal View History

2019-01-17 11:12:40 +01:00
// Create new instance
2019-07-23 12:53:38 +01:00
import EasyMDE = require('./easymde');
2019-01-17 11:12:40 +01:00
const editor = new EasyMDE({
2019-01-16 21:32:41 +08:00
autoDownloadFontAwesome: false,
2019-02-27 13:54:57 +01:00
element: document.getElementById('mdEditor')!,
hideIcons: ['side-by-side', 'fullscreen'],
inputStyle: 'textarea',
2019-01-16 21:32:41 +08:00
shortcuts: {
2019-02-27 13:54:57 +01:00
drawTable: 'Cmd-Alt-T',
toggleFullScreen: null,
2019-01-16 21:32:41 +08:00
},
2019-07-15 11:37:22 +02:00
previewClass: 'my-custom-class',
2019-01-17 11:12:40 +01:00
spellChecker: false,
2019-02-27 13:54:57 +01:00
onToggleFullScreen: (full: boolean) => {
console.log('FullscreenToggled', full);
},
2019-01-17 11:12:40 +01:00
theme: 'someOtherTheme',
minHeight: '200px',
2019-01-16 21:32:41 +08:00
});
2019-01-17 11:12:40 +01:00
// Editor functions
const value = editor.value() as string;
editor.value(value.toUpperCase());
const sbs = editor.isSideBySideActive() as boolean;
const fullscreen = editor.isFullscreenActive() as boolean;
// Access to codemirror object
editor.codemirror.setOption('readOnly', true);
// Static properties
2019-02-27 13:54:57 +01:00
EasyMDE.toggleItalic = (editor: EasyMDE) => {
console.log('SomeButtonOverride');
};
2019-07-15 11:37:22 +02:00
const editor2 = new EasyMDE({
autoDownloadFontAwesome: undefined,
previewClass: ['my-custom-class', 'some-other-class'],
nativeSpellcheck: true,
unorderedListStyle: '-',
inputStyle: 'contenteditable',
2019-10-19 16:00:18 +11:00
toolbar: [
{
name: 'bold',
action: EasyMDE.toggleBold,
2020-01-29 15:57:28 +01:00
className: 'fa fas fa-bolt',
title: 'Bold',
2019-07-15 11:37:22 +02:00
},
2019-10-19 16:00:18 +11:00
'|',
2020-01-29 15:57:28 +01:00
'undo',
2019-10-19 16:00:18 +11:00
{
name: 'alert',
action: (editor: EasyMDE) => {
alert('This is from a custom button action!');
// Custom functions have access to the `editor` instance.
},
2020-01-29 15:57:28 +01:00
className: 'fa fas fa-star',
2019-10-19 16:00:18 +11:00
title: 'A Custom Button',
noDisable: undefined,
noMobile: false,
attributes: {
'data-custom': 'attribute',
}
2019-10-19 16:00:18 +11:00
},
'|',
{
name: 'link',
action: 'https://github.com/Ionaru/easy-markdown-editor',
className: 'fa fab fa-github',
title: 'A Custom Link',
noDisable: true,
noMobile: true,
2020-01-29 15:57:28 +01:00
},
'preview',
{
name: 'links',
className: 'fa fas fa-arrow-down',
title: 'A Custom Link',
children: [
{
name: 'link',
action: 'https://github.com/Ionaru/easy-markdown-editor',
className: 'fa fab fa-github',
title: 'A Custom Link',
noDisable: true,
noMobile: true,
2020-01-29 15:57:28 +01:00
},
'preview',
{
name: 'bold',
action: EasyMDE.toggleBold,
className: 'fa fas fa-bold',
title: 'Bold',
attributes: {
'data-custom': 'some value',
'data-custom-2': 'another value',
}
2020-01-29 15:57:28 +01:00
},
],
},
],
2019-07-15 11:37:22 +02:00
});
editor2.clearAutosavedValue();
2023-01-12 14:38:17 +02:00
editor2.updateStatusBar('upload-image', 'Drag & drop images!');
2019-07-18 12:35:14 +02:00
EasyMDE.togglePreview(editor2);
EasyMDE.toggleSideBySide(editor2);
2019-07-18 12:35:14 +02:00
const editorImages = new EasyMDE({
uploadImage: true,
previewImagesInEditor: false,
2019-07-18 12:35:14 +02:00
imageAccept: 'image/png, image/bmp',
imageCSRFToken: undefined,
unorderedListStyle: '+',
2019-07-18 12:35:14 +02:00
imageMaxSize: 10485760,
imageUploadEndpoint: 'https://my.domain/image-upload/',
imageTexts: {
sbInit: 'Drag & drop images!',
sbOnDragEnter: 'Let it go, let it go',
sbOnDrop: 'Uploading...',
sbProgress: 'Uploading... (#progress#)',
sbOnUploaded: 'Upload complete!',
sizeUnits: 'b,Kb,Mb',
2019-07-18 12:35:14 +02:00
},
errorMessages: {
noFileGiven: 'Please select a file',
2019-07-18 12:56:51 +02:00
typeNotAllowed: 'This file type is not allowed!',
fileTooLarge: 'Image too big',
importError: 'Something went oops!',
2019-07-18 12:35:14 +02:00
},
2019-10-19 16:00:18 +11:00
errorCallback: errorMessage => {
2019-07-18 12:35:14 +02:00
console.error(errorMessage);
},
2019-07-18 12:35:14 +02:00
});
2019-07-23 12:53:38 +01:00
const editorImagesCustom = new EasyMDE({
uploadImage: true,
imageAccept: 'image/png, image/bmp',
imageCSRFToken: undefined,
imageMaxSize: 10485760,
imageUploadFunction: (file: File, onSuccess, onError) => {
console.log(file);
onSuccess('http://image.url/9.png');
onError('Failed because reasons.');
2019-07-23 12:53:38 +01:00
},
imageTexts: {
sbInit: 'Drag & drop images!',
sbOnDragEnter: 'Let it go, let it go',
sbOnDrop: 'Uploading...',
sbProgress: 'Uploading... (#progress#)',
sbOnUploaded: 'Upload complete!',
sizeUnits: 'b,Kb,Mb',
2019-07-23 12:53:38 +01:00
},
errorMessages: {
noFileGiven: 'Please select a file',
typeNotAllowed: 'This file type is not allowed!',
fileTooLarge: 'Image too big',
importError: 'Something went oops!',
2019-07-23 12:53:38 +01:00
},
2019-10-19 16:00:18 +11:00
errorCallback: errorMessage => {
2019-07-23 12:53:38 +01:00
console.error(errorMessage);
},
renderingConfig: {
codeSyntaxHighlighting: true,
markedOptions: {
silent: true,
highlight(code: string, lang: string, callback?: (error: (any | undefined), code: string) => void): string {
return 'something';
},
},
},
promptTexts: {
image: 'Insert URL',
},
syncSideBySidePreviewScroll: true,
});
new EasyMDE({
toolbarButtonClassPrefix: 'mde',
sideBySideFullscreen: true,
2020-11-11 22:40:51 +01:00
lineNumbers: false,
unorderedListStyle: '*',
autosave: {
enabled: true,
delay: 2000,
submit_delay: 10000,
uniqueId: 'abc',
timeFormat: {
locale: 'en-GB',
format: {
month: 'long',
},
},
text: 'Stored: ',
},
});
new EasyMDE({
sideBySideFullscreen: false,
2020-11-11 22:40:51 +01:00
lineNumbers: true,
2020-06-03 17:30:13 +03:00
maxHeight: '500px',
toolbar: [
'bold',
'italic',
'heading',
'|',
'quote',
'unordered-list',
'ordered-list',
'table',
'upload-image',
'|',
'link',
],
});
new EasyMDE({
direction: 'ltr',
});
new EasyMDE({
direction: 'rtl',
});
new EasyMDE({
previewRender: (plainText: string) => {
return '<pre>' + plainText + '</pre>';
}
});
new EasyMDE({
previewRender: (plainText: string, preview) => {
preview.innerHTML = '<pre>' + plainText + '</pre>';
return null;
}
});