Change diceroll to avoid the immense pain of dealing with tryign to localise that because of remarkdowning

indiachan-spamvector
Thomas Lynch 1 year ago
parent 257b4a136e
commit 491170cad3
  1. 7
      lib/post/markdown/handler/diceroll.js
  2. 21
      lib/post/markdown/handler/diceroll.test.js
  3. 4
      views/custompages/faq.pug

@ -2,8 +2,8 @@
module.exports = {
regexPrepare: /##(?<numdice>[1-9][0-9]{0,1})d(?<numsides>1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?<operator>[+-])(?<modifier>[1-9][0-9]{0,8}))?(?<value>=[1-9][0-9]{0,8})?/gmi,
regexMarkdown: /##(?<numdice>[1-9][0-9]{0,1})d(?<numsides>1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?<operator>[+-])(?<modifier>[1-9][0-9]{0,8}))?&#x3D;(?<value>[1-9][0-9]{0,8})/gmi,
regexPrepare: /##(?<numdice>[1-9][0-9]{0,1})%(?<numsides>1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?<operator>[+-])(?<modifier>[1-9][0-9]{0,8}))?(?<value>=[1-9][0-9]{0,8})?/gmi,
regexMarkdown: /##(?<numdice>[1-9][0-9]{0,1})%(?<numsides>1[0-9]{1,8}|[2-9][0-9]{0,8})(?:(?<operator>[+-])(?<modifier>[1-9][0-9]{0,8}))?&#x3D;(?<value>[1-9][0-9]{0,8})/gmi,
prepare: (force, match, numdice, numsides, operator, modifier, value) => {
if (!force && value) {
@ -34,7 +34,6 @@ module.exports = {
numdice = parseInt(numdice);
numsides = parseInt(numsides);
value = parseInt(value);
let matchWithoutValue = match.replace(/&#x3D;.*/, '');
return `<img src='/file/dice.png' height='16' width='16' /><span class='dice'>(${matchWithoutValue}) Rolled ${numdice} dice with ${numsides} sides${modifier ? ' and modifier '+operator+modifier : '' } = ${value}</span>`;
return `<img src='/file/dice.png' height='16' width='16' /><span class='dice'>(##${numdice}%${numsides}${modifier ? operator+modifier : '' }) = ${value}</span>`;
},
};

@ -3,12 +3,12 @@ const diceroll = require('./diceroll.js');
describe('diceroll markdown', () => {
const prepareCases = [
{ in: '##3d6', out: '##3d6=' },
{ in: '##99d99', out: '##99d99=' },
{ in: '##999d999', out: '##999d999' },
{ in: '##3d8+5', out: '##3d8+5=' },
{ in: '##3d8-5', out: '##3d8-5=' },
{ in: '##0d0', out: '##0d0' },
{ in: '##3%6', out: '##3%6=' },
{ in: '##99%99', out: '##99%99=' },
{ in: '##999%999', out: '##999%999' },
{ in: '##3%8+5', out: '##3%8+5=' },
{ in: '##3%8-5', out: '##3%8-5=' },
{ in: '##0%0', out: '##0%0' },
];
for(let i in prepareCases) {
test(`should contain ${prepareCases[i].out} for an input of ${prepareCases[i].in}`, () => {
@ -18,10 +18,11 @@ describe('diceroll markdown', () => {
}
const markdownCases = [
{ in: '##3d6&#x3D;10', out: 'Rolled 3 dice with 6 sides =' },
{ in: '##99d99&#x3D;5138', out: 'Rolled 99 dice with 99 sides =' },
{ in: '##999d999&#x3D;10000', out: '##999d999&#x3D;10000' },
{ in: '##0d0', out: '##0d0' },
{ in: '##3%6&#x3D;10', out: '(##3%6)' },
{ in: '##99%99&#x3D;5138', out: '(##99%99)' },
{ in: '##999%999&#x3D;10000', out: '##999%999&#x3D;' },
{ in: '##0%0&#x3D;10', out: '##0%0&#x3D;' },
{ in: '##0%0', out: '##0%0' },
];
for(let i in markdownCases) {
test(`should contain ${markdownCases[i].out} for an input of ${markdownCases[i].in}`, () => {

@ -148,10 +148,10 @@ block content
td
span.detected ((( detected )))
tr
td ##2d9+3
td ##2%9+3
td
img(src='/file/dice.png' height='16' width='16')
span.dice (##2d9+3) Rolled 2 dice with 9 sides and modifier +3 = 10
span.dice (##2%9+3) = 10
tr
td https://example.com
td: a(href='#!') https://example.com

Loading…
Cancel
Save