mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 11:22:40 +00:00
Merge pull request #2417 from G-Ambatte/addSmartPageBreak-#2289
Add smarter footer shortcut/snippet
This commit is contained in:
@@ -323,7 +323,8 @@ const Editor = createClass({
|
|||||||
theme={this.props.brew.theme}
|
theme={this.props.brew.theme}
|
||||||
undo={this.undo}
|
undo={this.undo}
|
||||||
redo={this.redo}
|
redo={this.redo}
|
||||||
historySize={this.historySize()} />
|
historySize={this.historySize()}
|
||||||
|
cursorPos={this.refs.codeEditor?.getCursorPosition() || {}} />
|
||||||
|
|
||||||
{this.renderEditor()}
|
{this.renderEditor()}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js');
|
|||||||
ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js');
|
ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js');
|
||||||
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
||||||
|
|
||||||
const execute = function(val, brew){
|
const execute = function(val, props){
|
||||||
if(_.isFunction(val)) return val(brew);
|
if(_.isFunction(val)) return val(props);
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,7 +33,8 @@ const Snippetbar = createClass({
|
|||||||
renderer : 'legacy',
|
renderer : 'legacy',
|
||||||
undo : ()=>{},
|
undo : ()=>{},
|
||||||
redo : ()=>{},
|
redo : ()=>{},
|
||||||
historySize : ()=>{}
|
historySize : ()=>{},
|
||||||
|
cursorPos : {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ const Snippetbar = createClass({
|
|||||||
snippets={snippetGroup.snippets}
|
snippets={snippetGroup.snippets}
|
||||||
key={snippetGroup.groupName}
|
key={snippetGroup.groupName}
|
||||||
onSnippetClick={this.handleSnippetClick}
|
onSnippetClick={this.handleSnippetClick}
|
||||||
|
cursorPos={this.props.cursorPos}
|
||||||
/>;
|
/>;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -165,7 +167,7 @@ const SnippetGroup = createClass({
|
|||||||
},
|
},
|
||||||
handleSnippetClick : function(e, snippet){
|
handleSnippetClick : function(e, snippet){
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.props.onSnippetClick(execute(snippet.gen, this.props.brew));
|
this.props.onSnippetClick(execute(snippet.gen, this.props));
|
||||||
},
|
},
|
||||||
renderSnippets : function(snippets){
|
renderSnippets : function(snippets){
|
||||||
return _.map(snippets, (snippet)=>{
|
return _.map(snippets, (snippet)=>{
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ const CodeEditor = createClass({
|
|||||||
|
|
||||||
indent : function () {
|
indent : function () {
|
||||||
const cm = this.codeMirror;
|
const cm = this.codeMirror;
|
||||||
if (cm.somethingSelected()) {
|
if(cm.somethingSelected()) {
|
||||||
cm.execCommand('indentMore');
|
cm.execCommand('indentMore');
|
||||||
} else {
|
} else {
|
||||||
cm.execCommand('insertSoftTab');
|
cm.execCommand('insertSoftTab');
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ const getTOC = (pages)=>{
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(brew){
|
module.exports = function(props){
|
||||||
const pages = brew.text.split('\\page');
|
const pages = props.brew.text.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
||||||
|
|||||||
@@ -19,16 +19,6 @@ module.exports = [
|
|||||||
icon : 'fas fa-pencil-alt',
|
icon : 'fas fa-pencil-alt',
|
||||||
view : 'text',
|
view : 'text',
|
||||||
snippets : [
|
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 : 'Table of Contents',
|
name : 'Table of Contents',
|
||||||
icon : 'fas fa-book',
|
icon : 'fas fa-book',
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ const getTOC = (pages)=>{
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(brew){
|
module.exports = function(props){
|
||||||
const pages = brew.text.split('\\page');
|
const pages = props.brew.text.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
if(g1.title !== null) {
|
if(g1.title !== null) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const WatercolorGen = require('./snippets/watercolor.gen.js');
|
const WatercolorGen = require('./snippets/watercolor.gen.js');
|
||||||
const ImageMaskGen = require('./snippets/imageMask.gen.js');
|
const ImageMaskGen = require('./snippets/imageMask.gen.js');
|
||||||
|
const FooterGen = require('./snippets/footer.gen.js');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
@@ -21,6 +22,53 @@ module.exports = [
|
|||||||
icon : 'fas fa-file-alt',
|
icon : 'fas fa-file-alt',
|
||||||
gen : '\n\\page\n'
|
gen : '\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',
|
name : 'Vertical Spacing',
|
||||||
icon : 'fas fa-arrows-alt-v',
|
icon : 'fas fa-arrows-alt-v',
|
||||||
|
|||||||
17
themes/V3/Blank/snippets/footer.gen.js
Normal file
17
themes/V3/Blank/snippets/footer.gen.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const Markdown = require('../../../../shared/naturalcrit/markdown.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createFooterFunc : function(headerSize=1){
|
||||||
|
return (props)=>{
|
||||||
|
const cursorPos = props.cursorPos;
|
||||||
|
|
||||||
|
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 ${outputText}}}\n`;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user