From 91921bda9600b4985e3b1523de97f9d80aaf930a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Fri, 9 Oct 2020 17:29:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AEmarkdown=E9=A2=84?= =?UTF-8?q?=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/view/article/article.component.html | 2 +- src/app/view/article/article.component.ts | 35 ++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/app/view/article/article.component.html b/src/app/view/article/article.component.html index 648b742..4486c50 100644 --- a/src/app/view/article/article.component.html +++ b/src/app/view/article/article.component.html @@ -1,6 +1,6 @@
-
+
over diff --git a/src/app/view/article/article.component.ts b/src/app/view/article/article.component.ts index 0adb93c..a1d4316 100644 --- a/src/app/view/article/article.component.ts +++ b/src/app/view/article/article.component.ts @@ -1,15 +1,14 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {ApiService} from '../../api/api.service'; import {Article} from '../../class/Article'; import {Title} from '@angular/platform-browser'; import {User} from '../../class/User'; -import {CommentReq} from '../../class/Comment'; +import {Comment, CommentReq} from '../../class/Comment'; import {PageList} from '../../class/HttpReqAndResp'; -import {Comment} from '../../class/Comment'; import {GlobalUserService} from '../../services/global-user.service'; +import VditorPreview from 'vditor/dist/method.min' -declare var editormd; declare var $; @Component({ @@ -40,6 +39,9 @@ export class ArticleComponent implements OnInit { avatarImgUrl: string; pid: number; content: string; + @ViewChild('divElement') divElement: ElementRef; + + // private vditor: Vditor; ngOnInit() { this.toArticle(this.articleId); @@ -55,17 +57,20 @@ export class ArticleComponent implements OnInit { } parseMd(md: string) { - editormd.markdownToHTML('article-content', { - markdown: this.article.mdContent, - htmlDecode: 'style,script,iframe', // you can filter tags decode - toc: false, - tocm: false, // Using [TOCM] - // tocContainer: '#article-slider', // 自定义 ToC 容器层 - // tocDropdown: true, - emoji: true, - taskList: true, - flowChart: true, // 默认不解析 - }); + const option: IPreviewOptions = { + anchor: 2, + hljs: { + lineNumber: true + }, + markdown: { + autoSpace: true, + fixTermTypo: true, + chinesePunct: true, + toc: true, + linkBase: location.href + } + }; + VditorPreview.preview(this.divElement.nativeElement, md); } toArticle(id: number) {