A Pen by Saman

Thumbnail
This awesome code was written by xengil, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright xengil ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Saman</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/xengil/a-pen-by-saman-LeoMWP */
var string = 'My life ``-was-`` good,';

var regex = /``-(.*?)-``/g;
var blankStyle = '___';

var card = string.replace(
  regex,
  function(question, text) {
    var regex = /(.+)—:(missing|insert)/;
    var is_question = regex.exec(text);
    
    if (is_question != null) {
      return (is_question[2] == 'missing') ? '' : '<a class="expression-hints" data-text="' + is_question[1] + '">' + blankStyle + '</a>';
    } else {
      return '<a class="expression-hints" data-text="' + text + '">' + blankStyle + '</a>';
    }
  }
).replace(/\s\s+/g, ' ');

console.log(card);

Comments