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

Errors when HTML has a comment tag #32

Closed
bfintal opened this issue Oct 3, 2015 · 11 comments
Closed

Errors when HTML has a comment tag #32

bfintal opened this issue Oct 3, 2015 · 11 comments
Assignees
Labels

Comments

@bfintal
Copy link
Contributor

bfintal commented Oct 3, 2015

I'm getting this:

Uncaught Error: Error at char 1 >> Error: Transition is undefined: (!, 3)

at line 1055:

throw new Error("Error at char " + this.head + " >> " + error);

I just added this into the HTML: <!-- -->

@anthonyjb
Copy link
Member

Ahh - it should strip HTML commends before attempting to parse inner HTML but perhaps it's failing if there's nothing in the comment - this is an issue with HTMLString. I'll resolve ASAP, thanks for highlighting.

@anthonyjb anthonyjb self-assigned this Oct 3, 2015
@anthonyjb anthonyjb added the bug label Oct 3, 2015
@bfintal
Copy link
Contributor Author

bfintal commented Oct 3, 2015

Even if there's content in it, it's still failing :)

@anthonyjb
Copy link
Member

Hmmm... that's odd - I don't think there's a test spec for this so will add one at the same time.

@anthonyjb
Copy link
Member

OK that now correctly removes comments before parsing (my RegExp was incorrect). There's now comments in the test spec data.

Only down side is any comments you add will be removed as soon as the element containing them is edited and saved, I hadn't considered supporting comments within the editable regions up to this point and I'm not entirely sure how they would be catered for when a user edits the content - but happy to consider arguments for supporting them :)

@bfintal
Copy link
Contributor Author

bfintal commented Oct 3, 2015

The reason I'm actually using comments is that I needed to add some sort of hidden marker inside the html. So for if I generate <!--marker1--> ...unknown html... <!--/marker1-->, I can get the insides of those comments when saving and process them in a different way.

@anthonyjb
Copy link
Member

Can you place those markers outside of the editable regions? For example:

<!--marker1--><div data-editable="marker1">
    <p>
        Here goes my editable content...
    </p>
</div><!--/marker1-->

I actually do something very similar with Jinja2 templates for the getcontenttools.com website.

@anthonyjb
Copy link
Member

If they need to be inside of the editable element one option would be to consider using a span tag:

<div data-editable="my-region">
    <p>
        Here <span class="marker1">goes my editable content...</span>
    </p>
</div>

It should still be relatively easy to extract this content safely.

@bfintal
Copy link
Contributor Author

bfintal commented Oct 3, 2015

Right now as an alternative I'm wrapping the content inside a div with a data-ce-tag="static", although the thing is I don't know what will be inside that so I might be messing up the content by adding a div. The best thing I thought was to add starting & ending comment tags so I can keep track of them. They need to be inside the editable content though.

@anthonyjb
Copy link
Member

Ah OK that makes a lot of sense - if you use a static element then the content inside wont be parsed by the editor, however one thing to be aware of is since the library basically relies on the browsers innerHTML output for static elements it might come back a little bit different once saved and across different browsers - but it should still be valid HTML of course.

@bfintal
Copy link
Contributor Author

bfintal commented Oct 3, 2015

So will comments not be stripped out anymore? :)

@anthonyjb
Copy link
Member

So if you use comments in static elements they shouldn't be stripped - they certainly aren't in Chrome - however as I say it does depend on the innerHTML output of each browser.

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

2 participants