3 Star 16 Fork 4

imlxp / ngx-editor.md-markdown

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

说明

This project was generated with Angular CLI version 1.5.0.

最近用angular做后端,需要用到markdown编辑器,网上找了许多,有html的,但是捣鼓了半天发现无法使用NgModel绑定;也有angular写的模块,但是集成到项目后发现不是很漂亮。

后来无意间在博客园中看到了一位网友推荐的markdown,打开后发现完美!漂亮!和我一直喜欢的CSDN的Markdown功能一样,后来才知道CSDN的也是用的该用例。那就是Editor.md编辑器。地址:https://pandao.github.io/editor.md/

大概就是这个样子:

这就是整体效果

指令结构:

这里写图片描述

详细代码自行查看

使用

找好了要使用的Markdown之后,开始集成到Angular中。于是就写了一个指令。并且支持NgModel

  • 使用npm或者yarn安装jquery

    npm install jquery
    或者
    yarn add jquery
  • 下载editor.md的的文件,并放置到assets文件夹中

  • .angular-cli.json中配置editor.mdcssjs

    "styles": [
         "assets/editor.md/css/editormd.css",
         "styles.css"
       ],
       "scripts": [
         "../node_modules/jquery/dist/jquery.js",
         "assets/editor.md/editormd.min.js"
       ]
  • textarea需要用到FromsModule记得添加,另外在module中添加EditorMdDirective指令

  • 引入

    Html

    <div id="md" appEditorMd [editormdConfig]="conf" (onEditorChange)="syncModel($event)">
       <textarea style="display: block;" [(ngModel)]="markdown"></textarea>
    </div>

    Component

    conf = new EditorConfig();
    markdown = '测试语句';
    
    // 同步属性内容
    syncModel(str): void {
         this.markdown = str;
    }

以下是效果图:

这里写图片描述

详细配置可参考官方Editor.md

The MIT License (MIT) Copyright (c) 2018 imlxp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个Angular指令。集成editor.md的markdown编辑器到Angular中。支持NgModel双向绑定。editor.md地址: 展开 收起
TypeScript 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/imlxp/ngx-editor.md-markdown.git
git@gitee.com:imlxp/ngx-editor.md-markdown.git
imlxp
ngx-editor.md-markdown
ngx-editor.md-markdown
master

搜索帮助