All Projects → ghiscoding → Angular Markdown Editor

ghiscoding / Angular Markdown Editor

Licence: mit
Angular Markdown Editor. All-in-one Markdown Editor and Preview

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular Markdown Editor

Codebe
CodeBe(码币)是一个是使用angular2整合各种插件的项目,包括(layer,bootstrap-table,markdown编辑器,highcharts,ckeditor,高德地图,fullcalendar 等等)。如果你有什么想要集成的插件,请告诉我,我来加进去。(请给我加个星,谢谢。)
Stars: ✭ 307 (+189.62%)
Mutual labels:  markdown, angularjs
Angular Gantt
Gantt chart component for AngularJS
Stars: ✭ 1,407 (+1227.36%)
Mutual labels:  angularjs
Coreui Angularjs
CoreUI AngularJS is free AngularJS admin template based on Bootstrap 4
Stars: ✭ 101 (-4.72%)
Mutual labels:  angularjs
Markor
Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
Stars: ✭ 1,394 (+1215.09%)
Mutual labels:  markdown
Vim Marked
Open the current Markdown buffer in Marked.app
Stars: ✭ 101 (-4.72%)
Mutual labels:  markdown
Meanstackjs
Mean Stack JS - MongoDB, Express JS, Angular JS & Node JS
Stars: ✭ 104 (-1.89%)
Mutual labels:  angularjs
Blog
博客文章 markdown 源文件
Stars: ✭ 100 (-5.66%)
Mutual labels:  markdown
Spaceboard
Pinterest for markdown notes. Made with React, TypeScript, and Next.js.
Stars: ✭ 106 (+0%)
Mutual labels:  markdown
Oscp Exam Report Template Markdown
📙 Markdown Templates for Offensive Security OSCP, OSWE, OSCE, OSEE, OSWP exam report
Stars: ✭ 2,066 (+1849.06%)
Mutual labels:  markdown
Docs
The Urbit docs
Stars: ✭ 104 (-1.89%)
Mutual labels:  markdown
Viki
A simple Wiki page in Markdown from notebook of VNote.
Stars: ✭ 103 (-2.83%)
Mutual labels:  markdown
Markdown Online Editor
📝基于 Vue、Vditor,所构建的在线 Markdown 编辑器,支持流程图、甘特图、时序图、任务列表、HTML 自动转换为 Markdown 等功能;🎉新增「所见即所得」编辑模式。
Stars: ✭ 1,373 (+1195.28%)
Mutual labels:  markdown
Md Roam
Use Org-roam with markdown files by adding Md-roam as a plug-in. Mix and match org and markdown files.
Stars: ✭ 104 (-1.89%)
Mutual labels:  markdown
Catfish
A typora markdown theme
Stars: ✭ 101 (-4.72%)
Mutual labels:  markdown
Vue Cli Multipage Bootstrap
vue-cli-multipage-bootstrap demo with vue2+vue-router+vuex+bootstrap+markdown for learning vue2.0
Stars: ✭ 105 (-0.94%)
Mutual labels:  markdown
Gatsby Starter Portfolio Minimal
A Gatsby Starter to create a clean one-page portfolio with Markdown content.
Stars: ✭ 100 (-5.66%)
Mutual labels:  markdown
Vscode Mdx Preview
MDX Preview for Visual Studio Code
Stars: ✭ 103 (-2.83%)
Mutual labels:  markdown
Retext
ReText: Simple but powerful editor for Markdown and reStructuredText
Stars: ✭ 1,500 (+1315.09%)
Mutual labels:  markdown
Ipfs.ink
PROJECT HAS BEEN SHUTDOWN - Publish and render markdown essays to and from ipfs
Stars: ✭ 106 (+0%)
Mutual labels:  markdown
Mikidown
A note taking application, featuring markdown syntax.
Stars: ✭ 105 (-0.94%)
Mutual labels:  markdown

Angular-Markdown-Editor

License: MIT TypeScript npm version NPM downloads

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.

Dependencies

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 4 support and has time to add the necessary code, PR (Pull Request) are certainly welcome.

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.

Demo page

Installation

NPM Package

Angular-Markdown-Editor on NPM

Install through NPM or Yarn

npm install angular-markdown-editor

# or with Yarn
yarn add angular-markdown-editor

Modify the angular.json file

You need to add CSS Styles for the Bootstrap, Markdown Editor and Font-Awesome (the latter is optional). Also make sure to include the proper 3rd party javascript libraries in your scripts as shown below.

"styles": [
    "../node_modules/bootstrap/dist/css/bootstrap.css",
    "../node_modules/bootstrap-markdown/css/bootstrap-markdown.min.css",
    "../node_modules/font-awesome/css/font-awesome.css"
],
"scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/bootstrap-markdown/js/bootstrap-markdown.js"
],

When using ngx-markdown and/or Prism.js

Prism.js uses separate javascript file for each language, so you'll need to add them yourself. For example, below we are adding the highlight for C#, JavaScript and TypeScript:

"styles": [
    "../node_modules/prismjs/themes/prism.css"
],
"scripts": [
    "../node_modules/prismjs/prism.js",
    "../node_modules/prismjs/components/prism-css.min.js",
    "../node_modules/prismjs/components/prism-javascript.min.js",
    "../node_modules/prismjs/components/prism-typescript.min.js"
],

Import Module

import { AngularMarkdownEditorModule } from 'angular-markdown-editor';

@NgModule({
  declarations: [],
  imports: [AngularMarkdownEditorModule]

  // or pre-define global configuration using the forRoot
  // imports: [AngularMarkdownEditorModule.forRoot({ iconlibrary: 'fa' })]
});

Input attributes

You can pass the following input attribute:

attribute type required comments
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

Global Options

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.

Event Hooks

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:

<angular-markdown-editor
  textareaId="editor1" rows="12"
  name="markdownText" [(ngModel)]="markdownText"
  (onFullscreenExit)="hidePreview()">
</angular-markdown-editor>
export class MyComponent {
  hidePreview() { console.log(e.getContent()); }
}

You can also pass the Event returned by the Editor via $event.detail.eventData

<angular-markdown-editor
  textareaId="editor1" rows="12"
  name="markdownText" [(ngModel)]="markdownText"
  (onChange)="onChange($event.detail.eventData)">
</angular-markdown-editor>
export class MyComponent {
  ngOnInit() {
    onChange(e) { console.log(e.getContent()); }
  }
}

2. Editor Option Callbacks

The second way is to use the callback directly when defining the Editor Options.

<angular-markdown-editor
  textareaId="editor1" rows="12"
  name="markdownText" [(ngModel)]="markdownText"
  [options]="editorOptions">
</angular-markdown-editor>
import { EditorOption } from 'angular-markdown-editor';
export class MyComponent {
  ngOnInit() {
    this.editorOptions: EditorOption = {
      iconlibrary: 'fa',
      onChange: (e) => console.log(e.getContent()),
      onFullscreenExit: () => this.hidePreview()
    };
  }
}

List of Event Hooks

  • onPreview
  • onPreviewEnd
  • onSave
  • onBlur
  • onFocus
  • onFullscreen
  • onFullscreenExit
  • onChange
  • onSelect
  • onShow

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 onShow callback.

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.

View
<button (click)="showFullScreen()">Show Full Screen</button>
<angular-markdown-editor
  textareaId="editor1" rows="12"
  name="markdownText" [(ngModel)]="markdownText"
  [options]="editorOptions">
</angular-markdown-editor>
Component
import { EditorInstance, EditorOption } from 'angular-markdown-editor';
export class MyComponent {
  bsEditorInstance: EditorInstance;

  ngOnInit() {
    this.editorOptions = {
      iconlibrary: 'fa',
      onShow: (e) => this.bsEditorInstance = e
    };
  }

  showFullScreen() {
    this.bsEditorInstance.setFullscreen(true);
  }
}

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:

Component
import { MarkdownService } from 'ngx-markdown';

export class TestComponent implements OnInit {
  constructor(private markdownService: MarkdownService) {}

  ngOnInit() {
    this.editorOptions = {
      parser: (val) => this.markdownService.compile(val.trim())
    };
  }
}

Security - Dealing with Cross Site Scripting (XSS)

If you want to use this package for any type of users, you should consider sanatizing your data for Cross Site Scripting (XSS) attack. A good package to use for sanitizing is DOMPurify and you should sanitize your data when calling the parser as shown below. Also if you have any Markdown Preview, remember to sanitize them as well probably via the form input or control.

this.editorOptions = {  
  parser: (val: string) => {
    const sanitizedText = DOMPurify.sanitize(val.trim());
    this.markdownService.compile(sanitizedText);
  }
};

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.

Adding Locale

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):

View
<button (click)="showFullScreen()">Show Full Screen</button>
<angular-markdown-editor
  textareaId="editor1" rows="12"
  name="markdownText" [(ngModel)]="markdownText"
  [locale]="locale"
  [options]="editorOptions">
</angular-markdown-editor>
Component
import { EditorInstance, EditorLocale, EditorOption } from 'angular-markdown-editor';
export class MyComponent {
  locale: EditorLocale = {
    language: 'fr',
    dictionary: {
      'Bold': 'Gras',
      'Italic': 'Italique',
      'Heading': 'Titre',
      'URL/Link': 'Insérer un lien HTTP',
      'Image': 'Insérer une image',
      'List': 'Liste à puces',
      'Ordered List': 'Liste ordonnée',
      'Unordered List': 'Liste non-ordonnée',
      'Code': 'Code',
      'Quote': 'Citation',
      'Preview': 'Prévisualiser',
      'Strikethrough': 'Caractères barrés',
      'Table': 'Table',
      'strong text': 'texte important',
      'emphasized text': 'texte souligné',
      'heading text': 'texte d\'entête',
      'enter link description here': 'entrez la description du lien ici',
      'Insert Hyperlink': 'Insérez le lien hypertexte',
      'enter image description here': 'entrez la description de l\'image ici',
      'Insert Image Hyperlink': 'Insérez le lien hypertexte de l\'image',
      'enter image title here': 'entrez le titre de l\'image ici',
      'list text here': 'texte à puce ici'
    }
  };

  // if you want to pass multiple locales, just pass it as an array
  /*
  locale: EditorLocale[] = [
    { language: 'fr', dictionary: { 'Bold': 'Gras', ...
    { language: 'en', dictionary: { 'Bold': 'Bold', ...
  ];
  */

  ngOnInit() {
    this.editorOptions = {
      language: 'fr', // also set the language option to French
      onShow: (e) => this.bsEditorInstance = e
    };
  }
}

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.

License

MIT License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].