Commit ecb07c0b authored by julien's avatar julien

added test for target-content and implemented first-letter

parent ab191423
This diff is collapsed.
......@@ -15,11 +15,24 @@ describe('target-text', async () => {
})
it('Table of content should include chapter titles', async () => {
let text = await page.$eval("nav li:first-of-type a" , (r) => window.getComputedStyle(r, '::after').content);
let text = await page.$eval("nav li:nth-of-type(1) a" , (r) => window.getComputedStyle(r, '::after').content);
expect(text).toContain("Lorem ipsum dolor sit amet");
})
it('Table of content should include first-letter of the chapter title', async () => {
let text = await page.$eval("nav li:nth-of-type(2) a" , (r) => window.getComputedStyle(r, '::after').content);
expect(text).toContain("P");
})
it('Table of content should include the content of the before pseudo element', async () => {
let text = await page.$eval("nav li:nth-of-type(3) a" , (r) => window.getComputedStyle(r, '::after').content);
expect(text).toContain("before");
})
it('Table of content should include the content of the before pseudo element', async () => {
let text = await page.$eval("nav li:nth-of-type(4) a" , (r) => window.getComputedStyle(r, '::after').content);
expect(text).toContain("after");
})
// if (!DEBUG) {
// it('should create a pdf', async () => {
// let pdf = await page.pdf(PDF_SETTINGS);
......
import Handler from "../handler";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import csstree from "css-tree";
import { nodeAfter } from "../../utils/dom";
class TargetText extends Handler {
constructor(chunker, polisher, caller) {
......@@ -10,6 +11,7 @@ class TargetText extends Handler {
this.textTargets = {};
}
onContent(funcNode, fItem, fList, declaration, rule) {
if (funcNode.name === "target-text") {
let selector = csstree.generate(rule.ruleNode.prelude);
......@@ -17,6 +19,7 @@ class TargetText extends Handler {
let last = funcNode.children.last();
let func = first.name;
// Check csstree generate: explain why generate
let value = csstree.generate(funcNode);
let args = [];
......@@ -55,6 +58,7 @@ class TargetText extends Handler {
name: variable
});
}
}
afterParsed(fragment) {
......@@ -63,6 +67,7 @@ class TargetText extends Handler {
let split = target.selector.split("::");
let query = split[0];
let queried = fragment.querySelectorAll(query);
console.log(queried);
queried.forEach((selected, index) => {
let val = attr(selected, target.args);
let element = fragment.querySelector(querySelectorEscape(val));
......@@ -83,9 +88,31 @@ class TargetText extends Handler {
});
// this.styleSheet.insertRule(`[data-target-text="${selector}"]${psuedo} { content: "${element.textContent}" }`, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(`[data-target-text="${selector}"]${psuedo} { ${target.variable}: "${textContent}" }`, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(`[data-target-text="${selector}"]${psuedo} { ${target.variable}: "${textContent}" }`);
}
// first-letter
else if (target.style === "first-letter") {
let selector = UUID();
selected.setAttribute("data-target-text", selector);
let psuedo = "";
if (split.length > 1) {
psuedo += "::" + split[1];
}
let textContent = element.textContent.trim().replace(/["']/g, (match) => {
return "\\" + match;
}).replace(/[\n]/g, (match) => {
return "\\00000A";
});
this.styleSheet.insertRule(`[data-target-text="${selector}"]${psuedo} { ${target.variable}: "${textContent.charAt(0)}" }`);
}
} else {
console.warn("missed target", val);
}
......
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