fix(viewer): remove double sanitize, fix yt directive
All checks were successful
Release to Staging / build_and_release (push) Successful in 1m1s

This commit is contained in:
enes 2024-12-24 20:20:13 +01:00
parent 73cec02ee5
commit 2440620328
2 changed files with 16 additions and 13 deletions

View File

@ -9,6 +9,14 @@ export const youtubeDirective: DirectiveConfig = {
//::youtube{#<VIDEO_ID>} //::youtube{#<VIDEO_ID>}
let vid: string = '' let vid: string = ''
if (token.attrs && token.meta.name === 'youtube') { if (token.attrs && token.meta.name === 'youtube') {
if (token.attrs.id) {
vid = token.attrs.id as string // Get the video `id` attribute (common id style)
} else if (token.attrs.vid) {
vid = token.attrs.vid as string // Check for the `vid` attribute (youtube directive attribute style)
} else {
// Fallback for id
// In case that video starts with the number it will not be recongizned as an id
// We have to manually fetch it
for (const attr in token.attrs) { for (const attr in token.attrs) {
if ( if (
Object.prototype.hasOwnProperty.call(token.attrs, attr) && Object.prototype.hasOwnProperty.call(token.attrs, attr) &&
@ -18,6 +26,7 @@ export const youtubeDirective: DirectiveConfig = {
} }
} }
} }
}
if (vid) { if (vid) {
return `<iframe title="Video embed" width="560" height="315" src="https://www.youtube.com/embed/${vid}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>` return `<iframe title="Video embed" width="560" height="315" src="https://www.youtube.com/embed/${vid}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>`

View File

@ -28,8 +28,6 @@ import { OriginalAuthor } from './OriginalAuthor'
import { CategoryAutocomplete } from './CategoryAutocomplete' import { CategoryAutocomplete } from './CategoryAutocomplete'
import { AlertPopup } from './AlertPopup' import { AlertPopup } from './AlertPopup'
import { Editor, EditorRef } from './Markdown/Editor' import { Editor, EditorRef } from './Markdown/Editor'
import TurndownService from 'turndown'
import DOMPurify from 'dompurify'
interface GameOption { interface GameOption {
value: string value: string
@ -48,10 +46,6 @@ export const ModForm = () => {
initializeFormState(mod) initializeFormState(mod)
) )
const editorRef = useRef<EditorRef>(null) const editorRef = useRef<EditorRef>(null)
const sanitized = DOMPurify.sanitize(formState.body)
const turndown = new TurndownService()
turndown.keep(['sup', 'sub'])
const markdown = turndown.turndown(sanitized)
useEffect(() => { useEffect(() => {
const options = games.map((game) => ({ const options = games.map((game) => ({
@ -208,7 +202,7 @@ export const ModForm = () => {
<div className='inputMain'> <div className='inputMain'>
<Editor <Editor
ref={editorRef} ref={editorRef}
markdown={markdown} markdown={formState.body}
placeholder="Here's what this mod is all about" placeholder="Here's what this mod is all about"
onChange={(md) => { onChange={(md) => {
handleInputChange('body', md) handleInputChange('body', md)