mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-17 16:42:41 +00:00
Fix fouled up regex that only worked by accident
This commit is contained in:
@@ -4,20 +4,22 @@ import request from '../client/homebrew/utils/request-middleware.js';
|
|||||||
|
|
||||||
// Convert the templates from a brew to a Snippets Structure.
|
// Convert the templates from a brew to a Snippets Structure.
|
||||||
const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets=null, full=true)=>{
|
const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets=null, full=true)=>{
|
||||||
const textSplit = /^\\snippet +/gm;
|
const textSplit = /^(\\snippet +.+\n)/gm;
|
||||||
const mpAsSnippets = [];
|
const mpAsSnippets = [];
|
||||||
// Snippets from Themes first.
|
// Snippets from Themes first.
|
||||||
if(themeBundleSnippets) {
|
if(themeBundleSnippets) {
|
||||||
for (let themes of themeBundleSnippets) {
|
for (let themes of themeBundleSnippets) {
|
||||||
if(typeof themes !== 'string') {
|
if(typeof themes !== 'string') {
|
||||||
const userSnippets = [];
|
const userSnippets = [];
|
||||||
for (let snips of themes.snippets.trim().split(textSplit)) {
|
const snipSplit = themes.snippets.trim().split(textSplit).slice(1);
|
||||||
const name = snips.trim().split('\n')[0];
|
for (let snips = 0; snips < snipSplit.length; snips+=2) {
|
||||||
if(name.length != 0) {
|
if(!snipSplit[snips].startsWith('\\snippet ')) break;
|
||||||
|
const snippetName = snipSplit[snips].split(/\\snippet +/)[1].split('\n')[0].trim();
|
||||||
|
if(snippetName.length != 0) {
|
||||||
userSnippets.push({
|
userSnippets.push({
|
||||||
name : name,
|
name : snippetName,
|
||||||
icon : '',
|
icon : '',
|
||||||
gen : snips.slice(name.length + 1).trim(),
|
gen : snipSplit[snips + 1],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,16 +37,14 @@ const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets=nul
|
|||||||
// Local Snippets
|
// Local Snippets
|
||||||
if(userBrewSnippets) {
|
if(userBrewSnippets) {
|
||||||
const userSnippets = [];
|
const userSnippets = [];
|
||||||
for (let snips of userBrewSnippets.trim().split(textSplit)) {
|
const snipSplit = userBrewSnippets.trim().split(textSplit).slice(1);
|
||||||
let name = snips.split('\n')[0];
|
for (let snips = 0; snips < snipSplit.length; snips+=2) {
|
||||||
let justSnippet = snips.slice(name.length + 1);
|
if(!snipSplit[snips].startsWith('\\snippet ')) break;
|
||||||
if(justSnippet.slice(-1) === '\n') {
|
const snippetName = snipSplit[snips].split(/\\snippet +/)[1].split('\n')[0].trim();
|
||||||
justSnippet = justSnippet.slice(0, -1);
|
if(snippetName.length != 0) {
|
||||||
}
|
|
||||||
if(name.length != 0) {
|
|
||||||
const subSnip = {
|
const subSnip = {
|
||||||
name : name,
|
name : snippetName,
|
||||||
gen : justSnippet,
|
gen : snipSplit[snips + 1],
|
||||||
};
|
};
|
||||||
// if(full) subSnip.icon = '';
|
// if(full) subSnip.icon = '';
|
||||||
userSnippets.push(subSnip);
|
userSnippets.push(subSnip);
|
||||||
|
|||||||
Reference in New Issue
Block a user