Skip to content

Commit

Permalink
Feature: Paste from markdown PoC.
Browse files Browse the repository at this point in the history
  • Loading branch information
martnpaneq committed Oct 20, 2023
1 parent fea4f07 commit 4dce8d9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/ckeditor5-markdown-gfm/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import { Plugin, type Editor } from 'ckeditor5/src/core';
import GFMDataProcessor from './gfmdataprocessor';
import type { ClipboardPipeline, ClipboardInputTransformationEvent } from 'ckeditor5/src/clipboard';
import type { ViewDocumentKeyDownEvent } from 'ckeditor5/src/engine';

/**
* The GitHub Flavored Markdown (GFM) plugin.
Expand All @@ -31,4 +33,31 @@ export default class Markdown extends Plugin {
public static get pluginName() {
return 'Markdown' as const;
}

/**
* @inheritDoc
*/
public init(): void {
const editor = this.editor;
const view = editor.editing.view;
const viewDocument = view.document;

const clipboardPipeline: ClipboardPipeline = editor.plugins.get( 'ClipboardPipeline' );

let shiftPressed = false;

this.listenTo<ViewDocumentKeyDownEvent>( viewDocument, 'keydown', ( evt, data ) => {
shiftPressed = data.shiftKey;
} );

this.listenTo<ClipboardInputTransformationEvent>( clipboardPipeline, 'inputTransformation', ( evt, data ) => {
if ( data.dataTransfer.getData( 'text/html' ) || shiftPressed ) {
return;
}

const dataStr = data.dataTransfer.getData( 'text/plain' );

data.content = editor.data.processor.toView( dataStr );
} );
}
}

0 comments on commit 4dce8d9

Please sign in to comment.