0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-15 19:12:38 +00:00

Add Roman numerals function

This commit is contained in:
G.Ambatte
2025-03-13 10:50:18 +13:00
parent e787a68859
commit b67eb59461

View File

@@ -8,6 +8,7 @@ import { markedSmartypantsLite as MarkedSmartypantsLite }
import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id'; import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id';
import { markedEmoji as MarkedEmojis } from 'marked-emoji'; import { markedEmoji as MarkedEmojis } from 'marked-emoji';
import MarkedSubSuperText from 'marked-subsuper-text'; import MarkedSubSuperText from 'marked-subsuper-text';
import { romanize } from 'romans';
//Icon fonts included so they can appear in emoji autosuggest dropdown //Icon fonts included so they can appear in emoji autosuggest dropdown
import diceFont from '../../themes/fonts/iconFonts/diceFont.js'; import diceFont from '../../themes/fonts/iconFonts/diceFont.js';
@@ -59,6 +60,16 @@ mathParser.functions.signed = function (a) {
if(a >= 0) return `+${a}`; if(a >= 0) return `+${a}`;
return `${a}`; return `${a}`;
}; };
// Add Roman numeral functions
mathParser.functions.toRomans = function (a) {
return romanize(a);
};
mathParser.functions.toRomansUpper = function (a) {
return romanize(a).toUpperCase();
};
mathParser.functions.toRomansLower = function (a) {
return romanize(a).toLowerCase();
};
//Processes the markdown within an HTML block if it's just a class-wrapper //Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (token) { renderer.html = function (token) {
@@ -87,7 +98,7 @@ renderer.paragraph = function(token){
//Fix local links in the Preview iFrame to link inside the frame //Fix local links in the Preview iFrame to link inside the frame
renderer.link = function (token) { renderer.link = function (token) {
let { href, title, tokens } = token; let { href, title, tokens } = token;
const text = this.parser.parseInline(tokens) const text = this.parser.parseInline(tokens);
let self = false; let self = false;
if(href[0] == '#') { if(href[0] == '#') {
self = true; self = true;
@@ -110,7 +121,7 @@ renderer.link = function (token) {
// Expose `src` attribute as `--HB_src` to make the URL accessible via CSS // Expose `src` attribute as `--HB_src` to make the URL accessible via CSS
renderer.image = function (token) { renderer.image = function (token) {
let {href, title, text} = token; const { href, title, text } = token;
if(href === null) if(href === null)
return text; return text;
@@ -873,7 +884,7 @@ const extractHTMLStyleTags = (htmlString)=>{
?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="')) ?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="'))
.reduce((obj, attr)=>{ .reduce((obj, attr)=>{
const index = attr.indexOf('='); const index = attr.indexOf('=');
let [key, value] = [attr.substring(0, index), attr.substring(index + 1)]; const [key, value] = [attr.substring(0, index), attr.substring(index + 1)];
obj[key.trim()] = value.replace(/"/g, ''); obj[key.trim()] = value.replace(/"/g, '');
return obj; return obj;
}, {}) || null; }, {}) || null;