update
This commit is contained in:
1 parent
31dd2b0049
commit
7039b10df2
32 files changed
+415
-192
No files matched your search
@@ -2,10 +2,11 @@ import crypto from 'crypto'
|
||||
|
||||
import scopeCss from '@patarapolw/scope-css'
|
||||
import cheerio from 'cheerio'
|
||||
import jieba from 'nodejieba'
|
||||
import showdown from 'showdown'
|
||||
|
||||
export class MakeHTML {
|
||||
$ = cheerio.load('');
|
||||
$ = cheerio.load('')
|
||||
|
||||
mdConverter = new showdown.Converter({
|
||||
noHeaderId: true,
|
||||
@@ -20,10 +21,10 @@ export class MakeHTML {
|
||||
backslashEscapesHTMLTags: true,
|
||||
emoji: true,
|
||||
underline: true,
|
||||
metadata: true
|
||||
});
|
||||
metadata: true,
|
||||
})
|
||||
|
||||
constructor (private slug: string) {
|
||||
constructor(private slug: string) {
|
||||
/**
|
||||
* ! For some reasons default underscore italic fails to render...
|
||||
*/
|
||||
@@ -31,13 +32,13 @@ export class MakeHTML {
|
||||
{
|
||||
type: 'lang',
|
||||
regex: /([^\\])_{1}(.*?[^\\])_{1}/g,
|
||||
replace: '$1<i>$2</i>'
|
||||
replace: '$1<i>$2</i>',
|
||||
},
|
||||
'underscore-italic'
|
||||
)
|
||||
}
|
||||
|
||||
parse (md: string): string {
|
||||
parse(md: string): string {
|
||||
const id =
|
||||
'md-' +
|
||||
crypto
|
||||
@@ -51,17 +52,20 @@ export class MakeHTML {
|
||||
$div.html(this.mdConverter.makeHtml(md))
|
||||
$div.find('style').each((_, el) => {
|
||||
const $el = this.$(el)
|
||||
$el.html(scopeCss($el.html(), `#${id}`))
|
||||
const html = $el.html() || ''
|
||||
if (html.trim()) {
|
||||
$el.html(scopeCss(html, `#${id}`))
|
||||
}
|
||||
})
|
||||
|
||||
return this.$('<div>').append($div).html()
|
||||
return this.$('<div>').append($div).html() || ''
|
||||
}
|
||||
|
||||
clean (md: string): string {
|
||||
clean(md: string): string {
|
||||
const $div = this.$('<div>')
|
||||
$div.html(this.mdConverter.makeHtml(md))
|
||||
$div.remove('style')
|
||||
|
||||
return $div.html()
|
||||
return jieba.cutForSearch($div.html() || '').join(' ')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user