Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets - text/plain edition #3

Open
cedricfrancoys opened this issue Mar 24, 2024 · 0 comments
Open

Widgets - text/plain edition #3

cedricfrancoys opened this issue Mar 24, 2024 · 0 comments

Comments

@cedricfrancoys
Copy link
Collaborator

cedricfrancoys commented Mar 24, 2024

Handling HTML Conversion in Quill Text Editor

The Quill text editor converts input text to HTML and returns HTML regardless of the original format. An issue arises when some values of type text/plain end up with HTML tags (e.g., <p>).

Solution:

If the field is not HTML, remove the tags.

Here is an example of how to implement this in JavaScript:

function removeHtmlTags(input) {
    // Check if the input contains HTML tags
    const containsHtml = /<[^>]*>/g.test(input);
    
    // If it doesn't contain HTML tags, return the input as is
    if (!containsHtml) {
        return input;
    }
    
    // Remove HTML tags if the input is not HTML
    const parser = new DOMParser();
    const parsedHtml = parser.parseFromString(input, 'text/html');
    return parsedHtml.body.textContent || "";
}

// Example usage
const quillInput = "<p>This is a text with HTML tags.</p>";
const result = removeHtmlTags(quillInput);
console.log(result); // Outputs: "This is a text with HTML tags."

This function checks if the input string contains HTML tags. If it does, it parses the input as HTML and removes the tags, returning plain text. If the input does not contain HTML tags, it returns the input unchanged.

@cedricfrancoys cedricfrancoys moved this to Todo in eQui Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant