mdparse: add toggle for viewing source chars

This commit is contained in:
Siddharth Singh 2023-04-25 22:06:30 +05:30
parent 1a32d7a77e
commit 34428da5c7
4 changed files with 33 additions and 11 deletions

View file

@ -59,7 +59,7 @@ export default defineComponent({
};
const toParse = "".concat(...generateStandIns(parsed));
return rehydrate(parseMd(toParse), htmls);
return rehydrate(parseMd(toParse, this.store.state.settings.renderMdSrc), htmls);
}
return parsed;

View file

@ -17,12 +17,6 @@
Include seconds in timestamp
</label>
</div>
<div>
<label class="opt">
<input :checked="store.state.settings.parseMd" type="checkbox" name="parseMd" />
Render inline markdown in messages
</label>
</div>
<div>
<label class="opt">
<input
@ -33,6 +27,27 @@
Use 12-hour timestamps
</label>
</div>
<h3>Markdown</h3>
<div>
<label class="opt">
<input :checked="store.state.settings.parseMd" type="checkbox" name="parseMd" />
Render inline Markdown in messages
</label>
</div>
<div>
<label class="opt">
<input
:checked="store.state.settings.renderMdSrc"
type="checkbox"
name="renderMdSrc"
/>
Show source characters in rendered Markdown (i.e. <code>`code`</code> instead of
<code>code</code>)
</label>
</div>
<template v-if="store.state.serverConfiguration?.prefetch">
<h2>Link previews</h2>
<div>

View file

@ -28,7 +28,7 @@ export type ParseFragment =
| undefined
)[];
export const parseMd = (src: string) => {
export const parseMd = (src: string, renderMdSrc) => {
let i = 0;
const result: string[] = [];
@ -44,10 +44,14 @@ export const parseMd = (src: string) => {
"`": "monospace",
}[c];
const srcBlock = renderMdSrc ? (double ? c + c : c) : "";
const spanContents = `${srcBlock}${parseMd(
src.slice(i + n, end),
renderMdSrc
)}${srcBlock}`;
if (end !== -1) {
result.push(
`<span class='irc-${className}'>${parseMd(src.slice(i + n, end))}</span>`
);
result.push(`<span class='irc-${className}'>${spanContents}</span>`);
i = end + n;
}
}

View file

@ -80,6 +80,9 @@ const defaultConfig = {
parseMd: {
default: false,
},
renderMdSrc: {
default: false,
},
use12hClock: {
default: false,
},