Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Added template matching following innerHTML #441

Merged
merged 10 commits into from
Nov 3, 2016

Conversation

DamnedScholar
Copy link
Contributor

A forum thread has raised the fact that template strings can sometimes be used to assign innerHTML values and that the developer might not want to involve the html template handler. This PR proposes to detect template strings following innerHTML = as HTML templates and include text.html.basic just like the template handler does.

@winstliu
Copy link
Contributor

How common is innerHTML?

@Alhadis
Copy link
Contributor

Alhadis commented Oct 11, 2016

Uhm, extremely common...

@@ -1360,6 +1360,30 @@
]
}
{
'begin': '(?<=innerHTML)\\s*(=)\\s*(`)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May wanna make this (\\+?=) instead, to accommodate innerHTML +=.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely right. I've fixed that.

@DamnedScholar
Copy link
Contributor Author

innerHTML gets used virtually every time a script needs to directly manipulate the DOM. In this age of template handler functions and front-end frameworks, directly manipulating the DOM is often a less efficient way to achieve the same goal, but for small pages or cases where the user requires very precise control, assigning the innerHTML property directly is still valuable. Sometimes these strings can be lengthy in the file, so highlighting the HTML inside is very useful for a user who wants to work with the DOM in this manner.

@winstliu
Copy link
Contributor

winstliu commented Oct 17, 2016

Yeah, sorry for that comment. I thought we were still dealing with template string functions and completely forgot about the actual method.

This will need some tests.

@@ -1360,6 +1360,28 @@
]
}
{
'begin': '(?<=innerHTML\\s*(\\+?=)\\s*)(`)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookbehinds only support fixed-width regexes, so \\s* and stuff won't work. I would suggest going back to the previous regex and trying to make that one work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Aside: is there a way that I could set up a local testing environment so that I don't have to wait for Travis to finish each time I tweak something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run the package specs: View -> Developer -> Run Package Specs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm dumb.

@lukasoppermann
Copy link

Hey @50Wliu can this be merged? I am waiting for this very badly. Writing es6 class based components, I really need this.

@winstliu
Copy link
Contributor

winstliu commented Nov 1, 2016

I didn't get notifications for the two latest commits that fixed the specs. Thanks for the heads up.

@winstliu
Copy link
Contributor

winstliu commented Nov 1, 2016

So, I realize now that I didn't look closely enough at the specs for the last HTML-related PR before merging. If you notice, none of the HTML tags are being scoped as HTML. To fix that, I would recommend grouping all the HTML-related specs under a single describe 'HTML strings' (or something), and then adding the following code right after the describe:

beforeEach ->
    waitsForPromise ->
      atom.packages.activatePackage("language-html")

@DamnedScholar
Copy link
Contributor Author

DamnedScholar commented Nov 2, 2016

That breaks all of the HTML-related specs. I've excerpted that section of the file as I have it in a gist. The error message is wordy enough that I've put it in a gist, too.

If this is a problem with all of the related specs, I suggest merging this PR and opening another one to fix the specs in general. The grammar portion of the PR is fully functional and as of the latest commit, the spec I added functions at the same level as the pre-existing ones.

expect(tokens[0]).toEqual value: 'text', scopes: [ 'source.js', 'variable.other.object.js' ]
expect(tokens[1]).toEqual value: '.', scopes: [ 'source.js', 'meta.delimiter.property.period.js' ]
expect(tokens[2]).toEqual value: 'innerHTML', scopes: [ 'source.js', 'variable.other.property.js' ]
expect(tokens[3]).toEqual value: ' ', scopes: [ 'source.js', 'string.quoted.template.html.js' ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scopes are incorrect. string.quoted should only start at the actual backtick, not before it. You can probably fix that by removing the capturing portions of begin and making it a lookbehind followed by a lookahead. Then change name to contentName and move what was previously captured in begin to the patterns section. In addition end needs to be changed to a lookbehind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've fixed the scopes and updated the grammar so that the output is correct.

@winstliu winstliu merged commit 3da89a1 into atom:master Nov 3, 2016
@winstliu
Copy link
Contributor

winstliu commented Nov 3, 2016

Thanks!

@lukasoppermann
Copy link

Awesome thanks @DamnedScholar & @50Wliu. When will this be released?

@winstliu
Copy link
Contributor

winstliu commented Nov 3, 2016

Current ETA is Atom 1.13.

@lukasoppermann
Copy link

Hey @50Wliu, 1.13 or 1.11.3 (aka the next release)?

@winstliu
Copy link
Contributor

winstliu commented Nov 3, 2016

1.13.

@lukasoppermann
Copy link

Oh noo, this will be so long, any idea when it will be released? Aboutish?

@winstliu
Copy link
Contributor

winstliu commented Nov 3, 2016

1.13-beta will be out in the next few weeks or so, and 1.13 stable should be released sometime in December.

@lukasoppermann
Copy link

okay, thanks for the info

@DamnedScholar
Copy link
Contributor Author

@lukasoppermann You can always override the core package until this version is released in core. Just git clone, then apm link. It will override the core language-javascript automatically. When 1.13 is released, you can just delete the symbolic link in .atom/packages.

@winstliu
Copy link
Contributor

winstliu commented Nov 9, 2016

My apologies - this did not make it into Atom 1.13 (the release came sooner than I expected and it didn't make the cutoff). Sorry for the inconvenience, and I would follow @DamnedScholar's steps for now.

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

Successfully merging this pull request may close these issues.

4 participants