This repository was archived by the owner on Oct 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
HTMLFileContent and component for extracting IDL fragments #46
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
dd775b5
WIP: Adding HTML Content parsing
m-cheung 58e5e48
Adding preliminary HTMLParsing and corresponding tests
m-cheung 32366c5
Merge branch 'htmlContent'
m-cheung 6376b3d
Renaming HTMLParser to HTMLFileContent and adding additional tests
m-cheung 959d608
Removing additional files
m-cheung b35f750
Adding some additional tests and filtering out examples / notes
m-cheung 853d12d
Adding additional tests
m-cheung 0f92a6b
Temporary work on pipeline
m-cheung b640239
Merge branch 'master' into htmlContent
m-cheung e9eb44d
Merge branch 'master' into htmlContent
m-cheung 5bcfc90
Merge branch 'master' into htmlContent
m-cheung a041087
Refactoring HTMLFileContent to correspond with HTMLLexer changes
m-cheung 5969d4b
Part 2 of refactor due to HTMLLexer changes
m-cheung ad7669e
Renaming components
m-cheung dd2bd1d
Removing parsing step from extractor
m-cheung f812b58
Removing unused variables and fixing comment styling
m-cheung ff6ad90
Fixing description for HTMLFileContents
m-cheung c5fb6fb
Removing requirement for HTTPRequest in HTMLFileContents
m-cheung c736c28
Allowing for nested excluded tags
m-cheung af4cd9d
Adding support for nested exclude tags
m-cheung 20932a6
Adding Future message with regards to nested pre tags
m-cheung 5f93bbb
Fixing minor formatting problem
m-cheung 30df62a
Additional documentation in IDLFragmentExtractor and HTMLFileContents
m-cheung 7c3d78e
Adding additional documentation to IDLFragmentExtractor
m-cheung 6865625
Formatting and style fixes on HTMLFileContents and IDLFragmentExtractor
m-cheung 2dc37e8
Minor changes to HTMLFileContents and removing unneeded test
m-cheung c93dec6
Addressing formatting changes in HTMLFileContents
m-cheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
'use strict'; | ||
|
||
foam.CLASS({ | ||
package: 'org.chromium.webidl', | ||
name: 'HTMLFileContents', | ||
|
||
documentation: 'An HTML file that stores the raw content of the response.', | ||
|
||
ids: ['url', 'timestamp'], | ||
|
||
properties: [ | ||
{ | ||
class: 'String', | ||
name: 'url', | ||
required: true, | ||
}, | ||
{ | ||
class: 'Date', | ||
name: 'timestamp', | ||
required: true, | ||
}, | ||
{ | ||
class: 'String', | ||
name: 'contents', | ||
}, | ||
{ | ||
class: 'Array', | ||
of: 'String', | ||
documentation: 'Any array of files referencing the URL of this file.', | ||
name: 'references', | ||
}, | ||
], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
'use strict'; | ||
|
||
foam.CLASS({ | ||
package: 'org.chromium.webidl', | ||
name: 'IDLFragmentExtractor', | ||
documentation: 'Extracts IDL Fragments from HTML files.', | ||
requires: [ | ||
'foam.parsers.html.HTMLLexer', | ||
'foam.parsers.html.TagType', | ||
], | ||
|
||
properties: [ | ||
{ | ||
name: 'file', | ||
of: 'org.chromium.webidl.HTMLFileContent', | ||
postSet: function(_, file) { | ||
this.idlFragments = this.extract(); | ||
}, | ||
}, | ||
{ | ||
name: 'idlFragments', | ||
// description: 'all idlFragments found in the parsed HTML file', | ||
}, | ||
], | ||
|
||
methods: [ | ||
function extract() { | ||
var lexer = this.HTMLLexer.create(); | ||
var OPEN = this.TagType.OPEN.name; | ||
var CLOSE = this.TagType.CLOSE.name; | ||
var extractAttr = function(node, attrName) { | ||
var retVal = []; | ||
node.attributes.forEach(function(attr) { | ||
if (attr.name === attrName) { | ||
retVal = retVal.concat(attr.value.split(' ')); | ||
} | ||
}); | ||
return retVal; | ||
}; | ||
|
||
var results = lexer.parseString(this.file.contents).value; | ||
if (!results) throw new Error("IDL Parse was not successful."); | ||
|
||
var idlFragments = []; | ||
var tagStack = []; // Used for tag matching. | ||
var excludeStack = []; // Used for tracking excluded (example/note) tags. | ||
var tagMatching = true; // Set whe not inside a pre tag of interest. | ||
var content = ''; // Used to group together related content. | ||
for (var i = 0; i < results.length; i++) { | ||
var item = results[i]; | ||
var isTag = lexer.Tag.isInstance(item); | ||
|
||
// FUTURE: Handle nested pre tags. | ||
// As of this writing, there has not been any IDL fragments | ||
// that has been found within nested pre tags. | ||
if (!tagMatching) { | ||
// Ignoring all tags. Only extracting text content within pre tags. | ||
if (isTag) { | ||
if (item.nodeName === 'pre') { | ||
tagMatching = true; | ||
tagStack.pop(); | ||
idlFragments.push(lexer.lib.unescapeString(content)); | ||
content = ''; | ||
} | ||
} else { | ||
// item is text fragments, so we append it. | ||
content += item; | ||
} | ||
} else if (isTag) { | ||
// Encountered a tag and we are tag matching. | ||
// Perform appropriate action based on class attribute and tagType. | ||
var top = tagStack[tagStack.length - 1]; | ||
var classes = extractAttr(item, 'class'); | ||
var isIDL = classes && classes.includes('idl'); | ||
var isExcluded = function(cls) { | ||
return cls && (cls.includes('example') || cls.includes('note')); | ||
}; | ||
|
||
if (item.type.name === OPEN) { | ||
if (isExcluded(classes)) { | ||
// Entering the body of an excluded tag. | ||
excludeStack.push(item); | ||
} else if (excludeStack.length === 0 | ||
&& item.nodeName === 'pre' && isIDL) { | ||
// Found a <pre class="idl.*">. | ||
// Ignore tags and only extract text now. | ||
tagMatching = false; | ||
} | ||
tagStack.push(item); | ||
} else if (top && item.type.name === CLOSE | ||
&& top.nodeName === item.nodeName) { | ||
// Item is a close tag matching the tag at the top of the stack. | ||
// Aliasing for readability. | ||
var openTag = top; | ||
var closeTag = item; | ||
|
||
var openTagCls = extractAttr(openTag, 'class'); | ||
var excludeStackTop = excludeStack[excludeStack.length - 1]; | ||
if (isExcluded(openTagCls) && | ||
closeTag.nodeName === excludeStackTop.nodeName) { | ||
excludeStack.pop(); | ||
} | ||
tagStack.pop(); | ||
} else { | ||
// Mismatched close tags and OPEN_CLOSE tags are ignored. | ||
} | ||
} | ||
} | ||
return idlFragments; | ||
}, | ||
], | ||
}); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[Exposed=(Window,Worker,Worklet)] | ||
namespace console { // but see namespace object requirements below | ||
// Logging | ||
void assert(optional boolean condition = false, any... data); | ||
void clear(); | ||
void count(optional DOMString label = "default"); | ||
void debug(any... data); | ||
void error(any... data); | ||
void info(any... data); | ||
void log(any... data); | ||
void table(any tabularData, optional sequence<DOMString> properties); | ||
void trace(any... data); | ||
void warn(any... data); | ||
void dir(any item, optional object? options); | ||
void dirxml(any... data); | ||
|
||
// Grouping | ||
void group(any... data); | ||
void groupCollapsed(any... data); | ||
void groupEnd(); | ||
|
||
// Timing | ||
void time(optional DOMString label = "default"); | ||
void timeEnd(optional DOMString label = "default"); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[Exposed=(Window,Worker,Worklet)] | ||
namespace console { // but see namespace object requirements below | ||
// Logging | ||
void assert(optional boolean condition = false, any... data); | ||
void clear(); | ||
void count(optional DOMString label = "default"); | ||
void debug(any... data); | ||
void error(any... data); | ||
void info(any... data); | ||
void log(any... data); | ||
void table(any tabularData, optional sequence<DOMString> properties); | ||
void trace(any... data); | ||
void warn(any... data); | ||
void dir(any item, optional object? options); | ||
void dirxml(any... data); | ||
|
||
// Grouping | ||
void group(any... data); | ||
void groupCollapsed(any... data); | ||
void groupEnd(); | ||
|
||
// Timing | ||
void time(optional DOMString label = "default"); | ||
void timeEnd(optional DOMString label = "default"); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits: usually in order: class, of, documentation, name. Please uncomment documentation.