Skip to content

Commit

Permalink
switch to plain markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaySagar-Git committed Aug 24, 2024
1 parent c900e9a commit 66fb4fc
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 497 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"rehype-raw": "^6.1.1",
"turndown": "^7.2.0",
"use-keyboard-shortcut": "^1.1.6",
"xlsx": "^0.18.5"
},
Expand Down
15 changes: 9 additions & 6 deletions src/Components/Common/RichTextEditor/MarkdownPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ const MarkdownPreview = ({
}

const processedMarkdown = markdown
.replace(
/!\[mention_user\]\(user_id:(\d+), username:([^)]+)\)/g,
(_, userId, username) =>
`<a class="user-mention" href="/user/profile/${username}" data-user-id="${userId}" data-username="${username}">@${username}</a>`,
)
.replace(/@(\w+)/g, (_, username) => {
const user = MentionedUsers[username];
if (user) {
return `<a href="/user/profile/${username}" data-username="${username}">@${username}</a>`;
} else {
return `@${username}`;
}
})
.replace(/~~(.*?)~~/g, (_, text) => `<del>${text}</del>`);

const CustomLink: React.FC<CustomLinkProps> = (props) => {
const [isHovered, setIsHovered] = useState(false);

if (props.className?.includes("user-mention") && props["data-username"]) {
if (props["data-username"]) {
const username = props["data-username"];
return (
<span
Expand Down
9 changes: 4 additions & 5 deletions src/Components/Common/RichTextEditor/MentionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useSlug from "../../../Common/hooks/useSlug";
interface MentionsDropdownProps {
onSelect: (user: { id: string; username: string }) => void;
position: { top: number; left: number };
editorRef: React.RefObject<HTMLDivElement>;
editorRef: React.RefObject<HTMLTextAreaElement>;
filter: string;
}

Expand All @@ -28,10 +28,9 @@ const MentionsDropdown: React.FC<MentionsDropdownProps> = ({

useEffect(() => {
if (editorRef.current) {
const editorRect = editorRef.current.getBoundingClientRect();
setDropdownPosition({
top: position.top - editorRect.top + editorRef.current.scrollTop,
left: position.left - editorRect.left,
top: position.top,
left: position.left,
});
}
}, [position, editorRef]);
Expand Down Expand Up @@ -83,7 +82,7 @@ const MentionsDropdown: React.FC<MentionsDropdownProps> = ({

return (
<div
className="absolute z-10 max-h-36 w-64 overflow-y-scroll rounded-md bg-white text-sm shadow-lg"
className="absolute z-10 max-h-36 w-64 overflow-y-auto rounded-md bg-white text-sm shadow-lg"
style={{ top: dropdownPosition.top, left: dropdownPosition.left }}
>
{loading && <div className="p-2 text-gray-500">Loading...</div>}
Expand Down
Loading

0 comments on commit 66fb4fc

Please sign in to comment.