Wrapping HTML elements in a rich text editor and the importance of focusing on structure over design
25 replies
Last updated: May 27, 2022
N
hi ! i'd like to know if i can wrap my
I just want the last li elements to be wrapped inside the div
<li>elements in a div.current schema :
marks: {
decorators: [
{ title: "strong", value: "strong" },
{ title: "em", value: "em" },
{ title: "strike", value: "strike" },
{ title: "underline", value: "underline" },
{ title: "blue", value: "blue" },
{ title: "green", value: "green" },
{ title: "animation", value: "animation" },
{ title: "muted", value: "muted" },
{ title: "div", value: "div" },But when i do something like that it just wrap my element in the li not the 2 li elements i want.
I just want the last li elements to be wrapped inside the div
May 27, 2022, 7:13 AM
K
Wrapping a
<li>element in a
<div>would yield invalid HTML and break list semantics.
May 27, 2022, 8:25 AM
N
ok so i tried to put an h2 and an h1 in a div but it doesnt let me
May 27, 2022, 11:34 AM
N
do i have to put the div as a decorator ?
May 27, 2022, 11:35 AM
N
<p class="text-2xl p-2"><div class="text-2xl p-2">Design</div></p>
<p class="text-2xl p-2"><div class="text-2xl p-2">UX/UI</div></p>
May 27, 2022, 11:42 AM
N
my code looks like that
May 27, 2022, 11:44 AM
N
<div><p class="text-2xl p-2">Design</p>
<p class="text-2xl p-2"><p class="text-2xl p-2">UX/UI</p></div>
May 27, 2022, 11:46 AM
N
while i want it to look like that
May 27, 2022, 11:46 AM
N
here s my portable text code
May 27, 2022, 11:47 AM
N
const portraitPortableTextComponents: any = {
block: {
normal: ({ children }) => <p _className_="text-2xl p-2">{children}</p>,
h3: ({ children }) => <h3 _className_="font-bold">{children}</h3>,
},
marks: {
div: ({ children }) => <div _className_="text-2xl p-2">{children}</div>,
},
}
May 27, 2022, 11:47 AM
N
tldr i want to wrap my content in a div
May 27, 2022, 11:55 AM
N
tldr i want to wrap my content in a div in a rich text block
May 27, 2022, 11:59 AM
K
Iโm a little confused as to why? The rich text editor is not an HTML editor. It gives structure, not markup. Ultimately, you map these nodes to whatever you want on your frontend. Or am I missing something?
May 27, 2022, 12:01 PM
N
it was just to have a line break but after a seond thought i might me able to do it another way like "going to the next line" :X
May 27, 2022, 12:04 PM
N
in my editor
May 27, 2022, 12:04 PM
N
its true that i was hoping to replace all my tags with predefined ones in my editor but that my not be the right way to do things
May 27, 2022, 12:06 PM
K
I would generally advise against trying to make the editor look like the frontend version of the content. The editor is suppose to convey content and structure, but not design per se. ๐
May 27, 2022, 12:08 PM
N
alright you must be right. I'm new to the cms things to be honest and i 'm trying to find my way on my own.
May 27, 2022, 12:09 PM
N
tahnk you for your advices i will rethink my process
May 27, 2022, 12:09 PM
K
It takes a bit of time to get the hang of it, but I think a healthy way to think about the portable text editor is to think about structure really. Similar to Markdown in a way.
You or your editors need to be able to say โthis is a heading, this is a list, this is a map widget with these options, this is an image with this alt text, this is a 2 columns layout with this content.โ How it will look (beyond the options you defined like layout or things like this) is the responsibility of the frontend. And markup is definitely on the frontend side as well.
๐
You or your editors need to be able to say โthis is a heading, this is a list, this is a map widget with these options, this is an image with this alt text, this is a 2 columns layout with this content.โ How it will look (beyond the options you defined like layout or things like this) is the responsibility of the frontend. And markup is definitely on the frontend side as well.
๐
May 27, 2022, 12:14 PM
N
alright ๐
May 27, 2022, 12:25 PM
N
thank you for your time
May 27, 2022, 12:25 PM
N
no need to say ill be back
May 27, 2022, 12:25 PM
N
haha
May 27, 2022, 12:25 PM
K
Haha, take care. โค๏ธ
May 27, 2022, 12:26 PM
N
thanks you too
May 27, 2022, 12:26 PM
Sanityโ build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.