on master help sign in
Merge pull request #274 from ljcooke/link-urls-on-wiki

Feature: Autolink URLs in wiki

commit6c3fd861010c5a3b1f185c5abc5aa43b6634fe43 authorChris <ckipp@pm.me> dateMon 12 Aug 2019, 17:15 (7 years ago) parentfb1571fdca72d2
1 file changed+7−2
scripts/wiki.js+7−2
scripts/wiki.js+7−2
@@ -55,11 +55,16 @@ const Wiki = sites => {
5555 return `${currentHtml}${newHtml}`
5656 }
5757
58+ const formatLinks = text => text.replace(
59+ /\b((https?|dat):\/\/[^"\s]+)/g,
60+ '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'
61+ )
62+
5863 const formatEntry = (definitions, definition) => {
59− const formatEntryList = entryList => entryList.reduce((items, item) => `${items}<li>${item}</li>`, '')
64+ const formatEntryList = entryList => entryList.reduce((items, item) => `${items}<li>${formatLinks(item)}</li>`, '')
6065
6166 const newHtml = typeof definition.entry === 'string'
62− ? `<li>${definition.entry}
67+ ? `<li>${formatLinks(definition.entry)}
6368 - <a class='author' target='_blank' href='${definition.url}'> @${definition.author}</a>
6469 </li>`
6570 : `<li><ul>${formatEntryList(definition.entry)}