From dfa8aea1ecb28c561ed8bc8b502e62af3232282d Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 5 Oct 2022 20:37:05 +1300 Subject: [PATCH 01/14] Add newPageWithFooter function --- shared/naturalcrit/codeEditor/codeEditor.jsx | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index da1390511..a06587082 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -142,6 +142,20 @@ const CodeEditor = createClass({ 'Shift-Cmd-Enter' : this.newColumn, 'Ctrl-Enter' : this.newPage, 'Cmd-Enter' : this.newPage, + 'Ctrl-Alt-Enter' : ()=>this.newPageWithFooter(), + 'Cmd-Alt-Enter' : ()=>this.newPageWithFooter(), + 'Ctrl-Alt-1' : ()=>this.newPageWithFooter(1), + 'Cmd-Alt-1' : ()=>this.newPageWithFooter(1), + 'Ctrl-Alt-2' : ()=>this.newPageWithFooter(2), + 'Cmd-Alt-2' : ()=>this.newPageWithFooter(2), + 'Ctrl-Alt-3' : ()=>this.newPageWithFooter(3), + 'Cmd-Alt-3' : ()=>this.newPageWithFooter(3), + 'Ctrl-Alt-4' : ()=>this.newPageWithFooter(4), + 'Cmd-Alt-4' : ()=>this.newPageWithFooter(4), + 'Ctrl-Alt-5' : ()=>this.newPageWithFooter(5), + 'Cmd-Alt-5' : ()=>this.newPageWithFooter(5), + 'Ctrl-Alt-6' : ()=>this.newPageWithFooter(6), + 'Cmd-Alt-6' : ()=>this.newPageWithFooter(6), 'Ctrl-F' : 'findPersistent', 'Cmd-F' : 'findPersistent', 'Shift-Enter' : 'findPersistentPrevious', @@ -229,6 +243,20 @@ const CodeEditor = createClass({ this.codeMirror.replaceSelection('\n\\page\n\n', 'end'); }, + newPageWithFooter : function(headerSize=1) { + let header=''; + while (header.length < headerSize) { + header = header.concat('#'); + } + header = header.concat(' '); + + const cursorPos = this.codeMirror.getCursor(); + + const text = this.codeMirror.getValue().split('\n').slice(0, cursorPos.line).reverse().filter((line)=>{return line.slice(0, header.length) == header && line; })[0] || 'CHAPTER TITLE'; + + this.codeMirror.replaceSelection(`\n{{footnote ${text}}}\n{{pageNumber,auto}}\n\n\\page\n\n`, 'end'); + }, + makeUnderline : function() { const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '' && selection.slice(-4) === ''; this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `${selection}`, 'around'); From 5de63799c21facdc43d624ea1e71d370e579262a Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 5 Oct 2022 21:20:39 +1300 Subject: [PATCH 02/14] Update default footnote text --- shared/naturalcrit/codeEditor/codeEditor.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index a06587082..aaee268b1 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -252,7 +252,7 @@ const CodeEditor = createClass({ const cursorPos = this.codeMirror.getCursor(); - const text = this.codeMirror.getValue().split('\n').slice(0, cursorPos.line).reverse().filter((line)=>{return line.slice(0, header.length) == header && line; })[0] || 'CHAPTER TITLE'; + const text = this.codeMirror.getValue().split('\n').slice(0, cursorPos.line).reverse().filter((line)=>{return line.slice(0, header.length) == header && line; })[0] || 'PART 1 | SECTION NAME'; this.codeMirror.replaceSelection(`\n{{footnote ${text}}}\n{{pageNumber,auto}}\n\n\\page\n\n`, 'end'); }, From ee3cd214869adfb6bf75a1f7c6aeecf9e6c2e5f0 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 5 Oct 2022 21:29:49 +1300 Subject: [PATCH 03/14] Add to base snippets --- themes/V3/Blank/snippets.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/themes/V3/Blank/snippets.js b/themes/V3/Blank/snippets.js index cd508cccb..142e8f893 100644 --- a/themes/V3/Blank/snippets.js +++ b/themes/V3/Blank/snippets.js @@ -22,6 +22,11 @@ module.exports = [ icon : 'fas fa-file-alt', gen : '\n\\page\n' }, + { + name : 'Page Break with Footer', + icon : 'fas fa-file', + gen : '\n{{footnote PART 1 | SECTION NAME}}\n{{pageNumber,auto}}\n\n\\page\n' + }, { name : 'Vertical Spacing', icon : 'fas fa-arrows-alt-v', From c30eb9056a5be7b58fdc41473401ce31bf549bd6 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 5 Oct 2022 22:11:03 +1300 Subject: [PATCH 04/14] Break up text generation for legibility --- shared/naturalcrit/codeEditor/codeEditor.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index aaee268b1..b075033ac 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -252,7 +252,10 @@ const CodeEditor = createClass({ const cursorPos = this.codeMirror.getCursor(); - const text = this.codeMirror.getValue().split('\n').slice(0, cursorPos.line).reverse().filter((line)=>{return line.slice(0, header.length) == header && line; })[0] || 'PART 1 | SECTION NAME'; + const cmText = this.codeMirror.getValue(); + const cmTextArray = cmText.split('\n').slice(0, cursorPos.line).reverse(); + const cmTextArrayFilter = cmTextArray.filter((line)=>{ return line.slice(0, header.length) == header; }); + const text = cmTextArrayFilter[0].slice(header.length) || 'PART 1 | SECTION NAME'; this.codeMirror.replaceSelection(`\n{{footnote ${text}}}\n{{pageNumber,auto}}\n\n\\page\n\n`, 'end'); }, From e6ad8aefde42fed1a0b5b0595af8e1cb47c92cf6 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 3 Jun 2023 12:18:22 +1200 Subject: [PATCH 05/14] Lint fix --- shared/naturalcrit/codeEditor/codeEditor.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 2b23dcbf4..9a9c39ee9 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -190,7 +190,7 @@ const CodeEditor = createClass({ indent : function () { const cm = this.codeMirror; - if (cm.somethingSelected()) { + if(cm.somethingSelected()) { cm.execCommand('indentMore'); } else { cm.execCommand('insertSoftTab'); From 052c25506834ed008cca335d07560a196887c394 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 3 Jun 2023 13:23:39 +1200 Subject: [PATCH 06/14] Lint fixes --- server/googleActions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/googleActions.js b/server/googleActions.js index 49de3c077..3fdfadd45 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -100,12 +100,12 @@ const GoogleActions = { const drive = googleDrive.drive({ version: 'v3', auth }); const fileList = []; - let NextPageToken = ""; + let NextPageToken = ''; do { const obj = await drive.files.list({ pageSize : 1000, - pageToken : NextPageToken || "", + pageToken : NextPageToken || '', fields : 'nextPageToken, files(id, name, description, createdTime, modifiedTime, properties)', q : 'mimeType != \'application/vnd.google-apps.folder\' and trashed = false' }) From d2b2e69123f86e61707e33658563b71aca017f25 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 3 Jun 2023 13:30:32 +1200 Subject: [PATCH 07/14] Shift Footer generation to snippet --- client/homebrew/editor/editor.jsx | 3 +- .../homebrew/editor/snippetbar/snippetbar.jsx | 10 +++--- shared/naturalcrit/codeEditor/codeEditor.jsx | 31 ------------------- themes/V3/5ePHB/snippets.js | 6 ++++ themes/V3/5ePHB/snippets/footer.gen.js | 16 ++++++++++ 5 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 themes/V3/5ePHB/snippets/footer.gen.js diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 58e84e4fc..ed8cb87d5 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -323,7 +323,8 @@ const Editor = createClass({ theme={this.props.brew.theme} undo={this.undo} redo={this.redo} - historySize={this.historySize()} /> + historySize={this.historySize()} + cursorPos={this.refs.codeEditor?.getCursorPosition() || {}} /> {this.renderEditor()} diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index cfd2d5e91..adba5ff59 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -15,8 +15,8 @@ ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js'); ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js'); ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js'); -const execute = function(val, brew){ - if(_.isFunction(val)) return val(brew); +const execute = function(val, brew, params){ + if(_.isFunction(val)) return val(brew, params); return val; }; @@ -33,7 +33,8 @@ const Snippetbar = createClass({ renderer : 'legacy', undo : ()=>{}, redo : ()=>{}, - historySize : ()=>{} + historySize : ()=>{}, + cursorPos : {} }; }, @@ -105,6 +106,7 @@ const Snippetbar = createClass({ snippets={snippetGroup.snippets} key={snippetGroup.groupName} onSnippetClick={this.handleSnippetClick} + cursorPos={this.props.cursorPos} />; }); }, @@ -165,7 +167,7 @@ const SnippetGroup = createClass({ }, handleSnippetClick : function(e, snippet){ e.stopPropagation(); - this.props.onSnippetClick(execute(snippet.gen, this.props.brew)); + this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { cursorPos: this.props.cursorPos })); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 9a9c39ee9..2b5685e49 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -145,20 +145,6 @@ const CodeEditor = createClass({ 'Shift-Cmd-Enter' : this.newColumn, 'Ctrl-Enter' : this.newPage, 'Cmd-Enter' : this.newPage, - 'Ctrl-Alt-Enter' : ()=>this.newPageWithFooter(), - 'Cmd-Alt-Enter' : ()=>this.newPageWithFooter(), - 'Ctrl-Alt-1' : ()=>this.newPageWithFooter(1), - 'Cmd-Alt-1' : ()=>this.newPageWithFooter(1), - 'Ctrl-Alt-2' : ()=>this.newPageWithFooter(2), - 'Cmd-Alt-2' : ()=>this.newPageWithFooter(2), - 'Ctrl-Alt-3' : ()=>this.newPageWithFooter(3), - 'Cmd-Alt-3' : ()=>this.newPageWithFooter(3), - 'Ctrl-Alt-4' : ()=>this.newPageWithFooter(4), - 'Cmd-Alt-4' : ()=>this.newPageWithFooter(4), - 'Ctrl-Alt-5' : ()=>this.newPageWithFooter(5), - 'Cmd-Alt-5' : ()=>this.newPageWithFooter(5), - 'Ctrl-Alt-6' : ()=>this.newPageWithFooter(6), - 'Cmd-Alt-6' : ()=>this.newPageWithFooter(6), 'Ctrl-F' : 'findPersistent', 'Cmd-F' : 'findPersistent', 'Shift-Enter' : 'findPersistentPrevious', @@ -259,23 +245,6 @@ const CodeEditor = createClass({ this.codeMirror.replaceSelection('\n\\page\n\n', 'end'); }, - newPageWithFooter : function(headerSize=1) { - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); - } - header = header.concat(' '); - - const cursorPos = this.codeMirror.getCursor(); - - const cmText = this.codeMirror.getValue(); - const cmTextArray = cmText.split('\n').slice(0, cursorPos.line).reverse(); - const cmTextArrayFilter = cmTextArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = cmTextArrayFilter[0].slice(header.length) || 'PART 1 | SECTION NAME'; - - this.codeMirror.replaceSelection(`\n{{footnote ${text}}}\n{{pageNumber,auto}}\n\n\\page\n\n`, 'end'); - }, - injectText : function(injectText, overwrite=true) { const cm = this.codeMirror; if(!overwrite) { diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index dba4ad8d5..2a9b26b68 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -8,6 +8,7 @@ const ClassFeatureGen = require('./snippets/classfeature.gen.js'); const CoverPageGen = require('./snippets/coverpage.gen.js'); const TableOfContentsGen = require('./snippets/tableOfContents.gen.js'); const indexGen = require('./snippets/index.gen.js'); +const FooterGen = require('./snippets/footer.gen.js'); const dedent = require('dedent-tabs').default; @@ -29,6 +30,11 @@ module.exports = [ icon : 'fas fa-sort-numeric-down', gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n' }, + { + name : 'Footer', + icon : 'fas fa-sort-numeric-down', + gen : FooterGen + }, { name : 'Table of Contents', icon : 'fas fa-book', diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/5ePHB/snippets/footer.gen.js new file mode 100644 index 000000000..7a5d64fdb --- /dev/null +++ b/themes/V3/5ePHB/snippets/footer.gen.js @@ -0,0 +1,16 @@ +module.exports = function(brew, params){ + const cursorPos = params.cursorPos; + const headerSize = params.headerSize || 1; + + let header=''; + while (header.length < headerSize) { + header = header.concat('#'); + } + header = header.concat(' '); + + const textArray = brew.text.split('\n').slice(0, cursorPos.line).reverse(); + const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); + const text = textArrayFilter[0]?.slice(header.length) || 'PART 1 | SECTION NAME'; + + return `\n{{footnote ${text}}}\n`; +}; \ No newline at end of file From 9093f610bd4dc65c907829f3436a45f4072c09b2 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 3 Jun 2023 14:09:50 +1200 Subject: [PATCH 08/14] Add params from snippet to function --- .../homebrew/editor/snippetbar/snippetbar.jsx | 2 +- themes/V3/5ePHB/snippets.js | 44 +++++++++++++++++-- themes/V3/5ePHB/snippets/footer.gen.js | 28 ++++++------ 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index adba5ff59..f157e6107 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -167,7 +167,7 @@ const SnippetGroup = createClass({ }, handleSnippetClick : function(e, snippet){ e.stopPropagation(); - this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { cursorPos: this.props.cursorPos })); + this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { ...snippet.params, cursorPos: this.props.cursorPos })); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 2a9b26b68..8031efece 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -31,9 +31,47 @@ module.exports = [ gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n' }, { - name : 'Footer', - icon : 'fas fa-sort-numeric-down', - gen : FooterGen + name : 'Footer', + icon : 'fas fa-shoe-prints', + gen : FooterGen.createFooter, + subsnippets : [ + { + name : 'Footer from H1', + icon : 'fas fa-dice-one', + gen : FooterGen.createFooter, + params : { headerSize: 1 } + }, + { + name : 'Footer from H2', + icon : 'fas fa-dice-two', + gen : FooterGen.createFooter, + params : { headerSize: 2 } + }, + { + name : 'Footer from H3', + icon : 'fas fa-dice-three', + gen : FooterGen.createFooter, + params : { headerSize: 3 } + }, + { + name : 'Footer from H4', + icon : 'fas fa-dice-four', + gen : FooterGen.createFooter, + params : { headerSize: 4 } + }, + { + name : 'Footer from H5', + icon : 'fas fa-dice-five', + gen : FooterGen.createFooter, + params : { headerSize: 5 } + }, + { + name : 'Footer from H6', + icon : 'fas fa-dice-six', + gen : FooterGen.createFooter, + params : { headerSize: 6 } + } + ] }, { name : 'Table of Contents', diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/5ePHB/snippets/footer.gen.js index 7a5d64fdb..59c736836 100644 --- a/themes/V3/5ePHB/snippets/footer.gen.js +++ b/themes/V3/5ePHB/snippets/footer.gen.js @@ -1,16 +1,18 @@ -module.exports = function(brew, params){ - const cursorPos = params.cursorPos; - const headerSize = params.headerSize || 1; +module.exports = { + createFooter : function(brew, params){ + const cursorPos = params.cursorPos; + const headerSize = params.headerSize || 1; - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); + let header=''; + while (header.length < headerSize) { + header = header.concat('#'); + } + header = header.concat(' '); + + const textArray = brew.text.split('\n').slice(0, cursorPos.line).reverse(); + const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); + const text = textArrayFilter[0]?.slice(header.length) || 'PART 1 | SECTION NAME'; + + return `\n{{footnote ${text}}}\n`; } - header = header.concat(' '); - - const textArray = brew.text.split('\n').slice(0, cursorPos.line).reverse(); - const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = textArrayFilter[0]?.slice(header.length) || 'PART 1 | SECTION NAME'; - - return `\n{{footnote ${text}}}\n`; }; \ No newline at end of file From ade61971d0a163dffdbe1e029b7d025d2297c356 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 15 Jun 2023 11:50:38 +1200 Subject: [PATCH 09/14] Remove snippet.params --- .../homebrew/editor/snippetbar/snippetbar.jsx | 2 +- themes/V3/5ePHB/snippets.js | 44 ++++++++----------- themes/V3/5ePHB/snippets/footer.gen.js | 25 ++++++----- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index f157e6107..6048af6b0 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -167,7 +167,7 @@ const SnippetGroup = createClass({ }, handleSnippetClick : function(e, snippet){ e.stopPropagation(); - this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { ...snippet.params, cursorPos: this.props.cursorPos })); + this.props.onSnippetClick(execute(snippet.gen, this.props)); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 8031efece..e91e1f0ad 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -33,43 +33,37 @@ module.exports = [ { name : 'Footer', icon : 'fas fa-shoe-prints', - gen : FooterGen.createFooter, + gen : FooterGen.createFooterFunc(), subsnippets : [ { - name : 'Footer from H1', - icon : 'fas fa-dice-one', - gen : FooterGen.createFooter, - params : { headerSize: 1 } + name : 'Footer from H1', + icon : 'fas fa-dice-one', + gen : FooterGen.createFooterFunc(1) }, { - name : 'Footer from H2', - icon : 'fas fa-dice-two', - gen : FooterGen.createFooter, - params : { headerSize: 2 } + name : 'Footer from H2', + icon : 'fas fa-dice-two', + gen : FooterGen.createFooterFunc(2) }, { - name : 'Footer from H3', - icon : 'fas fa-dice-three', - gen : FooterGen.createFooter, - params : { headerSize: 3 } + name : 'Footer from H3', + icon : 'fas fa-dice-three', + gen : FooterGen.createFooterFunc(3) }, { - name : 'Footer from H4', - icon : 'fas fa-dice-four', - gen : FooterGen.createFooter, - params : { headerSize: 4 } + name : 'Footer from H4', + icon : 'fas fa-dice-four', + gen : FooterGen.createFooterFunc(4) }, { - name : 'Footer from H5', - icon : 'fas fa-dice-five', - gen : FooterGen.createFooter, - params : { headerSize: 5 } + name : 'Footer from H5', + icon : 'fas fa-dice-five', + gen : FooterGen.createFooterFunc(5) }, { - name : 'Footer from H6', - icon : 'fas fa-dice-six', - gen : FooterGen.createFooter, - params : { headerSize: 6 } + name : 'Footer from H6', + icon : 'fas fa-dice-six', + gen : FooterGen.createFooterFunc(6) } ] }, diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/5ePHB/snippets/footer.gen.js index 59c736836..6da003cb9 100644 --- a/themes/V3/5ePHB/snippets/footer.gen.js +++ b/themes/V3/5ePHB/snippets/footer.gen.js @@ -1,18 +1,19 @@ module.exports = { - createFooter : function(brew, params){ - const cursorPos = params.cursorPos; - const headerSize = params.headerSize || 1; + createFooterFunc : function(headerSize=1){ + return (props)=>{ + const cursorPos = props.cursorPos; - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); - } - header = header.concat(' '); + let header=''; + while (header.length < headerSize) { + header = header.concat('#'); + } + header = header.concat(' '); - const textArray = brew.text.split('\n').slice(0, cursorPos.line).reverse(); - const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = textArrayFilter[0]?.slice(header.length) || 'PART 1 | SECTION NAME'; + const textArray = props.brew.text.split('\n').slice(0, cursorPos.line).reverse(); + const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); + const text = textArrayFilter[0]?.slice(header.length).trim() || 'PART 1 | SECTION NAME'; - return `\n{{footnote ${text}}}\n`; + return `\n{{footnote ${text}}}\n`; + }; } }; \ No newline at end of file From e06f5e17d91a1d7f919caac15be6f391e93a2c23 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 15 Jun 2023 13:42:10 +1200 Subject: [PATCH 10/14] Relocate from 5ePHB to Blank theme --- themes/V3/5ePHB/snippets.js | 48 ------------------ themes/V3/Blank/snippets.js | 49 +++++++++++++++++-- .../{5ePHB => Blank}/snippets/footer.gen.js | 0 3 files changed, 46 insertions(+), 51 deletions(-) rename themes/V3/{5ePHB => Blank}/snippets/footer.gen.js (100%) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index e91e1f0ad..53bb6d3da 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -8,7 +8,6 @@ const ClassFeatureGen = require('./snippets/classfeature.gen.js'); const CoverPageGen = require('./snippets/coverpage.gen.js'); const TableOfContentsGen = require('./snippets/tableOfContents.gen.js'); const indexGen = require('./snippets/index.gen.js'); -const FooterGen = require('./snippets/footer.gen.js'); const dedent = require('dedent-tabs').default; @@ -20,53 +19,6 @@ module.exports = [ icon : 'fas fa-pencil-alt', view : 'text', snippets : [ - { - name : 'Page Number', - icon : 'fas fa-bookmark', - gen : '{{pageNumber 1}}\n{{footnote PART 1 | SECTION NAME}}\n\n' - }, - { - name : 'Auto-incrementing Page Number', - icon : 'fas fa-sort-numeric-down', - gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n' - }, - { - name : 'Footer', - icon : 'fas fa-shoe-prints', - gen : FooterGen.createFooterFunc(), - subsnippets : [ - { - name : 'Footer from H1', - icon : 'fas fa-dice-one', - gen : FooterGen.createFooterFunc(1) - }, - { - name : 'Footer from H2', - icon : 'fas fa-dice-two', - gen : FooterGen.createFooterFunc(2) - }, - { - name : 'Footer from H3', - icon : 'fas fa-dice-three', - gen : FooterGen.createFooterFunc(3) - }, - { - name : 'Footer from H4', - icon : 'fas fa-dice-four', - gen : FooterGen.createFooterFunc(4) - }, - { - name : 'Footer from H5', - icon : 'fas fa-dice-five', - gen : FooterGen.createFooterFunc(5) - }, - { - name : 'Footer from H6', - icon : 'fas fa-dice-six', - gen : FooterGen.createFooterFunc(6) - } - ] - }, { name : 'Table of Contents', icon : 'fas fa-book', diff --git a/themes/V3/Blank/snippets.js b/themes/V3/Blank/snippets.js index 5c51efa76..72372c297 100644 --- a/themes/V3/Blank/snippets.js +++ b/themes/V3/Blank/snippets.js @@ -2,6 +2,7 @@ const WatercolorGen = require('./snippets/watercolor.gen.js'); const ImageMaskGen = require('./snippets/imageMask.gen.js'); +const FooterGen = require('./snippets/footer.gen.js'); const dedent = require('dedent-tabs').default; module.exports = [ @@ -22,9 +23,51 @@ module.exports = [ gen : '\n\\page\n' }, { - name : 'Page Break with Footer', - icon : 'fas fa-file', - gen : '\n{{footnote PART 1 | SECTION NAME}}\n{{pageNumber,auto}}\n\n\\page\n' + name : 'Page Number', + icon : 'fas fa-bookmark', + gen : '{{pageNumber 1}}\n' + }, + { + name : 'Auto-incrementing Page Number', + icon : 'fas fa-sort-numeric-down', + gen : '{{pageNumber,auto}}\n' + }, + { + name : 'Footer', + icon : 'fas fa-shoe-prints', + gen : FooterGen.createFooterFunc(), + subsnippets : [ + { + name : 'Footer from H1', + icon : 'fas fa-dice-one', + gen : FooterGen.createFooterFunc(1) + }, + { + name : 'Footer from H2', + icon : 'fas fa-dice-two', + gen : FooterGen.createFooterFunc(2) + }, + { + name : 'Footer from H3', + icon : 'fas fa-dice-three', + gen : FooterGen.createFooterFunc(3) + }, + { + name : 'Footer from H4', + icon : 'fas fa-dice-four', + gen : FooterGen.createFooterFunc(4) + }, + { + name : 'Footer from H5', + icon : 'fas fa-dice-five', + gen : FooterGen.createFooterFunc(5) + }, + { + name : 'Footer from H6', + icon : 'fas fa-dice-six', + gen : FooterGen.createFooterFunc(6) + } + ] }, { name : 'Vertical Spacing', diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/Blank/snippets/footer.gen.js similarity index 100% rename from themes/V3/5ePHB/snippets/footer.gen.js rename to themes/V3/Blank/snippets/footer.gen.js From 949d763e352651e13da06cc4779530a4f2360147 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 23 Jun 2023 17:58:54 +1200 Subject: [PATCH 11/14] Detect heading from Markdown Lexer tokens --- themes/V3/Blank/snippets/footer.gen.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/themes/V3/Blank/snippets/footer.gen.js b/themes/V3/Blank/snippets/footer.gen.js index 6da003cb9..393151c1b 100644 --- a/themes/V3/Blank/snippets/footer.gen.js +++ b/themes/V3/Blank/snippets/footer.gen.js @@ -2,18 +2,17 @@ module.exports = { createFooterFunc : function(headerSize=1){ return (props)=>{ const cursorPos = props.cursorPos; + const renderer = props.brew.renderer || 'V3'; - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); - } - header = header.concat(' '); + const Markdown = renderer == 'V3' ? require('../../../../shared/naturalcrit/markdown.js') : require('../../../../shared/naturalcrit/markdownLegacy.js'); - const textArray = props.brew.text.split('\n').slice(0, cursorPos.line).reverse(); - const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = textArrayFilter[0]?.slice(header.length).trim() || 'PART 1 | SECTION NAME'; + const markdownText = props.brew.text.split('\n').slice(0, cursorPos.line).join('\n'); + const markdownTokens = Markdown.marked.lexer(markdownText); + const headerToken = markdownTokens.findLast((lexerToken)=>{ return lexerToken.type === 'heading' && lexerToken.depth === headerSize; }); + const headerText = headerToken?.tokens.map((token)=>{ return token.text; }).join(''); + const outputText = headerText || 'PART 1 | SECTION NAME'; - return `\n{{footnote ${text}}}\n`; + return `\n{{footnote ${outputText}}}\n`; }; } }; \ No newline at end of file From 62532f788e7d96871de4327c000d90cd5cf9c15f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 8 Jul 2023 01:42:47 -0400 Subject: [PATCH 12/14] Remove extra param sent to `execute()` --- client/homebrew/editor/snippetbar/snippetbar.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 6048af6b0..fee1a5780 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -15,8 +15,8 @@ ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js'); ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js'); ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js'); -const execute = function(val, brew, params){ - if(_.isFunction(val)) return val(brew, params); +const execute = function(val, props){ + if(_.isFunction(val)) return val(props); return val; }; From 96d04ad75a5b2c9d5abea525713567873959a127 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 8 Jul 2023 01:43:08 -0400 Subject: [PATCH 13/14] Fix TOC generators --- themes/Legacy/5ePHB/snippets/tableOfContents.gen.js | 4 ++-- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js b/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js index 4082ac4ef..40d64af22 100644 --- a/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js @@ -47,8 +47,8 @@ const getTOC = (pages)=>{ return res; }; -module.exports = function(brew){ - const pages = brew.text.split('\\page'); +module.exports = function(props){ + const pages = props.brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`); diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 1c52d5cf7..44605c05d 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -48,8 +48,8 @@ const getTOC = (pages)=>{ return res; }; -module.exports = function(brew){ - const pages = brew.text.split('\\page'); +module.exports = function(props){ + const pages = props.brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ if(g1.title !== null) { From 3140299d73d9a0622095fd66618cd1489e33a678 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 8 Jul 2023 01:48:49 -0400 Subject: [PATCH 14/14] Renderer is always V3. No need to check. --- themes/V3/Blank/snippets/footer.gen.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/themes/V3/Blank/snippets/footer.gen.js b/themes/V3/Blank/snippets/footer.gen.js index 393151c1b..6583cd06e 100644 --- a/themes/V3/Blank/snippets/footer.gen.js +++ b/themes/V3/Blank/snippets/footer.gen.js @@ -1,10 +1,9 @@ +const Markdown = require('../../../../shared/naturalcrit/markdown.js'); + module.exports = { createFooterFunc : function(headerSize=1){ return (props)=>{ const cursorPos = props.cursorPos; - const renderer = props.brew.renderer || 'V3'; - - const Markdown = renderer == 'V3' ? require('../../../../shared/naturalcrit/markdown.js') : require('../../../../shared/naturalcrit/markdownLegacy.js'); const markdownText = props.brew.text.split('\n').slice(0, cursorPos.line).join('\n'); const markdownTokens = Markdown.marked.lexer(markdownText);