mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 02:52:38 +00:00
Add editor highlighting
This commit is contained in:
@@ -158,7 +158,7 @@ const Editor = createClass({
|
|||||||
|
|
||||||
highlightCustomMarkdown : function(){
|
highlightCustomMarkdown : function(){
|
||||||
if(!this.codeEditor.current) return;
|
if(!this.codeEditor.current) return;
|
||||||
if(this.state.view === 'text') {
|
if((this.state.view === 'text') ||(this.state.view === 'snip')) {
|
||||||
const codeMirror = this.codeEditor.current.codeMirror;
|
const codeMirror = this.codeEditor.current.codeMirror;
|
||||||
|
|
||||||
codeMirror.operation(()=>{ // Batch CodeMirror styling
|
codeMirror.operation(()=>{ // Batch CodeMirror styling
|
||||||
@@ -178,8 +178,10 @@ const Editor = createClass({
|
|||||||
for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
|
for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
|
||||||
|
|
||||||
let editorPageCount = 2; // start page count from page 2
|
let editorPageCount = 2; // start page count from page 2
|
||||||
|
let userSnippetCount = 1; // start snippet count from page 2
|
||||||
|
|
||||||
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
|
const whichSource = this.state.view === 'text' ? this.props.brew.text : this.props.brew.snippets;
|
||||||
|
_.forEach(whichSource.split('\n'), (line, lineNumber)=>{
|
||||||
|
|
||||||
//reset custom line styles
|
//reset custom line styles
|
||||||
codeMirror.removeLineClass(lineNumber, 'background', 'pageLine');
|
codeMirror.removeLineClass(lineNumber, 'background', 'pageLine');
|
||||||
@@ -193,7 +195,7 @@ const Editor = createClass({
|
|||||||
|
|
||||||
// Styling for \page breaks
|
// Styling for \page breaks
|
||||||
if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
|
if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
|
||||||
(this.props.renderer == 'V3' && line.match(/^\\page$/))) {
|
(this.props.renderer == 'V3' && line.match(/^\\page$/) && this.state.view === 'text')) {
|
||||||
|
|
||||||
// add back the original class 'background' but also add the new class '.pageline'
|
// add back the original class 'background' but also add the new class '.pageline'
|
||||||
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
||||||
@@ -206,12 +208,26 @@ const Editor = createClass({
|
|||||||
editorPageCount += 1;
|
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(/^\\column$/)){
|
if(line.match(/^\\column$/)){
|
||||||
codeMirror.addLineClass(lineNumber, 'text', 'columnSplit');
|
codeMirror.addLineClass(lineNumber, 'text', 'columnSplit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Styling for \snippet breaks
|
||||||
|
if(this.state.view === 'snip' && line.match(/^\\snippet\ .*$/)) {
|
||||||
|
|
||||||
|
// add back the original class 'background' but also add the new class '.snippetLine'
|
||||||
|
codeMirror.addLineClass(lineNumber, 'background', 'snippetLine');
|
||||||
|
const userSnippetCountElement = Object.assign(document.createElement('span'), {
|
||||||
|
className : 'editor-snippet-count',
|
||||||
|
textContent : userSnippetCount
|
||||||
|
});
|
||||||
|
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, userSnippetCountElement);
|
||||||
|
|
||||||
|
userSnippetCount += 1;
|
||||||
|
};
|
||||||
// definition lists
|
// definition lists
|
||||||
if(line.includes('::')){
|
if(line.includes('::')){
|
||||||
if(/^:*$/.test(line) == true){ return; };
|
if(/^:*$/.test(line) == true){ return; };
|
||||||
|
|||||||
@@ -10,10 +10,18 @@
|
|||||||
background : #33333328;
|
background : #33333328;
|
||||||
border-top : #333399 solid 1px;
|
border-top : #333399 solid 1px;
|
||||||
}
|
}
|
||||||
|
.snippetLine {
|
||||||
|
background : #33333328;
|
||||||
|
border-top : #333399 solid 1px;
|
||||||
|
}
|
||||||
.editor-page-count {
|
.editor-page-count {
|
||||||
float : right;
|
float : right;
|
||||||
color : grey;
|
color : grey;
|
||||||
}
|
}
|
||||||
|
.editor-snippet-count {
|
||||||
|
float : right;
|
||||||
|
color : grey;
|
||||||
|
}
|
||||||
.columnSplit {
|
.columnSplit {
|
||||||
font-style : italic;
|
font-style : italic;
|
||||||
color : grey;
|
color : grey;
|
||||||
|
|||||||
Reference in New Issue
Block a user