mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 09:52:41 +00:00
Add params from snippet to function
This commit is contained in:
@@ -167,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, { cursorPos: this.props.cursorPos }));
|
this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { ...snippet.params, cursorPos: this.props.cursorPos }));
|
||||||
},
|
},
|
||||||
renderSnippets : function(snippets){
|
renderSnippets : function(snippets){
|
||||||
return _.map(snippets, (snippet)=>{
|
return _.map(snippets, (snippet)=>{
|
||||||
|
|||||||
@@ -31,9 +31,47 @@ module.exports = [
|
|||||||
gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n'
|
gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'Footer',
|
name : 'Footer',
|
||||||
icon : 'fas fa-sort-numeric-down',
|
icon : 'fas fa-shoe-prints',
|
||||||
gen : FooterGen
|
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',
|
name : 'Table of Contents',
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
module.exports = function(brew, params){
|
module.exports = {
|
||||||
const cursorPos = params.cursorPos;
|
createFooter : function(brew, params){
|
||||||
const headerSize = params.headerSize || 1;
|
const cursorPos = params.cursorPos;
|
||||||
|
const headerSize = params.headerSize || 1;
|
||||||
|
|
||||||
let header='';
|
let header='';
|
||||||
while (header.length < headerSize) {
|
while (header.length < headerSize) {
|
||||||
header = header.concat('#');
|
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`;
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user