Skip to content

Commit 398c818

Browse files
committed
Custom render blockquote
1 parent c0c013b commit 398c818

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/page.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,29 @@ $('span.abc.raw').removeClass('raw')
161161
console.warn(err)
162162
}
163163
})
164+
165+
166+
// regex for extra tags
167+
const spaceregex = /\s*/
168+
const notinhtmltagregex = /(?![^<]*>|[^<>]*<\/)/
169+
let coloregex = /\[color=([#|(|)|\s|,|\w]*?)\]/
170+
coloregex = new RegExp(coloregex.source + notinhtmltagregex.source, 'g')
171+
let nameregex = /\[name=(.*?)\]/
172+
let timeregex = /\[time=([:|,|+|-|(|)|\s|\w]*?)\]/
173+
const nameandtimeregex = new RegExp(nameregex.source + spaceregex.source + timeregex.source + notinhtmltagregex.source, 'g')
174+
nameregex = new RegExp(nameregex.source + notinhtmltagregex.source, 'g')
175+
timeregex = new RegExp(timeregex.source + notinhtmltagregex.source, 'g')
176+
177+
function replaceExtraTags (html) {
178+
html = html.replace(coloregex, '<span class="color" data-color="$1"></span>')
179+
html = html.replace(nameandtimeregex, '<small><i class="fa fa-user"></i> $1 <i class="fa fa-clock-o"></i> $2</small>')
180+
html = html.replace(nameregex, '<small><i class="fa fa-user"></i> $1</small>')
181+
html = html.replace(timeregex, '<small><i class="fa fa-clock-o"></i> $1</small>')
182+
return html
183+
}
184+
185+
186+
$('blockquote').removeClass('.raw').each(function (_, elem) {
187+
const p = $(elem).find('p')
188+
p[0].innerHTML = replaceExtraTags(p[0].innerHTML);
189+
})

0 commit comments

Comments
 (0)