Markdown Preview in SlateJS
Unanswered
Argentine hake posted this in #help-forum
Argentine hakeOP
Hello everybody!
I have tried implementing a rich text editor using
or
## headers.
If anyone has at least some experience with
I have tried implementing a rich text editor using
SlateJS that allows for markdown preview, just like discord does, however, I am finding great difficulty in doing so. I am aware that the github page has an [example](https://github.com/ianstormtaylor/slate/blob/main/site/examples/markdown-preview.tsx) for this but it seems to be overly conveluted and difficult to understand. Furthermore, it only works for Leafs, meaning I cannot have things likecode blocks or
## headers.
If anyone has at least some experience with
SlateJS, your help would be greatly appreciated, thank you in advance!21 Replies
Argentine hakeOP
Bump
Argentine hakeOP
Bump v2
Argentine hakeOP
Bump v3
Argentine hakeOP
Bump v4
hmm, I don't think you're gonna get a response anytime soon, you ain't asking a question, more like suggestion. Do it through docs, and ask questions if you have any.
@averydelusionalperson hmm, I don't think you're gonna get a response anytime soon, you ain't asking a question, more like suggestion. Do it through docs, and ask questions if you have any.
Argentine hakeOP
I guess my initial question was unclear, I'm asking if anybody knows how to implement create a markdown preview editor using
SlateJS that would work for both Leaf and Element.You’ll need to post your attempt here. We may help you with debugging but no one here has the time to implement it from scratch for you. Slatejs is big.
Also, kindly only bump once per day.
@joulev Also, kindly only bump once per day.
Argentine hakeOP
I'm so sorry, I won't do that again
@joulev You’ll need to post your attempt here. We may help you with debugging but no one here has the time to implement it from scratch for you. Slatejs is big.
Argentine hakeOP
This is my attempt using some code from the example, some from the docs and some from AI and then trying to stich everything together.
@Argentine hake This is my attempt using some code from the example, some from the docs and some from AI and then trying to stich everything together.
Argentine hakeOP
It works but it feels incredibly hacky and when I try to use the
useState hook to track the values of the editor, it starts getting very laggyFor context this is where the editor resides:
function NewPostForm({ user }: {user: User}) {
const [content, setContent] = useState('')
let formStyleArray;
let backgroundStyleArray;
const {isFormOpen, setIsFormOpen} = useContext(FormContext);
let createPostWithAuthor = createPost.bind(null, user.id, content)
// TODO Throw a visible error to the user
return (
<div className={`fixed w-full bg-black h-full grid place-items-center z-10 transition-all ${isFormOpen ? 'bg-opacity-50' : 'bg-opacity-0 invisible'}`} onClick={() => setIsFormOpen(false)}>
<form action={createPostWithAuthor} className={`flex flex-col bg-neutral-800 h-[98%] border-neutral-700 border-solid w-1/2 rounded-t-xl p-4 bottom-0 absolute transition-all ${isFormOpen ? 'translate-y-0' : 'translate-y-full'}`} onClick={(e) => e.stopPropagation()}>
<div className='flex flex-row justify-end items-center gap-2'>
<input className={`bg-transparent w-full text-2xl font-bold p-2 outline-none`} type="text" placeholder='Title' name='title'/>
<button className='bg-black h-9 px-2 rounded-md border-white border-2 border-opacity-30'><FaPlus/></button>
<SubmitButton/>
</div>
<Editor setContent={setContent}/
</form>
</div>
)
}Argentine hakeOP
Bump v5
Argentine hakeOP
Bump v6
Argentine hakeOP
Bump v7
Argentine hakeOP
Bump v8
Argentine hakeOP
Bump v9
Argentine hakeOP
Bump v10
Argentine hakeOP
Bump v11
Argentine hakeOP
Bump v12