highlight hashtags
This commit is contained in:
parent
24ac41918c
commit
f84710d8f1
@ -62,3 +62,8 @@ export const InvoiceRegex = /(lnbc\w+)/i;
|
||||
* YouTube URL regex
|
||||
*/
|
||||
export const YoutubeUrlRegex = /^(?:https?:\/\/)?(?:www|m\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
|
||||
|
||||
/**
|
||||
* Hashtag regex
|
||||
*/
|
||||
export const HashtagRegex = /(#[a-z\d-]+)/ig
|
||||
|
18
src/Text.js
18
src/Text.js
@ -1,9 +1,10 @@
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import Invoice from "./element/Invoice";
|
||||
import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex } from "./Const";
|
||||
import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, HashtagRegex } from "./Const";
|
||||
import { eventLink, hexToBech32, profileLink } from "./Util";
|
||||
import LazyImage from "./element/LazyImage";
|
||||
import Hashtag from "./element/Hashtag";
|
||||
|
||||
function transformHttpLink(a) {
|
||||
try {
|
||||
@ -111,3 +112,18 @@ export function extractInvoices(fragments) {
|
||||
return f;
|
||||
}).flat();
|
||||
}
|
||||
|
||||
export function extractHashtags(fragments) {
|
||||
return fragments.map(f => {
|
||||
if (typeof f === "string") {
|
||||
return f.split(HashtagRegex).map(i => {
|
||||
if (i.toLowerCase().startsWith("#")) {
|
||||
return <Hashtag>{i}</Hashtag>
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
}
|
||||
return f;
|
||||
}).flat();
|
||||
}
|
||||
|
3
src/element/Hashtag.css
Normal file
3
src/element/Hashtag.css
Normal file
@ -0,0 +1,3 @@
|
||||
.hashtag {
|
||||
color: var(--highlight);
|
||||
}
|
11
src/element/Hashtag.js
Normal file
11
src/element/Hashtag.js
Normal file
@ -0,0 +1,11 @@
|
||||
import './Hashtag.css'
|
||||
|
||||
const Hashtag = ({ children }) => {
|
||||
return (
|
||||
<span className="hashtag">
|
||||
{children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default Hashtag
|
@ -5,7 +5,7 @@ import { useNavigate } from "react-router-dom";
|
||||
|
||||
import Event from "../nostr/Event";
|
||||
import ProfileImage from "./ProfileImage";
|
||||
import { extractLinks, extractMentions, extractInvoices } from "../Text";
|
||||
import { extractLinks, extractMentions, extractInvoices, extractHashtags } from "../Text";
|
||||
import { eventLink, hexToBech32 } from "../Util";
|
||||
import NoteFooter from "./NoteFooter";
|
||||
import NoteTime from "./NoteTime";
|
||||
@ -32,6 +32,7 @@ export default function Note(props) {
|
||||
let fragments = extractLinks([body]);
|
||||
fragments = extractMentions(fragments, ev.Tags, users);
|
||||
fragments = extractInvoices(fragments);
|
||||
fragments = extractHashtags(fragments);
|
||||
if (deletion?.length > 0) {
|
||||
return (
|
||||
<>
|
||||
|
@ -272,7 +272,7 @@ body.scroll-lock {
|
||||
}
|
||||
|
||||
.root-tabs {
|
||||
padding: 0 2px;
|
||||
padding: 0;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user