Created
December 12, 2018 15:42
-
-
Save DanyelMorales/15b0e3caef4ee21c75ff8d90f138f9c7 to your computer and use it in GitHub Desktop.
find Elements start with @
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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