Markdown and line break support in descriptions
This commit is contained in:
parent
6ac1189405
commit
6e8c5cd9c2
6 changed files with 24 additions and 8 deletions
BIN
dist/.DS_Store
vendored
BIN
dist/.DS_Store
vendored
Binary file not shown.
11
dist/app.js
vendored
11
dist/app.js
vendored
|
@ -102,10 +102,10 @@ const emphasis = str => {
|
|||
let keywords = ['constitution', 'con', 'intelligence', 'int', 'wisdom', 'wis', 'strength', 'str', 'dexterity', 'dex', 'charisma', 'cha', 'comeliness', 'com', 'saving throw', 'ability check', 'skill check'];
|
||||
keywords.forEach(word => {
|
||||
let r = new RegExp(` ${ word } `, 'gi');
|
||||
str = str.replace(r, o => `<em class="mdl-color-text--teal-600">${ o }</em>`);
|
||||
str = str.replace(r, o => ` _${ o.trim() }_ `);
|
||||
});
|
||||
|
||||
str = str.replace(/[\s()<>]+\d+d*\d*(th)*[\s()<>]+/gi, o => `<strong>${ o }</strong>`);
|
||||
str = str.replace(/[\s()<>]+\d+d*\d*(th)*[\s()<>]+/gi, o => ` **${ o.trim() }** `);
|
||||
return str;
|
||||
};
|
||||
|
||||
|
@ -198,8 +198,13 @@ const spellDetails = name => {
|
|||
view.spell_details.update({ data: {} });
|
||||
$('body').removeClass('details');
|
||||
} else {
|
||||
let data = store.spells.find(spell => name === spell.name);
|
||||
let data = clone(store.spells.find(spell => name === spell.name));
|
||||
let md = new Remarkable();
|
||||
data.description = Array.isArray(data.description) ? data.description.join('\n') : data.description;
|
||||
data.description = emphasis(data.description);
|
||||
data.description = md.render(data.description);
|
||||
data.description = data.description.replace(/\n/g, '<br>');
|
||||
|
||||
view.spell_details.update({
|
||||
data,
|
||||
url: window.location.href
|
||||
|
|
4
dist/remarkable.min.js
vendored
Normal file
4
dist/remarkable.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -74,6 +74,7 @@
|
|||
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
|
||||
<script src="./dist/jquery.min.js"></script>
|
||||
<script src="./dist/monkberry.js"></script>
|
||||
<script src="./dist/remarkable.min.js"></script>
|
||||
<script src="./dist/clipboard.min.js"></script>
|
||||
<script src="./dist/view.js"></script>
|
||||
<script src="./dist/app.js"></script>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"views": "views/*.monk"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "cp ./node_modules/clipboard/dist/clipboard.min.js ./dist && cp ./node_modules/jquery/dist/jquery.min.js ./dist && cp ./node_modules/monkberry/monkberry.js ./dist",
|
||||
"postinstall": "cp node_modules/clipboard/dist/clipboard.min.js dist && cp node_modules/jquery/dist/jquery.min.js dist && cp node_modules/monkberry/monkberry.js dist && cp node_modules/remarkable/dist/remarkable.min.js dist",
|
||||
"views": "monkberry src/views/*.monk --source-map --output dist/view.js",
|
||||
"js": "babel src/app.js --out-file dist/app.js",
|
||||
"develop": "nodemon --watch src -e monk,js --exec 'npm run views && npm run js'"
|
||||
|
@ -24,6 +24,7 @@
|
|||
"dependencies": {
|
||||
"clipboard": "^1.5.12",
|
||||
"jquery": "^3.1.0",
|
||||
"monkberry": "^4.0.7"
|
||||
"monkberry": "^4.0.7",
|
||||
"remarkable": "^1.6.2"
|
||||
}
|
||||
}
|
||||
|
|
11
src/app.js
11
src/app.js
|
@ -103,10 +103,10 @@ const emphasis = str => {
|
|||
let keywords = ['constitution', 'con', 'intelligence', 'int', 'wisdom', 'wis', 'strength', 'str', 'dexterity', 'dex', 'charisma', 'cha', 'comeliness', 'com', 'saving throw', 'ability check', 'skill check'];
|
||||
keywords.forEach(word => {
|
||||
let r = new RegExp(` ${word} `, 'gi');
|
||||
str = str.replace(r, o => `<em class="mdl-color-text--teal-600">${o}</em>`);
|
||||
str = str.replace(r, o => ` _${o.trim()}_ `);
|
||||
});
|
||||
|
||||
str = str.replace(/[\s()<>]+\d+d*\d*(th)*[\s()<>]+/gi, o => `<strong>${o}</strong>`);
|
||||
str = str.replace(/[\s()<>]+\d+d*\d*(th)*[\s()<>]+/gi, o => ` **${o.trim()}** `);
|
||||
return str;
|
||||
};
|
||||
|
||||
|
@ -207,8 +207,13 @@ const spellDetails = name => {
|
|||
view.spell_details.update({data: {}});
|
||||
$('body').removeClass('details');
|
||||
} else {
|
||||
let data = store.spells.find(spell => name === spell.name);
|
||||
let data = clone(store.spells.find(spell => name === spell.name));
|
||||
let md = new Remarkable();
|
||||
data.description = Array.isArray(data.description) ? data.description.join('\n') : data.description;
|
||||
data.description = emphasis(data.description);
|
||||
data.description = md.render(data.description);
|
||||
data.description = data.description.replace(/\n/g, '<br>');
|
||||
|
||||
view.spell_details.update({
|
||||
data,
|
||||
url: window.location.href
|
||||
|
|
Loading…
Add table
Reference in a new issue