Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Created December 12, 2018 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyelMorales/15b0e3caef4ee21c75ff8d90f138f9c7 to your computer and use it in GitHub Desktop.
Save DanyelMorales/15b0e3caef4ee21c75ff8d90f138f9c7 to your computer and use it in GitHub Desktop.
find Elements start with @
Parser.prototype.findElements = function(block, filename) {
var elements = [];
// Replace Linebreak with Unicode
block = block.replace(/\n/g, '\uffff');
// Elements start with @
var elementsRegExp = /(@(\w*)\s?(.+?)(?=\uffff[\s\*]*@|$))/gm;
var matches = elementsRegExp.exec(block);
while (matches) {
var element = {
source : matches[1],
name : matches[2].toLowerCase(),
sourceName: matches[2],
content : matches[3]
};
// reverse Unicode Linebreaks
element.content = element.content.replace(/\uffff/g, '\n');
element.source = element.source.replace(/\uffff/g, '\n');
app.hook('parser-find-element-' + element.name, element, block, filename);
elements.push(element);
app.hook('parser-find-elements', elements, element, block, filename);
// next Match
matches = elementsRegExp.exec(block);
}
return elements;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment