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

Add a simple HTML editor and toggle system #128

Closed
benwasser opened this issue May 29, 2014 · 46 comments
Closed

Add a simple HTML editor and toggle system #128

benwasser opened this issue May 29, 2014 · 46 comments
Labels

Comments

@benwasser
Copy link

See button on far left of control bar on Redactor: http://imperavi.com/redactor/

@jhchen jhchen added the feature label May 29, 2014
@rtexal
Copy link

rtexal commented Jun 8, 2014

The toggle can already be done with getHTML and getText !

@benwasser
Copy link
Author

You can also make your own rich text editor, but part of the reason for having an editor like Quill is that it accomplishes these things for you. HTML toggling is not a fringe case for the rich text editor, as you can see with Redactor, Tumblr, Wordpress, and so on.

I've actually built such a toggle on top of Quill that does as you say, but it's practically useless, as each tag and style that someone could input directly into HTML needs to be set up to convert to the visual editor code.

@jbrooksuk
Copy link

@benwasser why do you need to convert all of the HTML into a visual format? Just set the innerHTML of the preview element the HTML source?

@andrewsauder
Copy link

Upvote. @benwasser - I'm curious how you managed to add a toggle ontop? Until there's an official method to toggle between a raw HTML view and the WYSIWYG mode, I need to hack something to together also.

@kapouer
Copy link

kapouer commented Aug 19, 2015

Hi,
it is actually useful in a very specific case: for a developer to see if Quill creates html marmelade or not.
Such a button would be useful in the demo.

@jocooler
Copy link

It's pretty easy to see the up-to-date HTML output.

I use code like:

var editor = new Quill('#editor', { ... });
editor.on('text-change', function() {
    var html = editor.getHTML();
    HTML_Container.value = html; // make this a <textarea>
});

Just stack the two areas and toggle opacity with a button. Or preview the code below the editor.

@garygreen
Copy link

+1 any news on this @jhchen ? It would be nice as an option to enable / disable in the toolbar. Often you have 'advanced users' in your system who feel confident dealing with raw HTML. Also as mentioned it will be nice to see the generated HTML by quill at a glance. All wysiwyg I've used before have this, it's the only feature Quill is missing....

@jhchen
Copy link
Member

jhchen commented Apr 27, 2016

If you want to simply output Quill’s contents in HTML this is already possible with DOM’s innerHTML, as others have already mentioned.

If you want to edit the HTML directly, then you may make some change that Quill does not allow. Editors deal with this by cleaning this up, which Quill 0.20 also does, but this communicates nothing about why your edit was not accepted or cleaned. Sometimes the reason is obvious and even welcome like merging adjacent identical tags, but sometimes the reason is very elusive, particularly because often the reason you are extorting to editing HTML is precisely because you are trying to make a modification not supported or understood by the editor. If this is acceptable user experience then you can certainly implement a custom module but Quill is not in that camp and will not condone this use case with an official module.

Some editors do not attempt to understand its contents and let the browser take care of everything through contenteditable, so they can accept any HTML edit, but then they suffer from all the issues from letting browsers take care of everything like non-determinism, inconsistent behavior across browsers, and cannot offer an API beyond what the DOM already offers. Most new editor do not take this approach and Quill does not either but if this is not the tradeoff choice you would have made then Quill is probably not the best solution for your needs.

@aguynamedben
Copy link

aguynamedben commented Dec 9, 2016

@jhchen I wish you would reconsider your stance on this. I'm in the same boat as @garygreen, where I have advanced internal admin users that are confident and allowed to edit our HTML directly. Those advanced users sometimes need to paste embed links like the embed code to show a video hosted on Wistia. I agree it's "edit at your own risk, for advanced users only", and that some of the HTML might be stripped in edge cases, but it's still a real use case that you shouldn't just deny or write off as invalid.

@aguynamedben
Copy link

aguynamedben commented Dec 9, 2016

You mention that Quill already cleans up HTML that it doesn't allow. A practical solution could be to show an alert when HTML is cleaned up so that advanced users are aware they added code that wasn't allowed. I.e. "Some of the HTML you entered in Advanced Mode wasn't allowed and had to be removed. Please double-check the results of your edits."

@AidasK
Copy link

AidasK commented Jan 6, 2017

This feature is a must! 👍

@maximelafarie
Copy link

maximelafarie commented Mar 29, 2017

Always nothing about that awesome new feature ? It needs to be implemented !

@erw13n
Copy link

erw13n commented Jun 3, 2017

Here's what I did to make it happen
https://codepen.io/anon/pen/ZyEjrQ

@matthewfbenjamin
Copy link

Does anyone know how to make this work with ReactQuill? My issue is that I don't instantiate Quill with ReactQuill.

@SoaresMG
Copy link

SoaresMG commented Jul 5, 2017

I'm using react-quill and quill, how may I create something like this?
I wasn't able to transpile the code given by @erw13n to the react environment and ended hacking all the script until the buttons stopped working.

Shouldn't this be one of core features? Or is it too hard too implement (time wise)?
Almost all the customers I've know html and they use it very often using editors like this.

One simple example is when they edit an email template using html or when they just copy templates from the web into the editor.

I've tried tiny-mce, and they have this feature, but it's a cluster of problems integrating with react/webpack...

This lib seems pretty and simple (just what I want), however it misses this key feature (at least for me).

@matthewfbenjamin
Copy link

@LESARQ check this out

@SoaresMG
Copy link

SoaresMG commented Jul 5, 2017

Hey @mbenjamin618 thank you, but I think I've seen all the resources available online 😄
I've done something similar and created a button on the toolbar, then on click I show my textarea and the user may change it.

Following @erw13n script, if you paste:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="viewport" content="width=device-width" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title#### - Invoice Submitted #21E1B3FA7D</title>

		<style>
			p {
				font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
			}
		</style>
	</head>

	<body bgcolor="#FFFFFF">
		<table>
			<tr>
				<td><p>example</p></td>
			</tr>
		</table>
	</body>
</html>

And then if you change it back to the editor and again to the source, you will see that all the code was erased.

Perhaps I'm confused and RichText Editor != Html Editor.

@erw13n
Copy link

erw13n commented Jul 5, 2017

@LESARQ please read @jhchen comment above

If you want to edit the HTML directly, then you may make some change that Quill does not allow. Editors deal with this by cleaning this up, which Quill 0.20 also does

Any element tags which Quill does not allow will automatically clean up, so if you paste such as Div or Table, Quill will replace it with Paragraph.

@SoaresMG
Copy link

SoaresMG commented Jul 5, 2017

Ok, I see. What a shame 😞

@Miindaugas
Copy link

Miindaugas commented Jul 14, 2017

FeelsBadMan..

@imnithin
Copy link

imnithin commented Sep 6, 2017

https://quilljs.com/standalone/full/

@yangwen2
Copy link

yangwen2 commented Oct 7, 2017

Ok so it looks like quill is not designed to be used as an web editor for HTML layouts. We need a richtext editor to create and edit E-mail templates. It doesn't look like quill allows for div elements.. Delete.

@5slight
Copy link

5slight commented Mar 26, 2018

Would it be possible to have a setting to disable automatic code cleaning so we can handle this outside of quill.

It would be quite easy to have a toggle above the editor like in wordpress where you can go between RichText and PlainText as long as quill doesn't just remove anything done in PlainText.

Some kind of html pretty printer would be needed to solve @Eddcapone issue of everything on one line but again thats something that can be handled outside of quill. It can always be concatenated back if the pretty printed code messes with quill.

@hberton
Copy link

hberton commented May 2, 2018

@Eddcapone I have the same problem

any other solution?

@mrspence
Copy link

mrspence commented Jul 8, 2018

+1

@nzolore
Copy link

nzolore commented Jul 18, 2018

While the interface is perfect for editing simple text, a way to preserve custom code would allow a lot more applications.

Here's another "source-button" attempt with external prettifier: https://jsfiddle.net/nzolore/1jxy58vn/

@RevealedFrom
Copy link

RevealedFrom commented Aug 18, 2018

If source code editor is available, it will take pressure off the urgency of delivering other features such as tables. Most people who can use raw Html know all about the <table> tag.

Just have a clean up to remove incompatible or dangerous tags such as <script>.

@Denny966
Copy link

+1

1 similar comment
@jbaydar
Copy link

jbaydar commented Aug 28, 2018

+1

@RevealedFrom
Copy link

I want to add marquee or css animations. It would be too much to ask for these in Quill JS. But if there is source Html edit, they're all there.

@mintyPT
Copy link

mintyPT commented Oct 1, 2018

+1

@aaclayton
Copy link

Just want to say I had put about an hour into building quill into my new platform and was loving the developer friendliness so far until I discovered there is no support for raw HTML editing. Complete deal-breaker, had to go in a different direction.

@RevealedFrom
Copy link

RevealedFrom commented Oct 4, 2018

I am now looking at summernote. It is almost plug compatible with JS Quill.

@egorvdovenko
Copy link

egorvdovenko commented Oct 30, 2018

Module for use with ngx-quill.

html-editor.ts:

export class HtmlEditor {
    quill: any;
    options: any;
    textarea: any;

    constructor(quill: any, options = {}) {
        this.quill = quill;
        this.options = options;

        this.addTextarea();
        this.bindEditorBehavior();
        this.bindButtonBehavior();
    }

    addTextarea() {
        let container = this.quill.addContainer('ql-custom');

        this.textarea = document.createElement('textarea');
        this.textarea.className = "ql-edit-html-textarea";
        this.textarea.style.display = "none";

        container.appendChild(this.textarea);
    }

    bindEditorBehavior() {
        let editor = document.querySelector('.ql-editor');

        this.quill.on('text-change', () => {
            if (editor) {
                let html = editor.innerHTML;

                this.textarea.value = html;
            }
        });
    }

    bindButtonBehavior() {
        let button = document.querySelector('.ql-edit-html');

        if (button) {
            button.addEventListener('click', () => {
                if (this.textarea.style.display === '') {
                    let html = this.textarea.value;

                    this.quill.pasteHTML(html);
                }

                this.textarea.style.display =
                    this.textarea.style.display === 'none'
                        ? ''
                        : 'none';
            });
        }
    }
}

quill-config.ts:

import Quill from 'quill';
import { HtmlEditor } from './html-editor'

Quill.register('modules/htmlEditor', HtmlEditor);

export class QuillConfig {
    constructor() {
        this.modules = {
            htmlEditor: true
        }
    }

    public modules = {};
}

textarea styles:

.ql-edit-html-textarea {
    width: 100%;
    background: rgb(29, 29, 29);
    color: rgb(204, 204, 204);
    outline: none;
    padding: 12px 15px;
    font-family: Consolas;
    position: absolute;
    top: 0;
    bottom: 0;
    border: none;
}

html:

<quill-editor>
    <div quill-editor-toolbar>
        <span class="ql-formats">
            <button class="ql-edit-html">html</button>
        </span>
    </div>
</quill-editor>

@izzygld
Copy link

izzygld commented Jan 9, 2019

Here is a component i made for Quill showing a "Source" show Html option to the Wysiwyg.
See - https://gist.github.com/izzygld/0762dce7292baf2168f9c7b2aa99b535

@chenbimo
Copy link

chenbimo commented Jan 12, 2019

So greate project.
So many troubles.

@Vishnupriya112
Copy link

@erw13n But its removing div , If am adding code like

<div>Hello</div>

Its showing <p>Hello</p>

Is any other way to do

@dokicro
Copy link

dokicro commented Jul 23, 2019

@Vishnupriya112 I have the same problem, it removes even<br>

@sarang-naico
Copy link

Hi,
are there any plans to implement this feature?

@mayesgr
Copy link

mayesgr commented Sep 12, 2019

Glad I found this issue before I decided on a text editor. What a pity that a years-old conceptualization and policy decision is preventing a somewhat straightforward technical implementation and, from glancing at this issue, a quite sought-after feature.

Scratch this one off my list!

@marcelo-amorim
Copy link

Such a great project but it makes no sense have to import Quill just to show what you've build with the editor with preserved styles (to render Delta operations).

I think some warning should be added to git's page saying Quill is not an HTML Editor and some about its dependency on Delta to render what you've stored

@rkarroll
Copy link

rkarroll commented Apr 8, 2020

Agree with @marcelo-amorim. Just integrated Quill, it's working great and now the customer wants to add more complex HTML tags beyond what is supported. Now having to move to something else or hacking together my own thing.

@brankoiliccc
Copy link

This is a deal breaker. Our users need to create responsive content with custom elements. Why would u not allow code editor just to add bootstrap classes for example?

@aswzen
Copy link

aswzen commented Apr 30, 2021

Any update to this absolutely very very basic feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests