I'm trying to create a youtube editor component with gatsby-remark-embed-video. I'm using Gatsby, Netlify CMS, and Netlify. I want to have a preview of the video (can be the video itself or an image) in my preview by Netlify CMS. However, it results in a conflict. If it works in Netlify CMS, it doesn't work to Gatsby and vice versa.
gatsby-remark-embed-video
relies on pattern youtube: ID
to embed a video, which works correctly on gatsby. The problem is that, when using Netlify CMS, it's parsing youtube: ID
as markdown code, because normally we use Backtick (grave accent) to write code!
{
id: 'youtube',
label: 'Youtube',
fields: [{ name: 'id', label: 'Youtube Video ID', widget: 'string' }],
pattern: /^`youtube: (\S+)`$/,
fromBlock: match => {
const id = match[1];
return { id };
},
toBlock: obj => `\`youtube: ${obj.id}\``,
toPreview: obj =>
`<img src="http://img.youtube.com/vi/${
obj.id
}/maxresdefault.jpg" alt="Youtube Video"/>`
}
To conclude, basically it's not working to Netlify CMS. All the time it results in a line of code in Netlify CMS preview. If I remove the backtick (grave accent) from my markdown file, it is reading by a normal text and not like a video. I don't know what to do, can someone help me?
Thank you! =)
What is reading by Netlify CMS in my preview: