0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-18 14:22:42 +00:00

Created new wrapper for my markdown parser, added it to the print page

This commit is contained in:
Scott Tolksdorf
2016-06-07 09:50:50 -04:00
parent 8df4dc56b2
commit e38850f807
6 changed files with 30 additions and 19 deletions

View File

@@ -1,5 +1,8 @@
# changelog # changelog
### Tuesday, 07/06/2016 - v2.2.2
- Fixed bug with new markdown lexer and aprser not working on print page
### Sunday, 05/06/2016 - v2.2.1 ### Sunday, 05/06/2016 - v2.2.1
- Adding in a new Class table div block. The old Class table block used weird stacking of HTML elements, resulting is difficult to control behaviour and poor interactiosn with the rest of the page. This new block is much easier to style and work with. - Adding in a new Class table div block. The old Class table block used weird stacking of HTML elements, resulting is difficult to control behaviour and poor interactiosn with the rest of the page. This new block is much easier to style and work with.
- Added in a new wide table snippet - Added in a new wide table snippet

View File

@@ -2,20 +2,7 @@ var React = require('react');
var _ = require('lodash'); var _ = require('lodash');
var cx = require('classnames'); var cx = require('classnames');
var Markdown = require('marked'); var Markdown = require('naturalcrit/markdown.js');
var renderer = new Markdown.Renderer();
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
if(_.startsWith(_.trim(html), '<div class=') && _.endsWith(_.trim(html), '</div>')){
var openTag = html.substring(0, html.indexOf('>')+1);
html = html.substring(html.indexOf('>')+1);
html = html.substring(0, html.lastIndexOf('</div>'));
return `${openTag} ${Markdown(html)} </div>`;
}
return html;
}
var PAGE_HEIGHT = 1056 + 30; var PAGE_HEIGHT = 1056 + 30;
@@ -77,7 +64,7 @@ var BrewRenderer = React.createClass({
}, },
renderPage : function(pageText, index){ renderPage : function(pageText, index){
return <div className='phb' dangerouslySetInnerHTML={{__html:Markdown(pageText, {renderer : renderer})}} key={index} /> return <div className='phb' dangerouslySetInnerHTML={{__html:Markdown.render(pageText)}} key={index} />
}, },
renderPages : function(){ renderPages : function(){

View File

@@ -11,7 +11,7 @@ var Navbar = React.createClass({
<Nav.item href='/' className='homebrewLogo'> <Nav.item href='/' className='homebrewLogo'>
<div>The Homebrewery</div> <div>The Homebrewery</div>
</Nav.item> </Nav.item>
<Nav.item>v2.2.1</Nav.item> <Nav.item>v2.2.2</Nav.item>
</Nav.section> </Nav.section>
{this.props.children} {this.props.children}
</Nav.base> </Nav.base>

View File

@@ -1,7 +1,7 @@
{ {
"name": "homebrewery", "name": "homebrewery",
"description": "Create authentic looking D&D homebrews using only markdown", "description": "Create authentic looking D&D homebrews using only markdown",
"version": "2.2.1", "version": "2.2.2",
"scripts": { "scripts": {
"postinstall": "gulp prod", "postinstall": "gulp prod",
"start": "node server.js" "start": "node server.js"

View File

@@ -108,7 +108,7 @@ app.get('/share/:id', function(req, res){
}); });
//Print Page //Print Page
var Markdown = require('marked'); var Markdown = require('naturalcrit/markdown.js');
var PHBStyle = '<style>' + require('fs').readFileSync('./phb.standalone.css', 'utf8') + '</style>' var PHBStyle = '<style>' + require('fs').readFileSync('./phb.standalone.css', 'utf8') + '</style>'
app.get('/print/:id', function(req, res){ app.get('/print/:id', function(req, res){
HomebrewModel.find({shareId : req.params.id}, function(err, objs){ HomebrewModel.find({shareId : req.params.id}, function(err, objs){
@@ -120,7 +120,7 @@ app.get('/print/:id', function(req, res){
} }
var content = _.map(brew.text.split('\\page'), function(pageText){ var content = _.map(brew.text.split('\\page'), function(pageText){
return '<div class="phb print">' + Markdown(pageText) + '</div>'; return '<div class="phb print">' + Markdown.render(pageText) + '</div>';
}).join('\n'); }).join('\n');
var dialog = ''; var dialog = '';

View File

@@ -0,0 +1,21 @@
var _ = require('lodash');
var Markdown = require('marked');
var renderer = new Markdown.Renderer();
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
if(_.startsWith(_.trim(html), '<div class=') && _.endsWith(_.trim(html), '</div>')){
var openTag = html.substring(0, html.indexOf('>')+1);
html = html.substring(html.indexOf('>')+1);
html = html.substring(0, html.lastIndexOf('</div>'));
return `${openTag} ${Markdown(html)} </div>`;
}
return html;
};
module.exports = {
render : (rawText)=>{
return Markdown(rawText, {renderer : renderer})
},
marked : Markdown
};