From a602d3b826f31ef72eb2de7328b15c062a83b6b5 Mon Sep 17 00:00:00 2001 From: Jeroen akkerman Date: Fri, 21 Feb 2025 22:31:16 +0100 Subject: [PATCH] Add support for `marked` extensions Fixes #514 Fixes #611 --- CHANGELOG.md | 8 ++++++- cypress/e2e/5-marked-options/index.html | 24 +++++++++++++++++++ .../e2e/5-marked-options/marked-options.cy.js | 18 ++++++++++++++ src/js/easymde.js | 2 +- types/easymde.d.ts | 2 +- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/5-marked-options/index.html create mode 100644 cypress/e2e/5-marked-options/marked-options.cy.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f1eaa0b..c487c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to EasyMDE will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [Unreleased] +### Added +- Support for `marked` extensions (Thanks to [@codingjoe], [#611], [#514]). + ## [2.19.0] - 2025-02-18 ### Added - `updateStatusBar` type to typescript definitions (Thanks to [@borodean], [#519]). @@ -268,6 +271,8 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown - Cursor not always showing in "text" mode over the edit field +[#611]: https://github.com/Ionaru/easy-markdown-editor/issues/611 +[#514]: https://github.com/Ionaru/easy-markdown-editor/issues/514 [#493]: https://github.com/Ionaru/easy-markdown-editor/issues/493 [#478]: https://github.com/Ionaru/easy-markdown-editor/issues/478 [#399]: https://github.com/Ionaru/easy-markdown-editor/issues/399 @@ -438,6 +443,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown [@robinvandernoord]: https://github.com/robinvandernoord [@p1gp1g]: https://github.com/p1gp1g [@mayraamaral]: https://github.com/mayraamaral +[@codingjoe]: https://github.com/codingjoe [Unreleased]: https://github.com/Ionaru/easy-markdown-editor/compare/2.19.0...HEAD diff --git a/cypress/e2e/5-marked-options/index.html b/cypress/e2e/5-marked-options/index.html new file mode 100644 index 0000000..5dc4d3d --- /dev/null +++ b/cypress/e2e/5-marked-options/index.html @@ -0,0 +1,24 @@ + + + + + + Default + + + + + + + + + + diff --git a/cypress/e2e/5-marked-options/marked-options.cy.js b/cypress/e2e/5-marked-options/marked-options.cy.js new file mode 100644 index 0000000..935b86a --- /dev/null +++ b/cypress/e2e/5-marked-options/marked-options.cy.js @@ -0,0 +1,18 @@ +/// + +describe('Marked options', () => { + beforeEach(() => { + cy.visit(__dirname + '/index.html'); + }); + + it('must apply the markedOptions to the markdown parser', () => { + cy.get('.EasyMDEContainer').should('be.visible'); + cy.get('#textarea').should('not.be.visible'); + + cy.get('.EasyMDEContainer .CodeMirror').type('# Title{enter}'); + + cy.previewOn(); + + cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Title

'); + }); +}); diff --git a/src/js/easymde.js b/src/js/easymde.js index 449c76f..a4c3059 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2045,7 +2045,7 @@ EasyMDE.prototype.markdown = function (text) { } // Set options - marked.setOptions(markedOptions); + marked.use(markedOptions); // Convert the markdown to HTML var htmlText = marked.parse(text); diff --git a/types/easymde.d.ts b/types/easymde.d.ts index 351939a..502b29d 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -101,7 +101,7 @@ declare namespace EasyMDE { interface RenderingOptions { codeSyntaxHighlighting?: boolean; hljs?: any; - markedOptions?: marked.MarkedOptions; + markedOptions?: marked.MarkedExtension; sanitizerFunction?: (html: string) => string; singleLineBreaks?: boolean; }