mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 10:52:46 +00:00
Merge branch 'master' into UpdateSolberaImitationFont
This commit is contained in:
@@ -34,7 +34,11 @@ const CodeEditor = createClass({
|
||||
mode : this.props.language,
|
||||
extraKeys : {
|
||||
'Ctrl-B' : this.makeBold,
|
||||
'Ctrl-I' : this.makeItalic
|
||||
'Cmd-B' : this.makeBold,
|
||||
'Ctrl-I' : this.makeItalic,
|
||||
'Cmd-I' : this.makeItalic,
|
||||
'Ctrl-M' : this.makeSpan,
|
||||
'Cmd-M' : this.makeSpan,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,8 +48,8 @@ const CodeEditor = createClass({
|
||||
},
|
||||
|
||||
makeBold : function() {
|
||||
const selection = this.codeMirror.getSelection();
|
||||
this.codeMirror.replaceSelection(`**${selection}**`, 'around');
|
||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '**' && selection.slice(-2) === '**';
|
||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `**${selection}**`, 'around');
|
||||
if(selection.length === 0){
|
||||
const cursor = this.codeMirror.getCursor();
|
||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
|
||||
@@ -53,14 +57,23 @@ const CodeEditor = createClass({
|
||||
},
|
||||
|
||||
makeItalic : function() {
|
||||
const selection = this.codeMirror.getSelection();
|
||||
this.codeMirror.replaceSelection(`*${selection}*`, 'around');
|
||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '_' && selection.slice(-1) === '_';
|
||||
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `_${selection}_`, 'around');
|
||||
if(selection.length === 0){
|
||||
const cursor = this.codeMirror.getCursor();
|
||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 });
|
||||
}
|
||||
},
|
||||
|
||||
makeSpan : function() {
|
||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{ ${selection}}}`, 'around');
|
||||
if(selection.length === 0){
|
||||
const cursor = this.codeMirror.getCursor();
|
||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
|
||||
}
|
||||
},
|
||||
|
||||
componentDidUpdate : function(prevProps) {
|
||||
if(this.codeMirror && this.codeMirror.getValue() != this.props.value) {
|
||||
this.codeMirror.setValue(this.props.value);
|
||||
|
||||
@@ -11,56 +11,31 @@ renderer.html = function (html) {
|
||||
html = html.substring(0, html.lastIndexOf('</div>'));
|
||||
return `${openTag} ${Markdown(html)} </div>`;
|
||||
}
|
||||
// if(_.startsWith(_.trim(html), '<style') && _.endsWith(_.trim(html), '</style>')){
|
||||
// const openTag = html.substring(0, html.indexOf('>')+1);
|
||||
// html = html.substring(html.indexOf('>')+1);
|
||||
// html = html.substring(0, html.lastIndexOf('</style>'));
|
||||
// html = html.replaceAll(/\s(\.[^{]*)/gm, '.V3 $1');
|
||||
// return `${openTag} ${html} </style>`;
|
||||
// }
|
||||
return html;
|
||||
};
|
||||
|
||||
// Ensure {{ Divs don't confuse paragraph parsing (else it renders empty paragraphs)
|
||||
// Don't wrap {{ Divs or {{ empty Spans in <p> tags
|
||||
renderer.paragraph = function(text){
|
||||
let match;
|
||||
if(text.startsWith('<div') || text.startsWith('</div'))
|
||||
return `${text}`;
|
||||
else if(match = text.match(/(^|^.*?\n)<span class="inline([^>]*><\/span>)$/))
|
||||
return `<p>${match[1]}</p><span class="inline-block"${match[2]}`;
|
||||
else
|
||||
return `<p>${text}</p>\n`;
|
||||
};
|
||||
|
||||
// Mustache-style Divs {{class \n content ... \n}}
|
||||
let blockCount = 0;
|
||||
const blockRegex = /^ *{{(?:="[\w, ]*"|[^"'\s])*$|^ *}}$/gm;
|
||||
const blockRegex = /^ *{{(?:="[\w,\-. ]*"|[^"'\s])*$|^ *}}$/gm;
|
||||
const inlineFullRegex = /{{[^\n]*}}/g;
|
||||
const inlineRegex = /{{(?:="[\w, ]*"|[^"'\s])*\s*|}}/g;
|
||||
const inlineRegex = /{{(?:="[\w,\-. ]*"|[^"'{}}\s])*\s*|}}/g;
|
||||
|
||||
renderer.text = function(text){
|
||||
const newText = text.replaceAll('"', '"');
|
||||
let matches;
|
||||
|
||||
//DIV - BLOCK-LEVEL
|
||||
if(matches = newText.match(blockRegex)) {
|
||||
let matchIndex = 0;
|
||||
const res = _.reduce(newText.split(blockRegex), (r, splitText)=>{
|
||||
if(splitText) r.push(Markdown.parseInline(splitText, { renderer: renderer }));
|
||||
|
||||
const block = matches[matchIndex] ? matches[matchIndex].trimLeft() : '';
|
||||
if(block && block.startsWith('{')) {
|
||||
const values = processStyleTags(block.substring(2));
|
||||
r.push(`<div class="block ${values}">`);
|
||||
blockCount++;
|
||||
} else if(block == '}}' && blockCount !== 0){
|
||||
r.push('</div>');
|
||||
blockCount--;
|
||||
}
|
||||
|
||||
matchIndex++;
|
||||
|
||||
return r;
|
||||
}, []).join('');
|
||||
return res;
|
||||
} else if(matches = newText.match(inlineFullRegex)) {
|
||||
if(matches = newText.match(inlineFullRegex)) {
|
||||
|
||||
//SPAN - INLINE
|
||||
matches = newText.match(inlineRegex);
|
||||
@@ -72,7 +47,7 @@ renderer.text = function(text){
|
||||
const block = matches[matchIndex] ? matches[matchIndex].trimLeft() : '';
|
||||
if(block && block.startsWith('{{')) {
|
||||
const values = processStyleTags(block.substring(2));
|
||||
r.push(`<span class="inline-block ${values}>`);
|
||||
r.push(`<span class="inline ${values}>`);
|
||||
blockCount++;
|
||||
} else if(block == '}}' && blockCount !== 0){
|
||||
r.push('</span>');
|
||||
@@ -84,7 +59,28 @@ renderer.text = function(text){
|
||||
return r;
|
||||
}, []).join('');
|
||||
return `${res}`;
|
||||
} else {
|
||||
} else if(matches = newText.match(blockRegex)) {
|
||||
//DIV - BLOCK-LEVEL
|
||||
let matchIndex = 0;
|
||||
const res = _.reduce(newText.split(blockRegex), (r, splitText)=>{
|
||||
if(splitText) r.push(Markdown.parseInline(splitText, { renderer: renderer }));
|
||||
|
||||
const block = matches[matchIndex] ? matches[matchIndex].trimLeft() : '';
|
||||
if(block && block.startsWith('{')) {
|
||||
const values = processStyleTags(block.substring(2));
|
||||
r.push(`<div class="block ${values}">`);
|
||||
blockCount++;
|
||||
} else if(block == '}}' && blockCount !== 0){
|
||||
r.push('</div>');
|
||||
blockCount--;
|
||||
}
|
||||
|
||||
matchIndex++;
|
||||
|
||||
return r;
|
||||
}, []).join('');
|
||||
return res;
|
||||
} else {
|
||||
if(!matches) {
|
||||
return `${text}`;
|
||||
}
|
||||
@@ -188,9 +184,13 @@ module.exports = {
|
||||
marked : Markdown,
|
||||
render : (rawBrewText)=>{
|
||||
blockCount = 0;
|
||||
rawBrewText = rawBrewText.replace(/^\\column/gm, `<div class='columnSplit'></div>`)
|
||||
rawBrewText = rawBrewText.replace(/^\\column$/gm, `<div class='columnSplit'></div>`)
|
||||
.replace(/^(:+)$/gm, (match)=>`${`<div class='blank'></div>`.repeat(match.length)}\n`)
|
||||
.replace(/(?:^|>) *:([^:\n]*):([^\n]*)\n/gm, (match, term, def)=>`<dt>${Markdown.parseInline(term)}</dt><dd>${def}</dd>`)
|
||||
.replace(/(<dt>.*<\/dt><dd>.*<\/dd>\n?)+/gm, `<dl>$1</dl>\n\n`)
|
||||
.replace(/^}}/gm, '\n}}')
|
||||
.replace(/^({{[^\n]*)$/gm, '$1\n');
|
||||
console.log(rawBrewText);
|
||||
return Markdown(
|
||||
sanatizeScriptTags(rawBrewText),
|
||||
{ renderer: renderer }
|
||||
|
||||
Reference in New Issue
Block a user