a demonstration replicated social networking web app built with anproto wiredove.net/
social ed25519 protocols
at main 66 lines 1.6 kB view raw
1import { h } from 'h' 2import { apds } from 'apds' 3import { marked } from 'https://esm.sh/gh/evbogue/bog5@de70376265/lib/marked.esm.js' 4import { send } from './send.js' 5 6const renderer = new marked.Renderer() 7 8renderer.paragraph = function (paragraph) { 9 const array = paragraph.split(' ') 10 11 for (let i = 0; i < array.length; i++) { 12 let word = array[i] 13 if (word.startsWith('#')) { 14 let end 15 16 if (['.', ',', '?', ':', '!'].some(char => word.endsWith(char))) { 17 end = word[word.length - 1] 18 word = word.substring(0, word.length - 1) 19 } 20 21 let hashtag = "<a href='#?" + word + "'>" + word + "</a>" 22 23 if (end) { 24 hashtag = hashtag + end 25 } 26 array[i] = hashtag 27 } 28 } 29 30 const newgraph = array.join(' ') 31 32 return '<p>' + newgraph + '</p>' 33} 34 35renderer.link = function (href, title, text) { 36 if (href.length == 44 && !href.startsWith('http')) { 37 href = '#' + href 38 return marked.Renderer.prototype.link.call(this, href, title, text); 39 } else { 40 const m = marked.Renderer.prototype.link.call(this, href, title, text) 41 return m 42 } 43} 44 45renderer.image = function (src, unknown, title) { 46 if (src.length === 44) { 47 apds.get(src).then(async (img) => { 48 if (img) { 49 const image = document.getElementById('inlineimage'+src) 50 image.src = img 51 } else { 52 await send(src) 53 } 54 }) 55 return `<img id="inlineimage${src}" />` 56 } 57} 58 59marked.setOptions({ 60 renderer: renderer 61}) 62 63export const markdown = async (txt) => { 64 return '<p>' + marked(txt) + '</p>' 65} 66