Mercurial Hosting > chat
comparison src/chat.js @ 118:04933d5ba05a
handle markdown
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 04 Dec 2025 22:57:00 -0700 |
| parents | 77c8104d7053 |
| children | d7e143175d9f |
comparison
equal
deleted
inserted
replaced
| 117:e2deb5236f26 | 118:04933d5ba05a |
|---|---|
| 90 for( let div of divs ) { | 90 for( let div of divs ) { |
| 91 for( let whenSpan of div.querySelectorAll('[when]') ) { | 91 for( let whenSpan of div.querySelectorAll('[when]') ) { |
| 92 whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'}); | 92 whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'}); |
| 93 } | 93 } |
| 94 let textDiv = div.querySelector('div[text]'); | 94 let textDiv = div.querySelector('div[text]'); |
| 95 textDiv.innerHTML = urlsToLinks(textDiv.innerHTML); | 95 textDiv.innerHTML = handleMarkdown(textDiv.innerHTML); |
| 96 let reply = div.querySelector('blockquote'); | 96 let reply = div.querySelector('blockquote'); |
| 97 if( reply ) | 97 if( reply ) |
| 98 reply.innerHTML = urlsToLinks(reply.innerHTML); | 98 reply.innerHTML = handleMarkdown(reply.innerHTML); |
| 99 let html; | 99 let html; |
| 100 if( div.getAttribute('author') === userId ) { | 100 if( div.getAttribute('author') === userId ) { |
| 101 html = document.querySelector('div[hidden] span[pulldown=author]').innerHTML; | 101 html = document.querySelector('div[hidden] span[pulldown=author]').innerHTML; |
| 102 } else { | 102 } else { |
| 103 html = document.querySelector('div[hidden] span[pulldown=other]').innerHTML; | 103 html = document.querySelector('div[hidden] span[pulldown=other]').innerHTML; |
| 249 // console.log('onfocus'); | 249 // console.log('onfocus'); |
| 250 document.title = title; | 250 document.title = title; |
| 251 active(); | 251 active(); |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 let urlRegex = /(^|\s)(https?:\/\/\S+)/g; | 254 let converter = window.markdownit({linkify:true}); |
| 255 let filebinUrlRegex = /(^|\s)(https:\/\/filebin.net\/[0-9a-f]+\/(\S+))/g; | 255 let filebinUrlRegex = />https:\/\/filebin.net\/[0-9a-f]+\/([^<]+)</g; |
| 256 | 256 |
| 257 function urlsToLinks(text) { | 257 function handleMarkdown(text) { |
| 258 text = text.replace( filebinUrlRegex, '$1<a target="_blank" href="$2">$3</a>' ); | 258 text = converter.render(text); |
| 259 text = text.replace( urlRegex, '$1<a target="_blank" href="$2">$2</a>' ); | 259 text = text.replace( filebinUrlRegex, '>$1<' ); |
| 260 return text; | 260 return text; |
| 261 } | 261 } |
| 262 | 262 |
| 263 let currentPulldown = null; | 263 let currentPulldown = null; |
| 264 let newPulldown = null; | 264 let newPulldown = null; |
