github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/static/js/link-formatter.js (about)

     1  // We don't need perfect regexp for links. So, use this one without any strict checks for url correctness
     2  const urlRegexp = /((https?:\/\/[^\s\/]+)[^\s]*)/g;
     3  
     4  function formatLinks(querySelector) {
     5  	const elements = document.querySelectorAll(querySelector);
     6  	for (const elem of elements) {
     7  		// Ignore all empty elements or elements with at least one child
     8  		if (elem.children.length !== 0 || elem.innerHTML === "") continue;
     9  
    10  		elem.innerHTML = elem.innerHTML.replace(urlRegexp, '<a href="$1" target="_blank" title="$1">$2/…</a>');
    11  	}
    12  }