Created
October 21, 2019 03:06
-
-
Save lisantwi/1d6073f503842d4eb697c1b115a94cba to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/latijed
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// todo - create a markup function using regular expressions to convert the strings to formatted html | |
// todo - output the html strings to js console | |
// extra - render the html strings in the html output | |
let strings = [ | |
'This is **bold** text.', | |
'This is __underlined__ text.', | |
'This is ~~strikethrough~~ text.', | |
'This is *italic* text.', | |
'This is a hyperlink: https://www.google.com/', | |
'This is an email: [email protected]' | |
]; | |
function markUp(arr){ | |
for (let i=0; i<arr.length; i++){ | |
arr[i] = arr[i].replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") | |
arr[i] = arr[i].replace(/__(.*?)__/g, "<u>$1</u>") | |
arr[i] = arr[i].replace(/~~(.*?)~~/g, "<del>$1</del>") | |
arr[i] = arr[i].replace(/\*(.*)\*/g, "<i>$1</i>"); | |
arr[i] = arr[i].replace(/(?:^|[^"'])(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,"<a href='$&'>Link</a>"); | |
arr[i] = arr[i].replace(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi, '<a href="mailto:$1">$1</a>'); | |
} | |
console.log(arr) | |
} | |
markUp(strings) | |
function parseStrings(strings){ | |
var parsed ='' | |
for (let i=0; i<strings.length; i++){ | |
parsed += strings[i] + '<br>' | |
} | |
return parsed | |
} | |
document.querySelector('body').innerHTML = parseStrings(strings) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// todo - create a markup function using regular expressions to convert the strings to formatted html | |
// todo - output the html strings to js console | |
// extra - render the html strings in the html output | |
let strings = [ | |
'This is **bold** text.', | |
'This is __underlined__ text.', | |
'This is ~~strikethrough~~ text.', | |
'This is *italic* text.', | |
'This is a hyperlink: https://www.google.com/', | |
'This is an email: [email protected]' | |
]; | |
function markUp(arr){ | |
for (let i=0; i<arr.length; i++){ | |
arr[i] = arr[i].replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") | |
arr[i] = arr[i].replace(/__(.*?)__/g, "<u>$1</u>") | |
arr[i] = arr[i].replace(/~~(.*?)~~/g, "<del>$1</del>") | |
arr[i] = arr[i].replace(/\*(.*)\*/g, "<i>$1</i>"); | |
arr[i] = arr[i].replace(/(?:^|[^"'])(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,"<a href='$&'>Link</a>"); | |
arr[i] = arr[i].replace(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi, '<a href="mailto:$1">$1</a>'); | |
} | |
console.log(arr) | |
} | |
markUp(strings) | |
function parseStrings(strings){ | |
var parsed ='' | |
for (let i=0; i<strings.length; i++){ | |
parsed += strings[i] + '<br>' | |
} | |
return parsed | |
} | |
document.querySelector('body').innerHTML = parseStrings(strings)</script></body> | |
</html> |
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
// todo - create a markup function using regular expressions to convert the strings to formatted html | |
// todo - output the html strings to js console | |
// extra - render the html strings in the html output | |
let strings = [ | |
'This is **bold** text.', | |
'This is __underlined__ text.', | |
'This is ~~strikethrough~~ text.', | |
'This is *italic* text.', | |
'This is a hyperlink: https://www.google.com/', | |
'This is an email: [email protected]' | |
]; | |
function markUp(arr){ | |
for (let i=0; i<arr.length; i++){ | |
arr[i] = arr[i].replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") | |
arr[i] = arr[i].replace(/__(.*?)__/g, "<u>$1</u>") | |
arr[i] = arr[i].replace(/~~(.*?)~~/g, "<del>$1</del>") | |
arr[i] = arr[i].replace(/\*(.*)\*/g, "<i>$1</i>"); | |
arr[i] = arr[i].replace(/(?:^|[^"'])(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,"<a href='$&'>Link</a>"); | |
arr[i] = arr[i].replace(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi, '<a href="mailto:$1">$1</a>'); | |
} | |
console.log(arr) | |
} | |
markUp(strings) | |
function parseStrings(strings){ | |
var parsed ='' | |
for (let i=0; i<strings.length; i++){ | |
parsed += strings[i] + '<br>' | |
} | |
return parsed | |
} | |
document.querySelector('body').innerHTML = parseStrings(strings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment