mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-28 09:12:45 +00:00
Definition List to Markdown Extension. New syntax.
This commit is contained in:
@@ -82,11 +82,11 @@ module.exports = {
|
||||
return [
|
||||
`#### ${_.sample(spellNames)}`,
|
||||
`*${_.sample(level)}-level ${_.sample(spellSchools)}*`,
|
||||
'___',
|
||||
'- **Casting Time:** 1 action',
|
||||
`- **Range:** ${_.sample(['Self', 'Touch', '30 feet', '60 feet'])}`,
|
||||
`- **Components:** ${components}`,
|
||||
`- **Duration:** ${_.sample(['Until dispelled', '1 round', 'Instantaneous', 'Concentration, up to 10 minutes', '1 hour'])}`,
|
||||
'',
|
||||
'**Casting Time:** :: 1 action',
|
||||
`**Range:** :: ${_.sample(['Self', 'Touch', '30 feet', '60 feet'])}`,
|
||||
`**Components:** :: ${components}`,
|
||||
`**Duration:** :: ${_.sample(['Until dispelled', '1 round', 'Instantaneous', 'Concentration, up to 10 minutes', '1 hour'])}`,
|
||||
'',
|
||||
'A flame, equivalent in brightness to a torch, springs from an object that you touch. ',
|
||||
'The effect look like a regular flame, but it creates no heat and doesn\'t use oxygen. ',
|
||||
|
||||
@@ -146,18 +146,18 @@ module.exports = {
|
||||
## ${getMonsterName()}
|
||||
*${getType()}, ${getAlignment()}*
|
||||
___
|
||||
: **Armor Class** : ${_.random(10, 20)} (chain mail, shield)
|
||||
: **Hit Points** : ${_.random(1, 150)}(1d4 + 5)
|
||||
: **Speed** : ${_.random(0, 50)}ft.
|
||||
**Armor Class** :: ${_.random(10, 20)} (chain mail, shield)
|
||||
**Hit Points** :: ${_.random(1, 150)}(1d4 + 5)
|
||||
**Speed** :: ${_.random(0, 50)}ft.
|
||||
___
|
||||
| STR | DEX | CON | INT | WIS | CHA |
|
||||
|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
|
||||
${getStats()}
|
||||
___
|
||||
: **Condition Immunities** : ${genList(['groggy', 'swagged', 'weak-kneed', 'buzzed', 'groovy', 'melancholy', 'drunk'], 3)}
|
||||
: **Senses** : darkvision 60 ft., passive Perception ${_.random(3, 20)}
|
||||
: **Languages** : ${genList(['Common', 'Pottymouth', 'Gibberish', 'Latin', 'Jive'], 2)}
|
||||
: **Challenge** : ${_.random(0, 15)} (${_.random(10, 10000)} XP)
|
||||
**Condition Immunities** :: ${genList(['groggy', 'swagged', 'weak-kneed', 'buzzed', 'groovy', 'melancholy', 'drunk'], 3)}
|
||||
**Senses** :: darkvision 60 ft., passive Perception ${_.random(3, 20)}
|
||||
**Languages** :: ${genList(['Common', 'Pottymouth', 'Gibberish', 'Latin', 'Jive'], 2)}
|
||||
**Challenge** :: ${_.random(0, 15)} (${_.random(10, 10000)} XP)
|
||||
___
|
||||
:
|
||||
${_.times(_.random(genLines, genLines + 2), function(){return genAbilities();}).join('\n\t\t\t\n\t\t\t')}
|
||||
|
||||
@@ -74,7 +74,7 @@ const mustacheSpans = {
|
||||
const mustacheDivs = {
|
||||
name : 'mustacheDivs',
|
||||
level : 'block',
|
||||
start(src) { return src.match(/^ *{{[^{]/)?.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) {
|
||||
const completeBlock = /^ *{{.*\n *}}/s; // Regex for the complete token
|
||||
const blockRegex = /^ *{{(?:="[\w,\-. ]*"|[^"'{}\s])*$|^ *}}$/gm;
|
||||
@@ -116,7 +116,43 @@ const mustacheDivs = {
|
||||
}
|
||||
};
|
||||
|
||||
Markdown.use({ extensions: [mustacheSpans, mustacheDivs] });
|
||||
const definitionLists = {
|
||||
name : 'definitionLists',
|
||||
level : 'block',
|
||||
start(src) { return src.match(/^.*?::.*/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||
tokenizer(src, tokens) {
|
||||
const regex = /^([^\n]*?)::([^\n]*)/ym;
|
||||
let match;
|
||||
let endIndex = 0;
|
||||
const definitions = [];
|
||||
//if(!src.match(/^[^\n]*?::/)) {console.log('return'); return;}
|
||||
while (match = regex.exec(src)) {
|
||||
definitions.push({
|
||||
dt : this.inlineTokens(match[1].trim()),
|
||||
dd : this.inlineTokens(match[2].trim())
|
||||
});
|
||||
//console.log(regexl)
|
||||
endIndex = regex.lastIndex;
|
||||
}
|
||||
if(definitions.length) {
|
||||
return {
|
||||
type : 'definitionLists',
|
||||
raw : src.slice(0, endIndex),
|
||||
definitions
|
||||
};
|
||||
}
|
||||
},
|
||||
renderer(token) {
|
||||
return `<dl>
|
||||
${token.definitions.reduce((html, def)=>{
|
||||
return `${html}<dt>${this.parseInline(def.dt)}</dt>`
|
||||
+ `<dd>${this.parseInline(def.dd)}</dd>\n`;
|
||||
}, '')}
|
||||
</dl>`;
|
||||
}
|
||||
};
|
||||
|
||||
Markdown.use({ extensions: [mustacheSpans, mustacheDivs, definitionLists] });
|
||||
|
||||
//Fix local links in the Preview iFrame to link inside the frame
|
||||
renderer.link = function (href, title, text) {
|
||||
@@ -216,8 +252,6 @@ module.exports = {
|
||||
render : (rawBrewText)=>{
|
||||
rawBrewText = rawBrewText.replace(/^\\column$/gm, `<div class='columnSplit'></div>`)
|
||||
.replace(/^(:+)$/gm, (match)=>`${`<div class='blank'></div>`.repeat(match.length)}\n`)
|
||||
.replace(/(?:^|>) *:([^:\n]*):([^\n]*)\n/gm, (match, term, def)=>`<dt>${Markdown.parseInline(term)}</dt><dd>${def}</dd>`)
|
||||
.replace(/(<dt>.*<\/dt><dd>.*<\/dd>\n?)+/gm, `<dl>$1</dl>\n\n`)
|
||||
.replace(/^}}/gm, '\n}}')
|
||||
.replace(/^({{[^\n]*)$/gm, '$1\n');
|
||||
return Markdown(
|
||||
|
||||
@@ -283,11 +283,6 @@ body {
|
||||
dl {
|
||||
.useSansSerif();
|
||||
color : @headerText;
|
||||
padding-left :1.3em;
|
||||
text-indent :-1.3em;
|
||||
}
|
||||
dd {
|
||||
text-indent : 0px;
|
||||
}
|
||||
|
||||
// Monster Ability table
|
||||
@@ -581,17 +576,26 @@ body {
|
||||
// * DEFINITION LISTS
|
||||
// *****************************/
|
||||
.page {
|
||||
// dl {
|
||||
// margin-top: 10px;
|
||||
// }
|
||||
dl {
|
||||
line-height : 1.3em;
|
||||
padding-left : 1em;
|
||||
text-indent : -1em;
|
||||
}
|
||||
dl + p {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
p + dl {
|
||||
margin-top: -0.5em;
|
||||
}
|
||||
dt {
|
||||
float: left;
|
||||
//clear: left; //Doesn't seem necessary
|
||||
margin-right: 5px;
|
||||
}
|
||||
// dd {
|
||||
// margin-left: 0px;
|
||||
// }
|
||||
dd {
|
||||
margin-left : 0px;
|
||||
text-indent : 0px;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************
|
||||
|
||||
Reference in New Issue
Block a user