Mercurial Hosting > chat
comparison src/chat.js @ 122:1ae3613dd090
markdown work
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Wed, 10 Dec 2025 20:30:42 -0700 |
| parents | b96d598aa7d1 |
| children |
comparison
equal
deleted
inserted
replaced
| 121:b96d598aa7d1 | 122:1ae3613dd090 |
|---|---|
| 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 = handleMarkdown(textDiv.innerHTML); | 95 textDiv.innerHTML = handleMarkdown(textDiv.textContent); |
| 96 let reply = div.querySelector('blockquote'); | 96 let reply = div.querySelector('blockquote'); |
| 97 if( reply ) | 97 if( reply ) |
| 98 reply.innerHTML = handleMarkdown(reply.innerHTML); | 98 reply.innerHTML = handleMarkdown(reply.textContent); |
| 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; |
| 254 let converter = window.markdownit({linkify:true}); | 254 let converter = window.markdownit({linkify:true}); |
| 255 let filebinUrlRegex = />https:\/\/filebin.net\/[0-9a-f]+\/([^<]+)</g; | 255 let filebinUrlRegex = />https:\/\/filebin.net\/[0-9a-f]+\/([^<]+)</g; |
| 256 let urlRegex = /(<a href="https?:\/\/[^" ]+")>/g; | 256 let urlRegex = /(<a href="https?:\/\/[^" ]+")>/g; |
| 257 | 257 |
| 258 function handleMarkdown(text) { | 258 function handleMarkdown(text) { |
| 259 text = converter.renderInline(text); | 259 text = converter.render(text); |
| 260 text = text.replace( filebinUrlRegex, '>$1<' ); | 260 text = text.replace( filebinUrlRegex, '>$1<' ); |
| 261 text = text.replace( urlRegex, '$1 target="_blank">' ); | 261 text = text.replace( urlRegex, '$1 target="_blank">' ); |
| 262 return text; | 262 return text; |
| 263 } | 263 } |
| 264 | 264 |
