In this package we will use a few libraries and tools to make a more convenient "all in one" WYSIWYG Markdown Editor with preview. All of that with a simple Angular Component. This can be useful for online documentation and many other reasons (docs, blog, ...).
AngularJS (previous version)
If you still have AngularJS project, you can still get the older version
1.1.5 from NPM, however please note that support has stopped and only the new version
2.x will be supported.
Here is the list of dependencies, which are required
- Bootstrap-Markdown (editor) itself
- jQuery (required for Bootstrap-Markdown editor)
- Bootstrap 3.x.
- If anyone needs
Bootstrap 4support and has time to add the necessary code, PR (Pull Request) are certainly welcome.
- If anyone needs
Nice to have Dependencies
It's a "nice to have" but not a deep dependencies, which is the ngx-markdown lib. It is used in the demo of this lib, but technically you could plug any other lib you wish for dealing with the markdown preview.
npm install angular-markdown-editor# or with Yarnyarn add angular-markdown-editor
You need to add CSS Styles for the Bootstrap, Markdown Editor and Font-Awesome (the latter is optional).
ngx-markdown and/or Prism.js
For example, below we are adding the highlight for
You can pass the following input attribute:
|textareaId||string||yes||id of the textarea DOM element used by the lib|
|rows||number||no||number of rows for the textarea, defaults to 10|
|options||mixed||no||markdown Editor Options to pass to the element|
|locale||EditorLocale||no||locale set that has a language and dictionary that can be added as an alternative language. Can be 1 or more dictionaries|
The library comes with it's own Global Editor Options, these propertoes can be overriden at any by the
options attribute. Click to see the Global Options defined.
You can hook to any of the Bootstrap Markdown Editor Events through 2 ways, just choose the one you prefer:
1. Dispatch of Custom Event
Each of the events are available in the View from a Custom Event as
(onX)="doSomething()", for example:
You can also pass the Event returned by the Editor via
2. Editor Option Callbacks
The second way is to use the callback directly when defining the Editor Options.
List of Event Hooks
API - Editor Methods
The editor API is quite dense and I will not list the entire set of methods, but you can see the entire list from the Editor Method Interface.
To call any of the Editor Methods, you will have to first get a reference to the Editor's instance which you can get from the
Get the Editor's instance through the
onShow, via the Custom Event (from the View) or Editor Option callback (just choose the one you prefer). Below shows how to get it through the latter option.
Show Full Screen
Preview Button (need a Parser)
For the "Preview" button to work, you will need to provide a
parser to the Editor Options. This lib has no deep dependencies to any Markdown Parser (you could use
marked.js or any other parser). But assuming we are using
ngx-markdown, we can add the parser this way:
Additional Editor Buttons
I really thought that some buttons were missing to go a great job (
Strikethrough & Table). So I added them directly in the Global Options. If you want to add your own, then just look at how it was done in the Global Options and read the section
additionalButtons of Bootstrap Markdown website.
You can add a locale to the editor but passing a
locale object (and bind it in the View) which contain a
language and the dictionary of words used by the editor. The entire list of words can be seen in the example below. So for example, if we want to add French locale, we will do the following (you can see demo code):
Show Full Screen
Note I could not find a way to change the language dynamically, so it seems that we would have to destroy the component and re-create it for switching the language/locale.
Use it, like it?
You like and use this great library
Angular-Markdown-Editor? You can always upvote ⭐️ and/or contribute :)
Like my work?
If you like my work, you can also support me with caffeine 😄 Buy Me a Coffee