SimpleChatTCRV:Markdown:BlockQuote support
This commit is contained in:
parent
1d26453b52
commit
edba012d80
|
|
@ -1499,7 +1499,7 @@ class MultiChatUI {
|
||||||
if (content.length > 0) {
|
if (content.length > 0) {
|
||||||
if ((name == "content") && (this.simpleChats[chatId].cfg.chatProps.bMarkdown)) {
|
if ((name == "content") && (this.simpleChats[chatId].cfg.chatProps.bMarkdown)) {
|
||||||
entry = document.createElement('div')
|
entry = document.createElement('div')
|
||||||
let md = new mMD.MarkDown()
|
let md = new mMD.MarkDown(this.simpleChats[chatId].cfg.chatProps.bMarkdownHtmlSanitize)
|
||||||
md.process(content)
|
md.process(content)
|
||||||
entry.innerHTML = md.html
|
entry.innerHTML = md.html
|
||||||
secContents.appendChild(entry)
|
secContents.appendChild(entry)
|
||||||
|
|
@ -2106,6 +2106,7 @@ export class Config {
|
||||||
*/
|
*/
|
||||||
iRecentUserMsgCnt: 5,
|
iRecentUserMsgCnt: 5,
|
||||||
bMarkdown: true,
|
bMarkdown: true,
|
||||||
|
bMarkdownHtmlSanitize: false,
|
||||||
bCompletionFreshChatAlways: true,
|
bCompletionFreshChatAlways: true,
|
||||||
bCompletionInsertStandardRolePrefix: false,
|
bCompletionInsertStandardRolePrefix: false,
|
||||||
bTrimGarbage: true,
|
bTrimGarbage: true,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@
|
||||||
*/
|
*/
|
||||||
export class MarkDown {
|
export class MarkDown {
|
||||||
|
|
||||||
constructor() {
|
/**
|
||||||
|
* Markdown parse and convert to html.
|
||||||
|
* @param {boolean} bHtmlSanitize
|
||||||
|
*/
|
||||||
|
constructor(bHtmlSanitize) {
|
||||||
|
this.bHtmlSanitize = bHtmlSanitize
|
||||||
this.in = {
|
this.in = {
|
||||||
preFenced: "",
|
preFenced: "",
|
||||||
table: {
|
table: {
|
||||||
|
|
@ -30,7 +35,9 @@ export class MarkDown {
|
||||||
},
|
},
|
||||||
/** @type {Object<string, number>} */
|
/** @type {Object<string, number>} */
|
||||||
empty: {
|
empty: {
|
||||||
}
|
},
|
||||||
|
/** @type {string} */
|
||||||
|
blockQuote: "",
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @type {Array<*>}
|
* @type {Array<*>}
|
||||||
|
|
@ -235,14 +242,50 @@ export class MarkDown {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unwind_blockquote() {
|
||||||
|
for(let i=0; i<this.in.blockQuote.length; i++) {
|
||||||
|
this.html += `</blockquote>\n`
|
||||||
|
}
|
||||||
|
this.in.blockQuote = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle blockquote block one line at a time.
|
||||||
|
* This expects all lines in the block quote to have the marker at the begining.
|
||||||
|
*
|
||||||
|
* @param {string} line
|
||||||
|
* @param {string} startTok
|
||||||
|
*/
|
||||||
|
process_blockquote(line, startTok) {
|
||||||
|
if (!line.startsWith(">")) {
|
||||||
|
this.unwind_blockquote()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (startTok.match(/^>+$/) == null) {
|
||||||
|
this.unwind_blockquote()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
this.unwind_list()
|
||||||
|
if (startTok.length > this.in.blockQuote.length) {
|
||||||
|
this.html += `<blockquote>\n`
|
||||||
|
} else if (startTok.length < this.in.blockQuote.length) {
|
||||||
|
this.html += `</blockquote>\n`
|
||||||
|
}
|
||||||
|
this.in.blockQuote = startTok
|
||||||
|
this.html += `<p>${line}</p>`
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a line from markdown content
|
* Process a line from markdown content
|
||||||
* @param {string} line
|
* @param {string} line
|
||||||
*/
|
*/
|
||||||
process_line(line) {
|
process_line(line) {
|
||||||
|
if (this.bHtmlSanitize) {
|
||||||
let elSanitize = document.createElement('div')
|
let elSanitize = document.createElement('div')
|
||||||
elSanitize.textContent = line
|
elSanitize.textContent = line
|
||||||
line = elSanitize.innerHTML
|
line = elSanitize.innerHTML
|
||||||
|
}
|
||||||
let lineA = line.split(' ')
|
let lineA = line.split(' ')
|
||||||
if (this.in.preFenced.length > 0) {
|
if (this.in.preFenced.length > 0) {
|
||||||
if (line == this.in.preFenced) {
|
if (line == this.in.preFenced) {
|
||||||
|
|
@ -278,6 +321,9 @@ export class MarkDown {
|
||||||
this.html += `<pre class="${matchPreFenced[2]}">\n`
|
this.html += `<pre class="${matchPreFenced[2]}">\n`
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (this.process_blockquote(line, lineA[0])) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (this.process_list(line)) {
|
if (this.process_list(line)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue