-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from kakakaya/release/v14
* Use BrowserOpenURL and delete OpenURL * Update version to v14 * Fix createdAt timezone problem * Update * Add Richtext ( hashtag, URL, mention ) support (#54) * Bump dependency, to use RichText * Add hashtag / URL / menthion richtext * Bump --------- Co-authored-by: Ryota Kayanuma <r.kayanuma@gigei.jp>
- Loading branch information
Showing
10 changed files
with
370 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// This file is copied from: https://github.com/mattn/bsky/blob/05cbf0a2797313b779950ee4afaa9adcf92c58f3/extract.go | ||
package main | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const ( | ||
urlPattern = `https?://[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+` | ||
mentionPattern = `@[a-zA-Z0-9.]+` | ||
tagPattern = `\B#\S+` | ||
) | ||
|
||
var ( | ||
urlRe = regexp.MustCompile(urlPattern) | ||
mentionRe = regexp.MustCompile(mentionPattern) | ||
tagRe = regexp.MustCompile(tagPattern) | ||
) | ||
|
||
type entry struct { | ||
start int64 | ||
end int64 | ||
text string | ||
} | ||
|
||
func extractLinks(text string) []entry { | ||
var result []entry | ||
matches := urlRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: text[m[0]:m[1]], | ||
start: int64(len([]rune(text[0:m[0]]))), | ||
end: int64(len([]rune(text[0:m[1]])))}, | ||
) | ||
} | ||
return result | ||
} | ||
|
||
func extractLinksBytes(text string) []entry { | ||
var result []entry | ||
matches := urlRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: text[m[0]:m[1]], | ||
start: int64(len(text[0:m[0]])), | ||
end: int64(len(text[0:m[1]]))}, | ||
) | ||
} | ||
return result | ||
} | ||
|
||
func extractMentions(text string) []entry { | ||
var result []entry | ||
matches := mentionRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: strings.TrimPrefix(text[m[0]:m[1]], "@"), | ||
start: int64(len([]rune(text[0:m[0]]))), | ||
end: int64(len([]rune(text[0:m[1]])))}, | ||
) | ||
} | ||
return result | ||
} | ||
|
||
func extractMentionsBytes(text string) []entry { | ||
var result []entry | ||
matches := mentionRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: strings.TrimPrefix(text[m[0]:m[1]], "@"), | ||
start: int64(len(text[0:m[0]])), | ||
end: int64(len(text[0:m[1]]))}, | ||
) | ||
} | ||
return result | ||
} | ||
|
||
func extractTags(text string) []entry { | ||
var result []entry | ||
matches := tagRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: strings.TrimPrefix(text[m[0]:m[1]], "#"), | ||
start: int64(len([]rune(text[0:m[0]]))), | ||
end: int64(len([]rune(text[0:m[1]])))}, | ||
) | ||
} | ||
return result | ||
} | ||
|
||
func extractTagsBytes(text string) []entry { | ||
var result []entry | ||
matches := tagRe.FindAllStringSubmatchIndex(text, -1) | ||
for _, m := range matches { | ||
result = append(result, entry{ | ||
text: strings.TrimPrefix(text[m[0]:m[1]], "#"), | ||
start: int64(len(text[0:m[0]])), | ||
end: int64(len(text[0:m[1]]))}, | ||
) | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8bc973e96983b95b62df8eb19fc1e169 | ||
6faf32c9fcd1f3bdc344cce03c10821a |
Oops, something went wrong.