Skip to content

Commit

Permalink
fix: epub:type="footnote" on non-aside element should not cause f…
Browse files Browse the repository at this point in the history
…ootnote layout

fix #1363
  • Loading branch information
MurakamiShinyu committed Jul 18, 2024
1 parent 6e04fd9 commit 1f21f56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/vivliostyle/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ a[epub|type="noteref"] {
line-height: 0.01;
}
a[epub|type="noteref"]:href-epub-type(footnote) {
a[epub|type="noteref"]:href-epub-type(footnote, aside) {
-adapt-template: url(user-agent.xml#footnote);
text-decoration: none;
}
Expand Down
17 changes: 12 additions & 5 deletions packages/core/src/vivliostyle/css-cascade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,10 @@ export class CheckNSTagAction extends ChainedAction {
}

export class CheckTargetEpubTypeAction extends ChainedAction {
constructor(public readonly epubTypePatt: RegExp) {
constructor(
public readonly epubTypePatt: RegExp,
public readonly targetLocalName?: string,
) {
super();
}

Expand All @@ -876,7 +879,10 @@ export class CheckTargetEpubTypeAction extends ChainedAction {
if (href && href.match(/^#/)) {
const id = href.substring(1);
const target = elem.ownerDocument.getElementById(id);
if (target) {
if (
target &&
(!this.targetLocalName || target.localName == this.targetLocalName)
) {
const epubType = target.getAttributeNS(Base.NS.epub, "type");
if (epubType && epubType.match(this.epubTypePatt)) {
this.chained.apply(cascadeInstance);
Expand Down Expand Up @@ -3779,10 +3785,11 @@ export class CascadeParserHandler
break;
case "-adapt-href-epub-type":
case "href-epub-type":
if (params && params.length == 1 && typeof params[0] == "string") {
if (params && params.length >= 1 && typeof params[0] == "string") {
const value = params[0] as string;
const patt = new RegExp(`(^|s)${Base.escapeRegExp(value)}(\$|s)`);
this.chain.push(new CheckTargetEpubTypeAction(patt));
const patt = new RegExp(`(^|\\s)${Base.escapeRegExp(value)}(\$|\\s)`);
const targetLocalName = params[1] as string;
this.chain.push(new CheckTargetEpubTypeAction(patt, targetLocalName));
} else {
this.chain.push(new CheckConditionAction("")); // always fails
}
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/vivliostyle/css-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,17 @@ export class Parser {
if (token.type === TokenType.IDENT) {
params = [token.text];
tokenizer.consume();
if (
text === "href-epub-type" &&
tokenizer.token().type === TokenType.COMMA
) {
tokenizer.consume();
token = tokenizer.token();
if (token.type === TokenType.IDENT) {
params.push(token.text);
tokenizer.consume();
}
}
break;
} else {
break pseudoclassType;
Expand Down

0 comments on commit 1f21f56

Please sign in to comment.