Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Integrate new tag detection and regexes (#3063)

* Integrate new tag detection and regexes

* Bump SDK

* Can use const

* Clarify intent

* Enhance clarity

authored by

Eric Bailey and committed by
GitHub
e11bd438 f8aa5fd0

+23 -14
+1 -1
package.json
··· 44 44 "update-extensions": "scripts/updateExtensions.sh" 45 45 }, 46 46 "dependencies": { 47 - "@atproto/api": "^0.10.3", 47 + "@atproto/api": "^0.10.4", 48 48 "@bam.tech/react-native-image-resizer": "^3.0.4", 49 49 "@braintree/sanitize-url": "^6.0.2", 50 50 "@emoji-mart/react": "^1.1.1",
+3 -2
src/view/com/composer/text-input/web/LinkDecorator.ts
··· 18 18 import {Plugin, PluginKey} from '@tiptap/pm/state' 19 19 import {Node as ProsemirrorNode} from '@tiptap/pm/model' 20 20 import {Decoration, DecorationSet} from '@tiptap/pm/view' 21 + import {URL_REGEX} from '@atproto/api' 22 + 21 23 import {isValidDomain} from 'lib/strings/url-helpers' 22 24 23 25 export const LinkDecorator = Mark.create({ ··· 78 80 79 81 function iterateUris(str: string, cb: (from: number, to: number) => void) { 80 82 let match 81 - const re = 82 - /(^|\s|\()((https?:\/\/[\S]+)|((?<domain>[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/gim 83 + const re = URL_REGEX 83 84 while ((match = re.exec(str))) { 84 85 let uri = match[2] 85 86 if (!uri.startsWith('http')) {
+15 -7
src/view/com/composer/text-input/web/TagDecorator.ts
··· 18 18 import {Plugin, PluginKey} from '@tiptap/pm/state' 19 19 import {Node as ProsemirrorNode} from '@tiptap/pm/model' 20 20 import {Decoration, DecorationSet} from '@tiptap/pm/view' 21 + import {TAG_REGEX, TRAILING_PUNCTUATION_REGEX} from '@atproto/api' 21 22 22 23 function getDecorations(doc: ProsemirrorNode) { 23 24 const decorations: Decoration[] = [] 24 25 25 26 doc.descendants((node, pos) => { 26 27 if (node.isText && node.text) { 27 - const regex = /(?:^|\s)(#[^\d\s]\S*)(?=\s)?/g 28 + const regex = TAG_REGEX 28 29 const textContent = node.textContent 29 30 30 31 let match 31 32 while ((match = regex.exec(textContent))) { 32 - const [matchedString, tag] = match 33 + const [matchedString, _, tag] = match 33 34 34 - if (tag.length > 66) continue 35 + if (!tag || tag.replace(TRAILING_PUNCTUATION_REGEX, '').length > 64) 36 + continue 35 37 36 - const [trailingPunc = ''] = tag.match(/\p{P}+$/u) || [] 38 + const [trailingPunc = ''] = tag.match(TRAILING_PUNCTUATION_REGEX) || [] 39 + const matchedFrom = match.index + matchedString.indexOf(tag) 40 + const matchedTo = matchedFrom + (tag.length - trailingPunc.length) 37 41 38 - const from = match.index + matchedString.indexOf(tag) 39 - const to = from + (tag.length - trailingPunc.length) 42 + /* 43 + * The match is exclusive of `#` so we need to adjust the start of the 44 + * highlight by -1 to include the `#` 45 + */ 46 + const start = pos + matchedFrom - 1 47 + const end = pos + matchedTo 40 48 41 49 decorations.push( 42 - Decoration.inline(pos + from, pos + to, { 50 + Decoration.inline(start, end, { 43 51 class: 'autolink', 44 52 }), 45 53 )
+4 -4
yarn.lock
··· 34 34 jsonpointer "^5.0.0" 35 35 leven "^3.1.0" 36 36 37 - "@atproto/api@^0.10.3": 38 - version "0.10.3" 39 - resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.10.3.tgz#cdef37a23b53e2e84840e527992482b0a0ab9d47" 40 - integrity sha512-eNP/6YLor48SUD38Jn5C7xocQL9XzW+BbYat2whWerKsFMn6Kfkk5O3fW1pvcc6NKtKVTo7/4ixMAS+dG2o/Yg== 37 + "@atproto/api@^0.10.4": 38 + version "0.10.4" 39 + resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.10.4.tgz#b73446f2344783c42c6040082756449443f15750" 40 + integrity sha512-9gwZt4v4pngfD4mgsET9i9Ym0PpMSzftTzqBjCbFpObx15zMkFemYnLUnyT/NEww2u/aRxjAe2TeBnU0dIbbuQ== 41 41 dependencies: 42 42 "@atproto/common-web" "^0.2.3" 43 43 "@atproto/lexicon" "^0.3.2"