From d3e357b8260a53c9db80370f48d7e916fda8b18d Mon Sep 17 00:00:00 2001 From: faisal Date: Thu, 1 Sep 2022 11:03:12 -0500 Subject: [PATCH] added extractYaml to option ts and yaml-fm default --- src/js/easymde.js | 10 ++++++---- types/easymde.d.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index 6ac8ff6..2b68fb9 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2011,8 +2011,8 @@ EasyMDE.prototype.updateStatusBar = function (itemName, content) { */ EasyMDE.prototype.markdown = function (text) { if (marked) { - // When extractYaml is present we remove it from preview - if (typeof this.options.extractYaml === 'function' && text.indexOf('---') === 0) { + // remove yaml-frontmatter from preview + if (text.indexOf('---') === 0) { var yaml = text.substring(3); var closeIdx = yaml.indexOf('---'); if (closeIdx === -1) { @@ -2025,7 +2025,9 @@ EasyMDE.prototype.markdown = function (text) { } else { text = ''; } - this.options.extractYaml(yaml); + if (this.options.extractYaml) { + this.options.extractYaml(yaml); + } } // Initialize var markedOptions; @@ -2132,7 +2134,7 @@ EasyMDE.prototype.render = function (el) { document.addEventListener('keydown', this.documentOnKeyDown, false); var mode, backdrop; - var defaultMode = typeof options.extractYaml === 'function' ? 'yaml-frontmatter' : 'gfm'; + var defaultMode = 'yaml-frontmatter'; // CodeMirror overlay mode if (options.overlayMode) { CodeMirror.defineMode('overlay-mode', function (config) { diff --git a/types/easymde.d.ts b/types/easymde.d.ts index decd4ca..cb16b53 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -182,6 +182,7 @@ declare namespace EasyMDE { autoRefresh?: boolean | { delay: number; }; blockStyles?: BlockStyleOptions; element?: HTMLElement; + extractYaml?: (yaml: string) => void; forceSync?: boolean; hideIcons?: ReadonlyArray; indentWithTabs?: boolean;