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

Parser changes to match coming update to the spec for the new ruby model #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/html5/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1839,8 +1839,10 @@ var Parser = HTML5.Parser = function HTML5Parser(options) {
optgroup: 'startTagOptionOptgroup',
math: 'startTagMath',
svg: 'startTagSVG',
rt: 'startTagRpRt',
rp: 'startTagRpRt',
rt: 'startTagRpRtRbRtc',
rp: 'startTagRpRtRbRtc',
rb: 'startTagRpRtRbRtc',
rtc: 'startTagRpRtRbRtc',
"-default": 'startTagOther'
};

Expand Down Expand Up @@ -2003,9 +2005,14 @@ var Parser = HTML5.Parser = function HTML5Parser(options) {
}
};

phases.inBody.startTagRpRt = function(name, attributes) {
phases.inBody.startTagRpRtRbRtc = function(name, attributes) {
if (this.inScope('ruby')) {
tree.generateImpliedEndTags();
if (name === 'rt') {
tree.generateImpliedEndTags('rtc');
}
else {
tree.generateImpliedEndTags();
}
if (tree.open_elements.last().tagName.toLowerCase() != 'ruby') {
parser.parse_error('unexpected-start-tag', {name: name});
}
Expand Down Expand Up @@ -2344,7 +2351,7 @@ var Parser = HTML5.Parser = function HTML5Parser(options) {
}

/// @todo Emit parse error on end tags other than the ones listed in http://www.w3.org/TR/html5/tree-construction.html#parsing-main-inbody
// ['dd', 'dt', 'li', 'optgroup', 'option', 'p', 'rp', 'rt', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'body', 'html']
// ['dd', 'dt', 'li', 'optgroup', 'option', 'p', 'rp', 'rt', 'rb', 'rtc', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'body', 'html']
if (tree.open_elements.last().tagName.toLowerCase() != 'body') {
parser.parse_error('expected-one-end-tag-but-got-another', {
expectedName: tree.open_elements.last().tagName.toLowerCase(),
Expand All @@ -2361,7 +2368,7 @@ var Parser = HTML5.Parser = function HTML5Parser(options) {
}

/// @todo Emit parse error on end tags other than the ones listed in http://www.w3.org/TR/html5/tree-construction.html#parsing-main-inbody
// ['dd', 'dt', 'li', 'optgroup', 'option', 'p', 'rp', 'rt', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'body', 'html']
// ['dd', 'dt', 'li', 'optgroup', 'option', 'p', 'rp', 'rt', 'rb', 'rtc', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'body', 'html']
if (tree.open_elements.last().tagName.toLowerCase() != 'body') {
parser.parse_error('expected-one-end-tag-but-got-another', {
expectedName: tree.open_elements.last().tagName.toLowerCase(),
Expand Down
2 changes: 1 addition & 1 deletion lib/html5/treebuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ b.prototype.generateImpliedEndTags = function(exclude) {
return
}
var name = this.open_elements.last().tagName.toLowerCase();
if(['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'].indexOf(name) != -1 && name != exclude) {
if(['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt', 'rb', 'rtc'].indexOf(name) != -1 && name != exclude) {
var p = this.pop_element();
this.generateImpliedEndTags(exclude);
}
Expand Down