add position, scale, fg and bg MFM functions

This commit is contained in:
Johann150 2023-05-27 15:11:49 +02:00
parent 51b95e272c
commit 59c880b909
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 28 additions and 1 deletions

View file

@ -71,6 +71,22 @@
}
}
.mfm-position {
transform: translate(calc(var(--mfm-x, 0) * 1em), calc(var(--mfm-y, 0) * 1em));
}
.mfm-scale {
transform: scale(var(--mfm-x, 1), var(--mfm-y, 1));
}
.mfm-fg {
color: var(--mfm-color, #f00);
}
.mfm-bg {
background-color: var(--mfm-color, #0f0);
}
.markdown-container {
blockquote {
display: block;

View file

@ -17,6 +17,9 @@ const sanitizerOptions = {
span: {
'--mfm-speed': [/^\d*\.?\d+m?s$/],
'--mfm-deg': [/^\d*\.?\d+$/],
'--mfm-x': [/^\d*\.?\d+$/],
'--mfm-y': [/^\d*\.?\d+$/],
'--mfm-color': [/^#([0-9a-f]{3}){1,2}$/i],
},
},
allowedSchemes: sanitizeHtml.defaults.allowedSchemes.concat([ 'gopher', 'gemini' ]),
@ -259,7 +262,15 @@ marked.use({
if (arg.includes('=')) {
// split once at first equal sign
const equalsIdx = arg.indexOf('=');
return [arg.slice(0, equalsIdx), arg.slice(equalsIdx + 1)];
const key = arg.slice(0, equalsIdx);
let value = arg.slice(equalsIdx + 1);
// add initial octothorpe to hex color code if necessary
if (key === 'color' && !value.startsWith('#')) {
value = '#' + value;
}
return [key, value];
} else {
return [arg, null];
}