From 72caf1bffd891758fe80ccbcc270194a4d454667 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Lavigne Date: Thu, 5 Sep 2024 23:44:48 +0900 Subject: [PATCH] WIP: selective heading levels --- example/index.html | 6 +++++- src/js/easymde.js | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/example/index.html b/example/index.html index ce03794..f464984 100644 --- a/example/index.html +++ b/example/index.html @@ -13,7 +13,11 @@ diff --git a/src/js/easymde.js b/src/js/easymde.js index c038d1c..f39c5e7 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -1822,7 +1822,15 @@ function EasyMDE(options) { options.parsingConfig = extend({ highlightFormatting: true, // needed for toggleCodeBlock to detect types of code }, options.parsingConfig || {}); - + if ( options.parsingConfig.headingLevels ) { + var headingLevels = []; + for ( var l = 0, requestedLevels = options.parsingConfig.headingLevels; l < requestedLevels.length; l++ ) { + if ( ! isNaN( requestedLevels[ l ] ) && headingLevels.indexOf( requestedLevels[ l ] ) === -1 ) { + headingLevels[ l ] = parseInt( requestedLevels[ l ], 10 ); + } + } + options.parsingConfig.headingLevels = headingLevels; + } // Merging the insertTexts, with the given options options.insertTexts = extend({}, insertTexts, options.insertTexts || {}); @@ -2190,6 +2198,12 @@ EasyMDE.prototype.render = function (el) { cm.save(); }); } + if (options.parsingConfig.headingLevels) { + var cm = this.codemirror; + cm.on('beforeChange', function (cm, obj) { + console.log( obj ); + }); + } this.gui = {};