1
0
Fork 0

Markdown and line break support in descriptions

This commit is contained in:
sharpshark28 2016-08-05 20:32:45 -05:00
parent 6ac1189405
commit 6e8c5cd9c2
6 changed files with 24 additions and 8 deletions

BIN
dist/.DS_Store vendored

Binary file not shown.

11
dist/app.js vendored
View file

@ -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']; 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 => { keywords.forEach(word => {
let r = new RegExp(` ${ word } `, 'gi'); 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; return str;
}; };
@ -198,8 +198,13 @@ const spellDetails = name => {
view.spell_details.update({ data: {} }); view.spell_details.update({ data: {} });
$('body').removeClass('details'); $('body').removeClass('details');
} else { } 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 = emphasis(data.description);
data.description = md.render(data.description);
data.description = data.description.replace(/\n/g, '<br>');
view.spell_details.update({ view.spell_details.update({
data, data,
url: window.location.href url: window.location.href

4
dist/remarkable.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -74,6 +74,7 @@
<script src="https://code.getmdl.io/1.1.3/material.min.js"></script> <script src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<script src="./dist/jquery.min.js"></script> <script src="./dist/jquery.min.js"></script>
<script src="./dist/monkberry.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/clipboard.min.js"></script>
<script src="./dist/view.js"></script> <script src="./dist/view.js"></script>
<script src="./dist/app.js"></script> <script src="./dist/app.js"></script>

View file

@ -7,7 +7,7 @@
"views": "views/*.monk" "views": "views/*.monk"
}, },
"scripts": { "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", "views": "monkberry src/views/*.monk --source-map --output dist/view.js",
"js": "babel src/app.js --out-file dist/app.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'" "develop": "nodemon --watch src -e monk,js --exec 'npm run views && npm run js'"
@ -24,6 +24,7 @@
"dependencies": { "dependencies": {
"clipboard": "^1.5.12", "clipboard": "^1.5.12",
"jquery": "^3.1.0", "jquery": "^3.1.0",
"monkberry": "^4.0.7" "monkberry": "^4.0.7",
"remarkable": "^1.6.2"
} }
} }

View file

@ -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']; 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 => { keywords.forEach(word => {
let r = new RegExp(` ${word} `, 'gi'); 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; return str;
}; };
@ -207,8 +207,13 @@ const spellDetails = name => {
view.spell_details.update({data: {}}); view.spell_details.update({data: {}});
$('body').removeClass('details'); $('body').removeClass('details');
} else { } 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 = emphasis(data.description);
data.description = md.render(data.description);
data.description = data.description.replace(/\n/g, '<br>');
view.spell_details.update({ view.spell_details.update({
data, data,
url: window.location.href url: window.location.href