mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-07 14:50:56 +00:00
4.20.91
* Added: Notice when FFZ fails to save settings because `localStorage` is full. * Added: Setting to move "Chat Identity" from the chat input box to the chat settings menu. (Closes #1025) * Fixed: Actually hide links when "Hide matching links for rich content." is enabled. (Closes #1019) * Fixed: Open the control center when clicking a markdown settings link without the control center open. * API Added: Toasts displayed by the `site.menu_button` module now support markdown.
This commit is contained in:
parent
a80728a10d
commit
66702103ff
24 changed files with 303 additions and 190 deletions
|
@ -5,101 +5,7 @@
|
|||
|
||||
<script>
|
||||
|
||||
import MD from 'markdown-it';
|
||||
import MILA from 'markdown-it-link-attributes';
|
||||
import {parse as parse_path} from 'utilities/path-parser';
|
||||
|
||||
let _md;
|
||||
|
||||
function getMD() {
|
||||
if ( ! _md ) {
|
||||
const md = _md = new MD({
|
||||
html: false,
|
||||
linkify: true
|
||||
});
|
||||
|
||||
md.use(SettingsLinks);
|
||||
md.use(MILA, {
|
||||
attrs: {
|
||||
class: 'ffz-tooltip',
|
||||
target: '_blank',
|
||||
rel: 'noopener',
|
||||
'data-tooltip-type': 'link'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return _md;
|
||||
}
|
||||
|
||||
|
||||
function SettingsLinks(md) {
|
||||
const default_render = md.renderer.rules.link_open || this.defaultRender;
|
||||
|
||||
md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
|
||||
const token = tokens[idx];
|
||||
if ( token && token.type === 'link_open' && Array.isArray(token.attrs) ) {
|
||||
let href;
|
||||
for(const attr of token.attrs) {
|
||||
if ( attr[0] === 'href' ) {
|
||||
href = attr[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( href.startsWith('~') ) {
|
||||
let path;
|
||||
|
||||
if ( href === '~' ) {
|
||||
// We don't have a path, make one from the bits.
|
||||
let i = idx + 1;
|
||||
let bits = [];
|
||||
|
||||
while(i < tokens.length) {
|
||||
const tok = tokens[i],
|
||||
type = tok?.type;
|
||||
if ( type === 'text' )
|
||||
bits.push(tok);
|
||||
else if ( type === 'link_close' )
|
||||
break;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
bits = bits.map(x => x.content).join('');
|
||||
const toks = parse_path(bits);
|
||||
path = toks.map(x => x.key).join('.');
|
||||
} else
|
||||
path = href.slice(1);
|
||||
|
||||
if ( path && path.length ) {
|
||||
for(const attr of token.attrs) {
|
||||
if ( attr[0] === 'class' ) {
|
||||
attr[1] = attr[1].replace(/ffz-tooltip/g, '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
token.attrs.push([
|
||||
'data-settings-link',
|
||||
path
|
||||
]);
|
||||
token.attrs.push([
|
||||
'onclick',
|
||||
'FrankerFaceZ.get().resolve("main_menu").mdNavigate(this);return false'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return default_render(tokens, idx, options, env, self);
|
||||
}
|
||||
}
|
||||
|
||||
SettingsLinks.defaultRender = function(tokens, idx, options, env, self) {
|
||||
return self.renderToken(tokens, idx, options);
|
||||
}
|
||||
|
||||
import getMD from 'utilities/markdown';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue