Open athishsreeram opened 1 month ago
how to validate malicious content link ?
does special characters includes numbers too. (in that case we cant enter numbers in title Example: "Top 10 A.I. courses to learn in 2024").
Plz explain me about this whole issue
@dinesh9396
We need to add a validation which will allow just Markdown as input
npm install markdown-it
import React, { useState } from 'react'; import MarkdownIt from 'markdown-it';
const md = new MarkdownIt();
const MarkdownValidator = () => { const [input, setInput] = useState(''); const [isValid, setIsValid] = useState(true); const [error, setError] = useState('');
const handleChange = (e) => { const value = e.target.value; setInput(value);
try {
// Attempt to parse the input as Markdown
md.parse(value);
setIsValid(true);
setError('');
} catch (err) {
// If parsing fails, update the state to reflect invalid input
setIsValid(false);
setError(err.message);
}
};
return (
Valid Markdown
) : (Invalid Markdown: {error}
)}); };
export default MarkdownValidator;
Sample idea
We need to add this validation this will prevent us from user entering those kind of html scripts