File tree 10 files changed +147
-31
lines changed
10 files changed +147
-31
lines changed Original file line number Diff line number Diff line change 1
- import Showdown from "showdown"
2
-
3
- const converter = new Showdown . Converter ( { tables : true } ) ;
1
+ // import Showdown from "showdown"
2
+ // const converter = new Showdown.Converter({tables: true});
4
3
5
4
/**
6
5
* 渲染Markdown
7
6
* @param md
8
7
*/
9
8
export function renderHTML ( md : string ) {
10
- return converter . makeHtml ( md ) ;
9
+ // @ts -ignore
10
+ const lute = Lute . New ( )
11
+ // const renderers = {
12
+ // renderText: (node:any, entering:any) => {
13
+ // if (entering) {
14
+ // console.log(" render text")
15
+ // // @ts -ignore
16
+ // return [node.Text() + " via Lute", Lute.WalkContinue]
17
+ // }
18
+ // // @ts -ignore
19
+ // return ["", Lute.WalkContinue]
20
+ // },
21
+ // renderStrong: (node:any, entering:any) => {
22
+ // entering ? console.log(" start render strong") : console.log(" end render strong")
23
+ // // @ts -ignore
24
+ // return ["", Lute.WalkContinue]
25
+ // },
26
+ // renderParagraph: (node:any, entering:any) => {
27
+ // entering ? console.log(" start render paragraph") : console.log(" end render paragraph")
28
+ // // @ts -ignore
29
+ // return ["", Lute.WalkContinue]
30
+ // }
31
+ // }
32
+ // lute.SetJSRenderers({
33
+ // renderers: {
34
+ // Md2HTML: renderers
35
+ // },
36
+ // })
37
+ // return converter.makeHtml(md);
38
+ return lute . MarkdownStr ( "" , md )
11
39
}
Original file line number Diff line number Diff line change @@ -146,9 +146,9 @@ export class MetaWeblogApi {
146
146
const postStruct = ret . params . param . value || [ ]
147
147
const post = this . parsePost ( postStruct )
148
148
149
- let htmlContent = renderHTML ( post . description )
150
- htmlContent = prettyHtml ( htmlContent )
151
- post . description = htmlContent
149
+ // let htmlContent = renderHTML(post.description)
150
+ // htmlContent = prettyHtml(htmlContent)
151
+ // post.description = htmlContent
152
152
153
153
return Promise . resolve ( post )
154
154
}
Original file line number Diff line number Diff line change @@ -106,8 +106,9 @@ export class SiYuanApiAdaptor implements IApi {
106
106
const shortDesc = attrs [ "custom-desc" ] || ""
107
107
108
108
// 渲染Markdown
109
- let htmlContent = renderHTML ( md . content )
110
- htmlContent = prettyHtml ( htmlContent )
109
+ // let htmlContent = renderHTML(md.content)
110
+ // htmlContent = prettyHtml(htmlContent)
111
+ let mdContent = md . content
111
112
112
113
let title = siyuanPost . content || ""
113
114
title = removeTitleNumber ( title )
@@ -116,7 +117,7 @@ export class SiYuanApiAdaptor implements IApi {
116
117
let commonPost = new Post ( )
117
118
commonPost . postid = siyuanPost . root_id || ""
118
119
commonPost . title = title
119
- commonPost . description = htmlContent || ""
120
+ commonPost . description = mdContent || ""
120
121
commonPost . shortDesc = shortDesc || ""
121
122
commonPost . mt_keywords = attrs . tags || ""
122
123
commonPost . isPublished = isPublished
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @function unescapeHTML 还原html脚本 < > & " '
3
+ * @param a -
4
+ * 字符串
5
+ */
6
+ export const unescapeHTML = function ( a : string ) {
7
+ a = "" + a ;
8
+ return a . replace ( / \& a m p ; / g, "&" ) . replace ( / \& l t ; / g, "<" )
9
+ . replace ( / \& g t ; / g, ">" )
10
+ }
Original file line number Diff line number Diff line change 1
- import { defineNuxtConfig } from 'nuxt'
1
+ import { defineNuxtConfig } from 'nuxt/config '
2
2
import ElementPlus from 'unplugin-element-plus/vite'
3
3
4
4
// https://v3.nuxtjs.org/api/configuration/nuxt.config
5
5
export default defineNuxtConfig ( {
6
+ app : {
7
+ head : {
8
+ script : [
9
+ {
10
+ src : "/lute.min.js" ,
11
+ } ,
12
+ ] ,
13
+ } ,
14
+ } ,
15
+
16
+
6
17
// meta
7
18
meta : {
8
19
title : 'Element Plus + Nuxt 3' ,
Original file line number Diff line number Diff line change 10
10
},
11
11
"devDependencies" : {
12
12
"@pinia/nuxt" : " ^0.4.3" ,
13
- "@types/showdown" : " ^2.0.0" ,
14
13
"@types/xmlrpc" : " ^1.3.7" ,
15
14
"@unocss/nuxt" : " ^0.45.29" ,
16
15
"@vueuse/nuxt" : " ^9.3.0" ,
31
30
"element-plus" : " ^2.2.15" ,
32
31
"highlight.js" : " ^11.6.0" ,
33
32
"pinia" : " ^2.0.23" ,
34
- "showdown" : " ^2.1.0" ,
35
33
"vue" : " ^3.2.40" ,
36
34
"xmlrpc" : " ^1.3.2"
37
35
}
Original file line number Diff line number Diff line change 4
4
* @copyright Copyright 2021. All rights reserved.
5
5
*/
6
6
7
+ import { unescapeHTML } from "~/lib/strUtil" ;
8
+
7
9
/**
8
10
* Adds a copy button to highlightjs code blocks
9
11
*/
@@ -40,7 +42,7 @@ export class CopyButtonPlugin {
40
42
button . onclick = function ( ) {
41
43
if ( ! navigator . clipboard ) return ;
42
44
43
- let newText = text ;
45
+ let newText = unescapeHTML ( text ) ;
44
46
// @ts -ignore
45
47
// eslint-disable-next-line no-undef
46
48
// if (hook && typeof hook === "function") {
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import Hljs from "highlight.js";
2
2
import { CopyButtonPlugin } from "../codecopy" ;
3
3
import "../codecopy/codecopy.css" ;
4
4
import "./vs.css" ;
5
+ import { renderHTML } from "~/lib/markdownUtil" ;
6
+ import { unescapeHTML } from "~/lib/strUtil" ;
7
+ import logUtil from "~/lib/logUtil" ;
5
8
6
9
const vueHljs = { } ;
7
10
@@ -12,9 +15,25 @@ vueHljs.install = Vue => {
12
15
) ;
13
16
14
17
Vue . directive ( "highlight" , el => {
18
+ const html = renderHTML ( el . innerHTML )
19
+ // console.log(html)
20
+ el . innerHTML = html ;
21
+
15
22
const blocks = el . querySelectorAll ( "pre code" ) ;
16
23
Array . prototype . forEach . call ( blocks , Hljs . highlightBlock ) ;
17
24
25
+ // 取消转义
26
+ Array . prototype . forEach . call ( blocks , function ( bel ) {
27
+ const bclass = bel . getAttribute ( "class" ) ;
28
+ console . log ( bclass )
29
+ let newHtml = bel . innerHTML
30
+ // console.log(newHtml)
31
+
32
+ newHtml = unescapeHTML ( newHtml )
33
+ bel . innerHTML = newHtml
34
+ // console.log(newHtml)
35
+ } )
36
+
18
37
// 代码选项卡
19
38
// 代码块
20
39
const codeGroups = el . querySelectorAll ( "code-group" ) ;
Original file line number Diff line number Diff line change 759
759
dependencies :
760
760
" @types/node" " *"
761
761
762
- " @types/showdown@^2.0.0 " :
763
- version "2.0.0"
764
- resolved "https://registry.npmmirror.com/@types/showdown/-/showdown-2.0.0.tgz#3e800eca8573848cac4e5555f4377ba3a0e7b1f2"
765
- integrity sha512-70xBJoLv+oXjB5PhtA8vo7erjLDp9/qqI63SRHm4REKrwuPOLs8HhXwlZJBJaB4kC18cCZ1UUZ6Fb/PLFW4TCA==
766
-
767
762
" @types/web-bluetooth@^0.0.15 " :
768
763
version "0.0.15"
769
764
resolved "https://registry.npmmirror.com/@types/web-bluetooth/-/web-bluetooth-0.0.15.tgz#d60330046a6ed8a13b4a53df3813c44942ebdf72"
@@ -1636,11 +1631,6 @@ commander@^8.0.0:
1636
1631
resolved "https://registry.npmmirror.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
1637
1632
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
1638
1633
1639
- commander@^9.0.0 :
1640
- version "9.4.0"
1641
- resolved "https://registry.npmmirror.com/commander/-/commander-9.4.0.tgz#bc4a40918fefe52e22450c111ecd6b7acce6f11c"
1642
- integrity sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==
1643
-
1644
1634
commondir@^1.0.1 :
1645
1635
version "1.0.1"
1646
1636
resolved "https://registry.npmmirror.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
@@ -4180,13 +4170,6 @@ shebang-regex@^3.0.0:
4180
4170
resolved "https://registry.npmmirror.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
4181
4171
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
4182
4172
4183
- showdown@^2.1.0 :
4184
- version "2.1.0"
4185
- resolved "https://registry.npmmirror.com/showdown/-/showdown-2.1.0.tgz#1251f5ed8f773f0c0c7bfc8e6fd23581f9e545c5"
4186
- integrity sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==
4187
- dependencies :
4188
- commander "^9.0.0"
4189
-
4190
4173
signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3 :
4191
4174
version "3.0.7"
4192
4175
resolved "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
You can’t perform that action at this time.
0 commit comments