require('./printPage.less'); const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); const { Meta } = require('vitreum/headtags'); const MarkdownLegacy = require('naturalcrit/markdownLegacy.js'); const Markdown = require('naturalcrit/markdown.js'); const PrintPage = createClass({ getDefaultProps : function() { return { query : {}, brew : { text : '', style : '', renderer : 'legacy' } }; }, getInitialState : function() { return { brewText : this.props.brew.text }; }, componentDidMount : function() { if(this.props.query.local){ this.setState((prevState, prevProps)=>({ brewText : localStorage.getItem(prevProps.query.local) })); } if(this.props.query.dialog) window.print(); }, renderStyle : function() { if(!this.props.brew.style) return; return
${this.props.brew.style} ` }} />; }, renderPages : function(){ if(this.props.brew.renderer == 'legacy') { return _.map(this.state.brewText.split('\\page'), (pageText, index)=>{ return
; }); } else { return _.map(this.state.brewText.split(/^\\page$/gm), (pageText, index)=>{ pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear) return (
); }); } }, render : function(){ return
{/* Apply CSS from Style tab */} {this.renderStyle()}
{this.renderPages()}
; } }); module.exports = PrintPage;