0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-15 19:12:38 +00:00

Merge pull request #1809 from Gazook89/page-numbers-via-JS

Page numbers via js
This commit is contained in:
Trevor Buckner
2021-12-06 15:51:58 -05:00
committed by GitHub
2 changed files with 23 additions and 27 deletions

View File

@@ -109,32 +109,35 @@ const Editor = createClass({
//reset custom text styles //reset custom text styles
const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear(); for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{ let editorPageCount = 2; // start page count from page 2
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
//reset custom line styles //reset custom line styles
codeMirror.removeLineClass(lineNumber, 'background'); codeMirror.removeLineClass(lineNumber, 'background');
codeMirror.removeLineClass(lineNumber, 'text'); codeMirror.removeLineClass(lineNumber, 'text');
// Legacy Codemirror styling // Styling for \page breaks
if(this.props.renderer == 'legacy') { if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
if(line.includes('\\page')){ (this.props.renderer == 'V3' && line.match(/^\\page$/))) {
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
r.push(lineNumber); // add back the original class 'background' but also add the new class '.pageline'
} codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
} const pageCountElement = Object.assign(document.createElement('span'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
editorPageCount += 1;
};
// New Codemirror styling for V3 renderer // New Codemirror styling for V3 renderer
if(this.props.renderer == 'V3') { if(this.props.renderer == 'V3') {
if(line.match(/^\\page$/)){
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
r.push(lineNumber);
}
if(line.match(/^\\column$/)){ if(line.match(/^\\column$/)){
codeMirror.addLineClass(lineNumber, 'text', 'columnSplit'); codeMirror.addLineClass(lineNumber, 'text', 'columnSplit');
r.push(lineNumber);
} }
// Highlight inline spans {{content}} // Highlight inline spans {{content}}
@@ -164,10 +167,7 @@ const Editor = createClass({
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' }); codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
} }
} }
});
return r;
}, []);
return lineNumbers;
} }
}, },

View File

@@ -5,17 +5,13 @@
.codeEditor{ .codeEditor{
height : 100%; height : 100%;
counter-reset : page;
counter-increment : page;
.pageLine{ .pageLine{
background : #33333328; background : #33333328;
border-top : #339 solid 1px; border-top : #339 solid 1px;
&:after{ }
content : counter(page); .editor-page-count{
counter-increment : page; color : grey;
float : right; float : right;
color : gray;
}
} }
.columnSplit{ .columnSplit{
font-style : italic; font-style : italic;