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,12 +9,21 @@ 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') {
for (const attr in token.attrs) { if (token.attrs.id) {
if ( vid = token.attrs.id as string // Get the video `id` attribute (common id style)
Object.prototype.hasOwnProperty.call(token.attrs, attr) && } else if (token.attrs.vid) {
attr.startsWith('#') vid = token.attrs.vid as string // Check for the `vid` attribute (youtube directive attribute style)
) { } else {
vid = attr.replace('#', '') // 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) {
if (
Object.prototype.hasOwnProperty.call(token.attrs, attr) &&
attr.startsWith('#')
) {
vid = attr.replace('#', '')
}
} }
} }
} }

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)