mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 08:32:44 +00:00
Added new lexer for handling the new block syntax
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const flux = require('pico-flux');
|
const flux = require('pico-flux');
|
||||||
|
|
||||||
const Markdown = require('homebrewery/markdown.js');
|
const Markdown = require('homebrewery/markdown.new.js');
|
||||||
|
|
||||||
let State = {
|
let State = {
|
||||||
version : '0.0.0',
|
version : '0.0.0',
|
||||||
@@ -30,7 +30,6 @@ const Store = flux.createStore({
|
|||||||
State.brew = brew;
|
State.brew = brew;
|
||||||
},
|
},
|
||||||
UPDATE_BREW_TEXT : (brewText) => {
|
UPDATE_BREW_TEXT : (brewText) => {
|
||||||
console.log(State);
|
|
||||||
State.brew.text = brewText;
|
State.brew.text = brewText;
|
||||||
State.errors = Markdown.validate(brewText);
|
State.errors = Markdown.validate(brewText);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const React = require('react');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const Markdown = require('homebrewery/markdown.js');
|
const Markdown = require('homebrewery/markdown.new.js');
|
||||||
const ErrorBar = require('./errorBar/errorBar.jsx');
|
const ErrorBar = require('./errorBar/errorBar.jsx');
|
||||||
|
|
||||||
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')
|
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
var _ = require('lodash');
|
const _ = require('lodash');
|
||||||
var Markdown = require('marked');
|
const Markdown = require('marked');
|
||||||
var renderer = new Markdown.Renderer();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
//Processes the markdown within an HTML block if it's just a class-wrapper
|
//Processes the markdown within an HTML block if it's just a class-wrapper
|
||||||
renderer.html = function (html) {
|
renderer.html = function (html) {
|
||||||
|
console.log(html);
|
||||||
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
|
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
|
||||||
var openTag = html.substring(0, html.indexOf('>')+1);
|
var openTag = html.substring(0, html.indexOf('>')+1);
|
||||||
html = html.substring(html.indexOf('>')+1);
|
html = html.substring(html.indexOf('>')+1);
|
||||||
@@ -12,22 +15,59 @@ renderer.html = function (html) {
|
|||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
const tagTypes = ['div', 'span', 'a'];
|
|
||||||
const tagRegex = new RegExp('(' +
|
|
||||||
_.map(tagTypes, (type)=>{
|
|
||||||
return `\\<${type}|\\</${type}>`;
|
|
||||||
}).join('|') + ')', 'g');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
marked : Markdown,
|
marked : Markdown,
|
||||||
render : (rawBrewText)=>{
|
render : (rawBrewText)=>{
|
||||||
return Markdown(rawBrewText, {renderer : renderer})
|
//Adds in the new div block syntax
|
||||||
|
let count = 0;
|
||||||
|
let blockReg = /{{\w+|}}/g;
|
||||||
|
const renderer = new Markdown.Renderer();
|
||||||
|
renderer.paragraph = function (text) {
|
||||||
|
const matches = text.match(blockReg);
|
||||||
|
if(!matches) return `<p>${text}</p>\n`;
|
||||||
|
let matchIndex = 0;
|
||||||
|
const res = _.reduce(text.split(blockReg), (r, text) => {
|
||||||
|
if(text) r.push(`<p>${text}</p>\n`);
|
||||||
|
const block = matches[matchIndex];
|
||||||
|
if(block && _.startsWith(block, '{{')){
|
||||||
|
r.push(`<div class="${block.substring(2)}">`);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if(block == '}}' && count !== 0){
|
||||||
|
r.push('</div>');
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
matchIndex++;
|
||||||
|
return r;
|
||||||
|
}, []).join('\n');
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
let html = Markdown(rawBrewText, {renderer : renderer, sanitize: true});
|
||||||
|
html += _.times(count, ()=>{return '</div>'}).join('\n');
|
||||||
|
return html;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
validate : (rawBrewText) => {
|
validate : (rawBrewText) => {
|
||||||
|
return [];
|
||||||
|
/*
|
||||||
var errors = [];
|
var errors = [];
|
||||||
var leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber) => {
|
var leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber) => {
|
||||||
var lineNumber = _lineNumber + 1;
|
var lineNumber = _lineNumber + 1;
|
||||||
@@ -77,6 +117,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ var CodeEditor = React.createClass({
|
|||||||
value : this.props.value,
|
value : this.props.value,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
lineWrapping : this.props.wrap,
|
lineWrapping : this.props.wrap,
|
||||||
mode : this.props.language
|
mode : this.props.language,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.codeMirror.on('change', this.handleChange);
|
this.codeMirror.on('change', this.handleChange);
|
||||||
|
|||||||
Reference in New Issue
Block a user