test
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

idea

12Me21 746415b3 8617d483

+70
+70
parse.js
··· 1 + class MarkupLanguage { 2 + big_regex = /(?:)/g 3 + constructor() {} 4 + process_match(match) { 5 + return [{text:match[0], features:[]}] 6 + } 7 + text_to_segments(text) { 8 + let segments = [] 9 + let last = 0 10 + 11 + for (let match of String(text).matchAll(this.big_regex)) { 12 + let before = text.slice(last, match.index) 13 + if (before.length) 14 + segments.push({text:before, features:[]}) 15 + last = match.index+match[0].length 16 + 17 + segments.push(...this.process_match(match)) 18 + } 19 + 20 + return segments 21 + } 22 + } 23 + 24 + class Markup1 extends MarkupLanguage { 25 + big_regex = ()=>{ 26 + let r = String.raw 27 + let whitespace = r`\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2` 28 + let url = r`[-\w/%&=#+~@$*'!?,.;:]*` 29 + let url_final = r`[-\w/%&=#+~@$*']` 30 + return new RegExp([ 31 + r`\b(?<link>https?://${url}${url_final}([(]${url}[)](${url}${url_final})?)?)(?:\[(?<link_text>.*?)\])?`, 32 + r`(?<=^|\s)[##](?<hashtag>(?!\uFE0F)[^${whitespace}]*[^\p{P}${whitespace}])`, // note: must filter out #123 33 + r`(?<=^|\s|[(])@(?<mention>[-a-zA-Z0-9]+([.][-a-zA-Z0-9]+)+)\b`, 34 + ].join("|"), 'gu') 35 + }() 36 + process_match(match) { 37 + let g = match.groups 38 + if (g.mention!=null) { 39 + return [{text:match[0], features:[{ 40 + $type: 'app.bsky.richtext.facet#mention', 41 + did: g.mention, // hack, DID must be resolved afterwards 42 + }]}] 43 + } 44 + if (g.link!=null) { 45 + if (g.link_text) { 46 + return [{text:g.link_text, features:[{ 47 + $type: 'app.bsky.richtext.facet#link', 48 + uri: g.link, 49 + }]}] 50 + } else { 51 + return [{text:match[0], features:[{ 52 + $type: 'app.bsky.richtext.facet#link', 53 + uri: g.link, 54 + }]}] 55 + } 56 + } 57 + if (g.hashtag!=null && !/^#\d+$/.test(g.hashtag)) { 58 + return [{text:match[0], features:[{ 59 + $type: 'app.bsky.richtext.facet#tag', 60 + tag: g.link, 61 + }]}] 62 + } 63 + return super.process_match(match) 64 + } 65 + } 66 + 67 + let text = "abc http://example.com[test] #hello @test.com.xyz" 68 + 69 + console.log(segments) 70 + </script>