mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 14:12:43 +00:00
Merge pull request #1485 from naturalcrit/MustacheSyntaxUsesColons
Mustache syntax to use colons
This commit is contained in:
@@ -131,7 +131,7 @@ const Editor = createClass({
|
|||||||
|
|
||||||
// Highlight inline spans {{content}}
|
// Highlight inline spans {{content}}
|
||||||
if(line.includes('{{') && line.includes('}}')){
|
if(line.includes('{{') && line.includes('}}')){
|
||||||
const regex = /{{(?:="[\w,\-. ]*"|[^"'\s])*\s*|}}/g;
|
const regex = /{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])*\s*|}}/g;
|
||||||
let match;
|
let match;
|
||||||
let blockCount = 0;
|
let blockCount = 0;
|
||||||
while ((match = regex.exec(line)) != null) {
|
while ((match = regex.exec(line)) != null) {
|
||||||
@@ -150,7 +150,7 @@ const Editor = createClass({
|
|||||||
// Highlight block divs {{\n Content \n}}
|
// Highlight block divs {{\n Content \n}}
|
||||||
let endCh = line.length+1;
|
let endCh = line.length+1;
|
||||||
|
|
||||||
const match = line.match(/^ *{{(?:="[\w,\-. ]*"|[^"'\s])*$|^ *}}$/);
|
const match = line.match(/^ *{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])* *$|^ *}}$/);
|
||||||
if(match)
|
if(match)
|
||||||
endCh = match.index+match[0].length;
|
endCh = match.index+match[0].length;
|
||||||
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
|
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module.exports = [
|
|||||||
{
|
{
|
||||||
name : 'Horizontal Spacing',
|
name : 'Horizontal Spacing',
|
||||||
icon : 'fas fa-arrows-alt-h',
|
icon : 'fas fa-arrows-alt-h',
|
||||||
gen : ' {{width="100px"}} '
|
gen : ' {{width:100px}} '
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'Wide Block',
|
name : 'Wide Block',
|
||||||
@@ -51,23 +51,22 @@ module.exports = [
|
|||||||
name : 'Image',
|
name : 'Image',
|
||||||
icon : 'fas fa-image',
|
icon : 'fas fa-image',
|
||||||
gen : dedent`
|
gen : dedent`
|
||||||
 {width="325px"}
|
 {width:325px}
|
||||||
Credit: Kyounghwan Kim`
|
Credit: Kyounghwan Kim`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'Background Image',
|
name : 'Background Image',
|
||||||
icon : 'fas fa-tree',
|
icon : 'fas fa-tree',
|
||||||
gen : ` {position="absolute",top="50px",right="30px",width="280px"}`
|
gen : ` {position:absolute,top:50px,right:30px,width:280px}`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'QR Code',
|
name : 'QR Code',
|
||||||
icon : 'fas fa-qrcode',
|
icon : 'fas fa-qrcode',
|
||||||
gen : (brew)=>{
|
gen : (brew)=>{
|
||||||
return `<img ` +
|
return `![]` +
|
||||||
`src='https://api.qrserver.com/v1/create-qr-code/?data=` +
|
`(https://api.qrserver.com/v1/create-qr-code/?data=` +
|
||||||
`https://homebrewery.naturalcrit.com/share/${brew.shareId}` +
|
`https://homebrewery.naturalcrit.com/share/${brew.shareId}` +
|
||||||
`&size=100x100' ` +
|
`&size=100x100) {width:100px;mix-blend-mode:multiply}`;
|
||||||
`style='width:100px;mix-blend-mode:multiply'/>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -257,7 +256,7 @@ module.exports = [
|
|||||||
gen : function(){
|
gen : function(){
|
||||||
return dedent`
|
return dedent`
|
||||||
##### Typical Difficulty Classes
|
##### Typical Difficulty Classes
|
||||||
{{column-count="2"
|
{{column-count:2
|
||||||
| Task Difficulty | DC |
|
| Task Difficulty | DC |
|
||||||
|:----------------|:--:|
|
|:----------------|:--:|
|
||||||
| Very easy | 5 |
|
| Very easy | 5 |
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const mustacheSpans = {
|
|||||||
start(src) { return src.match(/{{[^{]/)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/{{[^{]/)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
const completeSpan = /^{{[^\n]*}}/; // Regex for the complete token
|
const completeSpan = /^{{[^\n]*}}/; // Regex for the complete token
|
||||||
const inlineRegex = /{{(?:="[\w,\-()#%. ]*"|[^"'{}\s])*\s*|}}/g;
|
const inlineRegex = /{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])*\s*|}}/g;
|
||||||
const match = completeSpan.exec(src);
|
const match = completeSpan.exec(src);
|
||||||
if(match) {
|
if(match) {
|
||||||
//Find closing delimiter
|
//Find closing delimiter
|
||||||
@@ -76,8 +76,8 @@ const mustacheDivs = {
|
|||||||
level : 'block',
|
level : 'block',
|
||||||
start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
const completeBlock = /^ *{{[^\s}]*\n.*\n *}}/s; // Regex for the complete token
|
const completeBlock = /^ *{{[^\s}]* *\n.*\n *}}/s; // Regex for the complete token
|
||||||
const blockRegex = /^ *{{(?:="[\w,\-()#%. ]*"|[^"'{}\s])*$|^ *}}$/gm;
|
const blockRegex = /^ *{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])* *$|^ *}}$/gm;
|
||||||
const match = completeBlock.exec(src);
|
const match = completeBlock.exec(src);
|
||||||
if(match) {
|
if(match) {
|
||||||
//Find closing delimiter
|
//Find closing delimiter
|
||||||
@@ -121,7 +121,7 @@ const mustacheInjectInline = {
|
|||||||
level : 'inline',
|
level : 'inline',
|
||||||
start(src) { return src.match(/ *{[^{\n]/)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/ *{[^{\n]/)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
const inlineRegex = /^ *{((?:="[\w,\-()#%. ]*"|[^"'{}\s])*)}/g;
|
const inlineRegex = /^ *{((?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])*)}/g;
|
||||||
const match = inlineRegex.exec(src);
|
const match = inlineRegex.exec(src);
|
||||||
if(match) {
|
if(match) {
|
||||||
const lastToken = tokens[tokens.length - 1];
|
const lastToken = tokens[tokens.length - 1];
|
||||||
@@ -156,7 +156,7 @@ const mustacheInjectBlock = {
|
|||||||
level : 'block',
|
level : 'block',
|
||||||
start(src) { return src.match(/\n *{[^{\n]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/\n *{[^{\n]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
const inlineRegex = /^ *{((?:="[\w,\-()#%. ]*"|[^"'{}\s])*)}/ym;
|
const inlineRegex = /^ *{((?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])*)}/ym;
|
||||||
const match = inlineRegex.exec(src);
|
const match = inlineRegex.exec(src);
|
||||||
if(match) {
|
if(match) {
|
||||||
const lastToken = tokens[tokens.length - 1];
|
const lastToken = tokens[tokens.length - 1];
|
||||||
@@ -313,13 +313,15 @@ const tagRegex = new RegExp(`(${
|
|||||||
}).join('|')})`, 'g');
|
}).join('|')})`, 'g');
|
||||||
|
|
||||||
const processStyleTags = (string)=>{
|
const processStyleTags = (string)=>{
|
||||||
const tags = string.match(/(?:[^, "=]+|="[^"]*")+/g);
|
//split tags up. quotes can only occur right after colons.
|
||||||
|
//TODO: can we simplify to just split on commas?
|
||||||
|
const tags = string.match(/(?:[^, ":]+|:(?:"[^"]*"|))+/g);
|
||||||
|
|
||||||
if(!tags) return '"';
|
if(!tags) return '"';
|
||||||
|
|
||||||
const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0];
|
const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0];
|
||||||
const classes = _.remove(tags, (tag)=>!tag.includes('"'));
|
const classes = _.remove(tags, (tag)=>!tag.includes(':'));
|
||||||
const styles = tags.map((tag)=>tag.replace(/="(.*)"/g, ':$1;'));
|
const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;'));
|
||||||
return `${classes.join(' ')}" ${id ? `id="${id}"` : ''} ${styles.length ? `style="${styles.join(' ')}"` : ''}`;
|
return `${classes.join(' ')}" ${id ? `id="${id}"` : ''} ${styles.length ? `style="${styles.join(' ')}"` : ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -602,7 +602,7 @@ body {
|
|||||||
break-inside : avoid;
|
break-inside : avoid;
|
||||||
-webkit-transform : translateZ(0); //Prevents shadows from breaking across columns
|
-webkit-transform : translateZ(0); //Prevents shadows from breaking across columns
|
||||||
}
|
}
|
||||||
.inline {
|
.inline-block {
|
||||||
display : inline-block;
|
display : inline-block;
|
||||||
text-indent : initial;
|
text-indent : initial;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user