Skip to content

Instantly share code, notes, and snippets.

@cyberhck
Last active August 29, 2015 14:06
Show Gist options
  • Save cyberhck/934fc284271ad1c3c9b8 to your computer and use it in GitHub Desktop.
Save cyberhck/934fc284271ad1c3c9b8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hash Tag Demo</title>
<script>
function parse() {
text = document.getElementById("postToorq").value;
res = text.replace(/#[a-z0-9][a-z0-9\-_]*/gi, "<strong>$&</strong>");
res = res.replace(/ /g, "&nbsp;");
res = res.replace(/\n/g, "<br>");
document.getElementById("helper").innerHTML = res;
res = text.match(/(?:#)[a-z0-9][a-z0-9\-_]*/gi, text);
var ht = "";
for (var i = res.length - 1; i >= 0; i--) {
res[i] = res[i].substring(1, res[i].length);
ht = ht + "<br>" + res[i];
}
document.getElementById("hsh").innerHTML = ht;
console.log(res);
}
</script>
<style>
.inputbox {
position: relative;
}
.toorqpost {
background-color: rgba(0, 0, 0, 0);
position: absolute;
margin: 0px;
padding: 0px;
font: inherit;
}
.helper {
position: absolute;
margin: 0px;
font: inherit;
color: rgba(0, 0, 0, 0);
}
.helper strong {
background: #5FD5BB;
font-weight: normal;
margin: 0;
}
</style>
</head>
<body>
<div class="inputbox" style="min-height:200px;">
<div class="helper" id="helper" style="position:absolute; margin:0px;height:100%;width:100%;"></div>
<textarea onkeyup="return parse()" class="toorqpost" style="height:100%;width:100%;" name="" id="postToorq" cols="30" rows="10"></textarea>
</div>
<div class="list">
List of hashtags:
<div id="hsh"></div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment