made with requirebin
Last active
August 24, 2017 20:08
-
-
Save raghunandangupta1992/112a26ae5d1c7ab3c632576b6eac4106 to your computer and use it in GitHub Desktop.
requirebin sketch
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
// Welcome! require() some modules from npm (like you were using browserify) | |
// and then hit Run Code to run your code on the right side. | |
// Modules get downloaded from browserify-cdn and bundled in your browser. | |
var text = "initial text <b>tag 1 ka text</b> bwala word ka text <b>tag 2 ka text</b> left off text"; | |
var HtmlParser = function(textToParse, tagToPick) { | |
var openTag = tagToPick; | |
var closetag = tagToPick[0] + '/' + tagToPick.substr(1); | |
var splitArray = text.split(openTag); | |
var textArray = []; | |
var textObject = []; | |
if (splitArray[0].indexOf(closetag) === -1) { | |
textObject.startText = splitArray[0]; | |
splitArray.shift(); | |
} else { | |
textObject.startText = ''; | |
} | |
splitArray.forEach(function(txt, ind) { | |
var secondSplit = txt.split(closetag); | |
var tempObj = {}; | |
tempObj.msg = secondSplit[0] || ''; | |
tempObj.postText = secondSplit[1] || ''; | |
textArray.push(tempObj); | |
}); | |
textObject.textArray = textArray; | |
return textObject; | |
} | |
console.log(HtmlParser(text, '<b>')); |
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
setTimeout(function(){var text="initial text <b>tag 1 ka text</b> bwala word ka text <b>tag 2 ka text</b> left off text";var HtmlParser=function(textToParse,tagToPick){var openTag=tagToPick;var closetag=tagToPick[0]+"/"+tagToPick.substr(1);var splitArray=text.split(openTag);var textArray=[];var textObject=[];if(splitArray[0].indexOf(closetag)===-1){textObject.startText=splitArray[0];splitArray.shift()}else{textObject.startText=""}splitArray.forEach(function(txt,ind){var secondSplit=txt.split(closetag);var tempObj={};tempObj.msg=secondSplit[0]||"";tempObj.postText=secondSplit[1]||"";textArray.push(tempObj)});textObject.textArray=textArray;return textObject};console.log(HtmlParser(text,"<b>"))},0); |
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
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"htmlparser2": "3.9.2" | |
} | |
} |
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
<!-- contents of this file will be placed inside the <body> --> |
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
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment