0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 06:32:39 +00:00

Added new lexer for handling the new block syntax

This commit is contained in:
Scott Tolksdorf
2017-01-12 01:19:08 -05:00
parent 97c0443c76
commit c8b089f7fb
4 changed files with 53 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
const _ = require('lodash');
const flux = require('pico-flux');
const Markdown = require('homebrewery/markdown.js');
const Markdown = require('homebrewery/markdown.new.js');
let State = {
version : '0.0.0',
@@ -30,7 +30,6 @@ const Store = flux.createStore({
State.brew = brew;
},
UPDATE_BREW_TEXT : (brewText) => {
console.log(State);
State.brew.text = brewText;
State.errors = Markdown.validate(brewText);
},

View File

@@ -2,7 +2,7 @@ const React = require('react');
const _ = require('lodash');
const cx = require('classnames');
const Markdown = require('homebrewery/markdown.js');
const Markdown = require('homebrewery/markdown.new.js');
const ErrorBar = require('./errorBar/errorBar.jsx');
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')

View File

@@ -1,9 +1,12 @@
var _ = require('lodash');
var Markdown = require('marked');
var renderer = new Markdown.Renderer();
const _ = require('lodash');
const Markdown = require('marked');
/*
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
console.log(html);
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
var openTag = html.substring(0, html.indexOf('>')+1);
html = html.substring(html.indexOf('>')+1);
@@ -12,22 +15,59 @@ renderer.html = function (html) {
}
return html;
};
*/
const tagTypes = ['div', 'span', 'a'];
const tagRegex = new RegExp('(' +
_.map(tagTypes, (type)=>{
return `\\<${type}|\\</${type}>`;
}).join('|') + ')', 'g');
module.exports = {
marked : Markdown,
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) => {
return [];
/*
var errors = [];
var leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber) => {
var lineNumber = _lineNumber + 1;
@@ -77,6 +117,7 @@ module.exports = {
});
return errors;
*/
},
};

View File

@@ -29,7 +29,7 @@ var CodeEditor = React.createClass({
value : this.props.value,
lineNumbers: true,
lineWrapping : this.props.wrap,
mode : this.props.language
mode : this.props.language,
});
this.codeMirror.on('change', this.handleChange);