Bug 30831

Summary: Web Inspector: syntax highlight inline JS and CSS in HTML resources
Product: WebKit Reporter: Timothy Hatcher <timothy>
Component: Web Inspector (Deprecated)Assignee: Alexander Pavlov (apavlov) <apavlov>
Status: RESOLVED FIXED    
Severity: Normal CC: apavlov, aroben, bweinstein, joepeck, keishi, pfeldman, rik, robspychala, timothy
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
[PATCH] Suggested solution
yurys: review-
[PATCH] Comment addressed, added STYLE check in 2 places yurys: review+

Description Timothy Hatcher 2009-10-27 11:43:21 PDT
We should syntax highlight <script> and <style> blocks in HTML resources.
Comment 1 Anthony Ricaud 2009-10-29 17:24:02 PDT
*** Bug 19351 has been marked as a duplicate of this bug. ***
Comment 2 Brian Weinstein 2009-10-29 17:24:48 PDT
Can we do this in the inspector, or would it have to be done in the engine?
Comment 3 Timothy Hatcher 2009-10-29 19:44:41 PDT
We could do this in the Inspector.
Comment 4 Keishi Hattori 2009-10-31 04:09:07 PDT
I'll take this after I'm done with the new CSS syntax highlighter.
Comment 5 Alexander Pavlov (apavlov) 2011-01-03 15:12:30 PST
SourceHTMLTokenizer implements tokenization of the <script> tag contents with a SourceJavaScriptTokenizer, so we are good with that. We should implement a similar approach for the <style> tag and SourceCSSTokenizer.
Comment 6 Alexander Pavlov (apavlov) 2011-01-26 09:54:25 PST
Created attachment 80204 [details]
[PATCH] Suggested solution
Comment 7 Yury Semikhatsky 2011-01-28 02:24:02 PST
Comment on attachment 80204 [details]
[PATCH] Suggested solution

View in context: https://bugs.webkit.org/attachment.cgi?id=80204&action=review

> Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js:267
>                      if (this._condition.parseCondition & this._parseConditions.SCRIPT) {

You should add a check for STYLE state here, r- for this.
Comment 8 Alexander Pavlov (apavlov) 2011-01-28 03:43:23 PST
Created attachment 80436 [details]
[PATCH] Comment addressed, added STYLE check in 2 places
Comment 9 Yury Semikhatsky 2011-01-28 06:42:30 PST
Comment on attachment 80436 [details]
[PATCH] Comment addressed, added STYLE check in 2 places

View in context: https://bugs.webkit.org/attachment.cgi?id=80436&action=review

> Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js:268
>                          // Do not tokenize script tag contents, keep lexer state although processing "<".

Please update the comment to reflect that you're skipping style tag content as well.

> Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js:322
> +                    if (this._condition.parseCondition === this._parseConditions.SCRIPT || this._condition.parseCondition === this._parseConditions.STYLE) {

We should be consistent in using === vs & if there is no difference in case of SCRIPT and STYLE parse conditions I'd prefer ===
Comment 10 Alexander Pavlov (apavlov) 2011-01-28 07:30:29 PST
(In reply to comment #9)
> (From update of attachment 80436 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=80436&action=review
> 
> > Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js:268
> >                          // Do not tokenize script tag contents, keep lexer state although processing "<".
> 
> Please update the comment to reflect that you're skipping style tag content as well.

Done

> > Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js:322
> > +                    if (this._condition.parseCondition === this._parseConditions.SCRIPT || this._condition.parseCondition === this._parseConditions.STYLE) {
> 
> We should be consistent in using === vs & if there is no difference in case of SCRIPT and STYLE parse conditions I'd prefer ===

Alas, there is a difference. At times, we can have the ATTRIBUTE_VALUE or ATTRIBUTE flag set along with the SCRIPT or STYLE state (I have seen this break the highlighting). There is a special comment following the line quoted: "Fall through if expecting attributes", which mean this should not work if the ATTRIBUTE flag is set, so there is no point in fixing the consistency.
Comment 11 Alexander Pavlov (apavlov) 2011-01-28 07:49:18 PST
Committing to http://svn.webkit.org/repository/webkit/trunk ...
        M       Source/WebCore/ChangeLog
        M       Source/WebCore/inspector/front-end/SourceHTMLTokenizer.js
        M       Source/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
Committed r76943
Comment 12 Alexander Pavlov (apavlov) 2011-02-17 07:15:43 PST
Comment on attachment 80436 [details]
[PATCH] Comment addressed, added STYLE check in 2 places

Clearing cq? from a committed patch