Commit a603787f authored by Fred Chasen's avatar Fred Chasen
Browse files

Merge branch 'dot-in-ID' into 'master'

[#186] support for period characters in ID.

Closes #186

See merge request tools/pagedjs!100
parents e3646265 3890dc65
Pipeline #435 passed with stage
in 3 minutes and 34 seconds
......@@ -102,6 +102,7 @@
<ul>
<li><a href="#chap1">Lorem ipsum dolor sit amet</a></li>
<li><a href="#chap2">Praesent placerat lectus</a></li>
<li><a id="dot-id" href="#chap2.dot">This has a <code>.</code> in its id!</a></li>
<li>
<a href="#chap3">Aliquam eget massa loborti</a>
<ul>
......@@ -147,6 +148,7 @@
<p>
Proin eu quam id arcu interdum laoreet nec at urna. Vivamus non sem quis dolor sagittis facilisis. Nunc quis urna non neque sollicitudin hendrerit. Vestibulum odio velit, vestibulum vitae elementum convallis, tristique eu est. Sed vitae tortor sed purus accumsan euismod nec finibus lorem. Donec consectetur libero sit amet pretium eleifend. Nulla placerat ipsum sed eros aliquet, at venenatis purus convallis. Pellentesque pulvinar, justo eget tincidunt semper, augue massa placerat enim, non tempus quam erat eu orci. Suspendisse auctor consectetur lectus, a mattis odio. Pellentesque id sem sit amet justo fringilla bibendum id sit amet quam. Vivamus ex est, ultrices non pharetra eu, facilisis nec quam.
</p>
<h1 id="chap2.dot">chap2.dot</h1>
<p>
Etiam molestie sed orci sed suscipit. Donec ipsum est, venenatis ut nisl ut, viverra auctor diam. Cras vestibulum lacus vel nunc dapibus aliquam. Aliquam accumsan lorem rhoncus tortor rhoncus, ut euismod sapien ullamcorper. Vivamus et dictum lacus, eu pellentesque dolor. Suspendisse potenti. Mauris vitae volutpat odio. Duis vitae purus nec enim posuere efficitur at vitae nisl. Etiam enim nisl, rutrum in vestibulum nec, dapibus ut dui. Pellentesque imperdiet molestie ante quis feugiat. Sed nec felis congue, cursus ligula eget, bibendum est. Proin mattis, tortor non lobortis lobortis, nibh quam aliquam neque, sed tristique nibh ex aliquet felis. Phasellus non augue ac ante efficitur consectetur at at est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam dui enim, iaculis et felis ac, porta ullamcorper justo. Suspendisse potenti.
</p>
......
const TIMEOUT = 10000; // Some book might take longer than this to renderer
// the test for the target counters are problematics as we can’t find a way to find their value without recreating the whole thing in js.
describe('target-counter', () => {
let page;
let rendered;
......@@ -19,13 +20,18 @@ describe('target-counter', () => {
expect(text).toContain("(See p. ");
})
it('link to element with ID "chap2.dot" must been parsed by the lib', async () => {
let text = await page.$eval("#dot-id", (r) => window.getComputedStyle(r, '::after').content);
expect(text).toContain("counter");
})
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
// if (!DEBUG) {
// it('should create a pdf', async () => {
// let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
})
}
// expect(pdf).toMatchPDFSnapshot(1);
// })
// }
}
)
......@@ -14,6 +14,7 @@ class TargetCounters extends Handler {
onContent(funcNode, fItem, fList, declaration, rule) {
if (funcNode.name === "target-counter") {
let selector = csstree.generate(rule.ruleNode.prelude);
let first = funcNode.children.first();
let func = first.name;
......@@ -23,6 +24,7 @@ class TargetCounters extends Handler {
first.children.forEach((child) => {
if (child.type === "Identifier") {
args.push(child.name);
}
});
......@@ -56,7 +58,7 @@ class TargetCounters extends Handler {
variable: variable
};
});
// Replace with counter
funcNode.name = "counter";
funcNode.children = new csstree.List();
......@@ -65,6 +67,7 @@ class TargetCounters extends Handler {
loc: 0,
name: variable
});
if (styleIdentifier) {
funcNode.children.appendData({type: "Operator", loc: null, value: ","});
funcNode.children.appendData(styleIdentifier);
......@@ -77,7 +80,7 @@ class TargetCounters extends Handler {
let target = this.counterTargets[name];
let split = target.selector.split("::");
let query = split[0];
let queried = chunker.pagesArea.querySelectorAll(query + ":not([data-" + target.variable + "])");
queried.forEach((selected, index) => {
......
......@@ -35,7 +35,7 @@ export function getClientRects(element) {
*/
export function UUID() {
var d = new Date().getTime();
if (typeof performance !== "undefined" && typeof performance.now === "function"){
if (typeof performance !== "undefined" && typeof performance.now === "function") {
d += performance.now(); //use high-precision timer if available
}
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
......@@ -79,7 +79,7 @@ export function findCssSelector(ele) {
// document.querySelectorAll("#id") returns multiple if elements share an ID
if (ele.id &&
document.querySelectorAll("#" + cssEscape(ele.id)).length === 1) {
document.querySelectorAll("#" + cssEscape(ele.id)).length === 1) {
return "#" + cssEscape(ele.id);
}
......@@ -134,7 +134,7 @@ export function findCssSelector(ele) {
export function attr(element, attributes) {
for (var i = 0; i < attributes.length; i++) {
if(element.hasAttribute(attributes[i])) {
if (element.hasAttribute(attributes[i])) {
return element.getAttribute(attributes[i]);
}
}
......@@ -148,6 +148,7 @@ export function querySelectorEscape(value) {
throw new TypeError("`CSS.escape` requires an argument.");
}
var string = String(value);
var length = string.length;
var index = -1;
var codeUnit;
......@@ -155,6 +156,9 @@ export function querySelectorEscape(value) {
var firstCodeUnit = string.charCodeAt(0);
while (++index < length) {
codeUnit = string.charCodeAt(index);
// Note: there’s no need to special-case astral symbols, surrogate
// pairs, or lone surrogates.
......@@ -196,6 +200,15 @@ export function querySelectorEscape(value) {
continue;
}
// support for period character in id
if (codeUnit == 0x002E) {
if (string.charAt(0) == "#") {
result += "\\.";
continue;
}
}
// If the character is not handled by one of the above rules and is
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment