Skip to content

Commit

Permalink
mdparse: add toggle for viewing source chars
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzshantaram committed Apr 25, 2023
1 parent 43f6513 commit fa37f15
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/components/ParsedMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 19 additions & 4 deletions client/components/Settings/Appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,37 @@
Include seconds in timestamp
</label>
</div>
<div>
<label class="opt">
<input
:checked="store.state.settings.use12hClock"
type="checkbox"
name="use12hClock"
/>
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
Render inline Markdown in messages
</label>
</div>

<div>
<label class="opt">
<input
:checked="store.state.settings.use12hClock"
:checked="store.state.settings.renderMdSrc"
type="checkbox"
name="use12hClock"
name="renderMdSrc"
/>
Use 12-hour timestamps
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>
Expand Down
12 changes: 8 additions & 4 deletions client/js/helpers/mdHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand All @@ -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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions client/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const defaultConfig = {
parseMd: {
default: false,
},
renderMdSrc: {
default: false,
},
use12hClock: {
default: false,
},
Expand Down

0 comments on commit fa37f15

Please sign in to comment.