2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-08-28 11:32:45 -06:00

WIP: selective heading levels

This commit is contained in:
Pierre-Henri Lavigne 2024-09-05 23:44:48 +09:00
parent a6b121f2e6
commit 72caf1bffd
No known key found for this signature in database
GPG Key ID: E2D1C9E2BBD3007D
2 changed files with 20 additions and 2 deletions

View File

@ -13,7 +13,11 @@
<body>
<textarea></textarea>
<script>
const easyMDE = new EasyMDE();
const easyMDE = new EasyMDE({
parsingConfig: {
headingLevels: [ 5, 2, 3, 4, 5 ]
}
});
</script>
</body>

View File

@ -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 = {};