0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-10 09:12:39 +00:00

Update class Features snippet to v3

Puts adjacent `term :: definition` s into the same `dl` block for easier spacing of sets of terms.
This commit is contained in:
Trevor Buckner
2021-09-11 21:52:37 -04:00
parent cd0b659653
commit 82b9f825d5
3 changed files with 34 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
const _ = require('lodash'); const _ = require('lodash');
const dedent = require('dedent-tabs').default;
module.exports = function(classname){ module.exports = function(classname){
@@ -10,33 +11,32 @@ module.exports = function(classname){
const hitDie = _.sample([4, 6, 8, 10, 12]); const hitDie = _.sample([4, 6, 8, 10, 12]);
const abilityList = ['Strength', 'Dexerity', 'Constitution', 'Wisdom', 'Charisma', 'Intelligence']; const abilityList = ['Strength', 'Dexerity', 'Constitution', 'Wisdom', 'Charisma', 'Intelligence'];
const skillList = ['Acrobatics ', 'Animal Handling', 'Arcana', 'Athletics', 'Deception', 'History', 'Insight', 'Intimidation', 'Investigation', 'Medicine', 'Nature', 'Perception', 'Performance', 'Persuasion', 'Religion', 'Sleight of Hand', 'Stealth', 'Survival']; const skillList = ['Acrobatics', 'Animal Handling', 'Arcana', 'Athletics', 'Deception', 'History', 'Insight', 'Intimidation', 'Investigation', 'Medicine', 'Nature', 'Perception', 'Performance', 'Persuasion', 'Religion', 'Sleight of Hand', 'Stealth', 'Survival'];
return [ return dedent`
'## Class Features', ## Class Features
`As a ${classname}, you gain the following class features`, As a ${classname}, you gain the following class features
'#### Hit Points', #### Hit Points
'___',
`- **Hit Dice:** 1d${hitDie} per ${classname} level`, **Hit Dice:** :: 1d${hitDie} per ${classname} level
`- **Hit Points at 1st Level:** ${hitDie} + your Constitution modifier`, **Hit Points at 1st Level:** :: ${hitDie} + your Constitution modifier
`- **Hit Points at Higher Levels:** 1d${hitDie} (or ${hitDie/2 + 1}) + your Constitution modifier per ${classname} level after 1st`, **Hit Points at Higher Levels:** :: 1d${hitDie} (or ${hitDie/2 + 1}) + your Constitution modifier per ${classname} level after 1st
'',
'#### Proficiencies', #### Proficiencies
'___',
`- **Armor:** ${_.sampleSize(['Light armor', 'Medium armor', 'Heavy armor', 'Shields'], _.random(0, 3)).join(', ') || 'None'}`, **Armor:** :: ${_.sampleSize(['Light armor', 'Medium armor', 'Heavy armor', 'Shields'], _.random(0, 3)).join(', ') || 'None'}
`- **Weapons:** ${_.sampleSize(['Squeegee', 'Rubber Chicken', 'Simple weapons', 'Martial weapons'], _.random(0, 2)).join(', ') || 'None'}`, **Weapons:** :: ${_.sampleSize(['Squeegee', 'Rubber Chicken', 'Simple weapons', 'Martial weapons'], _.random(0, 2)).join(', ') || 'None'}
`- **Tools:** ${_.sampleSize(['Artian\'s tools', 'one musical instrument', 'Thieve\'s tools'], _.random(0, 2)).join(', ') || 'None'}`, **Tools:** :: ${_.sampleSize(['Artian\'s tools', 'one musical instrument', 'Thieve\'s tools'], _.random(0, 2)).join(', ') || 'None'}
'',
'___', **Saving Throws:** :: ${_.sampleSize(abilityList, 2).join(', ')}
`- **Saving Throws:** ${_.sampleSize(abilityList, 2).join(', ')}`, **Skills:** :: Choose two from ${_.sampleSize(skillList, _.random(4, 6)).join(', ')}
`- **Skills:** Choose two from ${_.sampleSize(skillList, _.random(4, 6)).join(', ')}`,
'', #### Equipment
'#### Equipment', You start with the following equipment, in addition to the equipment granted by your background:
'You start with the following equipment, in addition to the equipment granted by your background:', - *(a)* a martial weapon and a shield or *(b)* two martial weapons
'- *(a)* a martial weapon and a shield or *(b)* two martial weapons', - *(a)* five javelins or *(b)* any simple melee weapon
'- *(a)* five javelins or *(b)* any simple melee weapon', - ${_.sample(['10 lint fluffs', '1 button', 'a cherished lost sock'])}
`- ${_.sample(['10 lint fluffs', '1 button', 'a cherished lost sock'])}`,
'\n\n\n' `;
].join('\n');
}; };

View File

@@ -208,7 +208,7 @@ const definitionLists = {
level : 'block', level : 'block',
start(src) { return src.match(/^.*?::.*/m)?.index; }, // Hint to Marked.js to stop and check for a match start(src) { return src.match(/^.*?::.*/m)?.index; }, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) { tokenizer(src, tokens) {
const regex = /^([^\n]*?)::([^\n]*)/ym; const regex = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym;
let match; let match;
let endIndex = 0; let endIndex = 0;
const definitions = []; const definitions = [];
@@ -228,12 +228,10 @@ const definitionLists = {
} }
}, },
renderer(token) { renderer(token) {
return `<dl> return `<dl>${token.definitions.reduce((html, def)=>{
${token.definitions.reduce((html, def)=>{ return `${html}<dt>${this.parser.parseInline(def.dt)}</dt>`
return `${html}<dt>${this.parser.parseInline(def.dt)}</dt>` + `<dd>${this.parser.parseInline(def.dd)}</dd>\n`;
+ `<dd>${this.parser.parseInline(def.dd)}</dd>\n`; }, '')}</dl>`;
}, '')}
</dl>`;
} }
}; };

View File

@@ -739,13 +739,10 @@ body {
dl { dl {
line-height : 1.3em; line-height : 1.3em;
padding-left : 1em; padding-left : 1em;
text-indent : -1em; white-space : pre-line;
& + * { & + * {
margin-top : 0.28cm; margin-top : 0.28cm;
} }
& + dl {
margin-top : 0;
}
} }
dl + * { dl + * {
margin-top : 0.17cm; margin-top : 0.17cm;
@@ -756,6 +753,7 @@ body {
dt { dt {
display : inline; display : inline;
margin-right : 5px; margin-right : 5px;
margin-left : -1em;
} }
dd { dd {
display : inline; display : inline;