Skip to content

Commit 82fe977

Browse files
committed
generate-pdf.yml: test
1 parent a0479a3 commit 82fe977

File tree

17 files changed

+1989
-77
lines changed

17 files changed

+1989
-77
lines changed

.github/workflows/Quarkdown-Mock/index.html

Lines changed: 83 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Loading
394 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
executionQueue.push(() => {
2+
hljs.addPlugin(new CopyButtonPlugin()); // Add copy button to code blocks.
3+
hljs.highlightAll(); // Highlight all code blocks.
4+
hljs.initLineNumbersOnLoad(); // Show line numbers on code blocks.
5+
});
6+
7+
// Focuses specific lines in selected code blocks.
8+
function focusCodeLines() {
9+
document.querySelectorAll('code.focus-lines').forEach((code) => {
10+
const start = parseInt(code.getAttribute('data-focus-start'));
11+
const end = parseInt(code.getAttribute('data-focus-end'));
12+
code.querySelectorAll('.hljs-ln-line').forEach(line => {
13+
const lineNumber = parseInt(line.getAttribute('data-line-number'));
14+
// Open range support.
15+
if ((isNaN(start) || lineNumber >= start) && (isNaN(end) || lineNumber <= end)) {
16+
line.classList.add('focused');
17+
}
18+
});
19+
});
20+
}
21+
22+
hljs.addPlugin({
23+
'after:highlight': () => window.setTimeout(focusCodeLines, 1)
24+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
executionQueue.push(() => {
2+
MathJax = {
3+
tex: {
4+
displayMath: [['__QD_BLOCK_MATH__$', '$__QD_BLOCK_MATH__']],
5+
inlineMath: [['__QD_INLINE_MATH__$', '$__QD_INLINE_MATH__']]
6+
},
7+
svg: {
8+
fontCache: 'global'
9+
}
10+
};
11+
12+
// Script that enables MathJax rendering.
13+
let script = document.createElement('script');
14+
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
15+
script.async = true;
16+
script.id = 'MathJax-script';
17+
document.body.appendChild(script);
18+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
class PagedDocument extends QuarkdownDocument {
2+
populateExecutionQueue() {
3+
super.populateExecutionQueue();
4+
executionQueue.push(setColumnCount);
5+
}
6+
7+
copyPageMarginInitializers() {
8+
super.copyPageMarginInitializers();
9+
// <div class="page-margin-content-initializer page-margin-bottom-center">Hello</div>
10+
// will be copied to each page as:
11+
// <div class="pagedjs_margin-content">Hello</div>
12+
// contained in the .pagedjs_margin pagedjs_margin-top-left div.
13+
this.pageMarginInitializers.forEach(initializer => {
14+
const marginContent = document.createElement('div');
15+
marginContent.className = 'pagedjs_margin-content';
16+
marginContent.innerHTML = initializer.innerHTML;
17+
18+
// Given the initializer with class "page-margin-content-initializer page-margin-bottom-center",
19+
// the margin class will be "pagedjs_margin-bottom-center".
20+
const pageMargins = document.querySelectorAll('.pagedjs_margin-' + initializer.className.split('page-margin-').pop());
21+
pageMargins.forEach(pageMargin => {
22+
pageMargin.classList.add('hasContent'); // Required by paged.js to show the content.
23+
24+
// Append the content.
25+
const container = pageMargin.querySelector('.pagedjs_margin-content');
26+
container.classList.add(...initializer.classList); // Copy the classes, allows for styling.
27+
container.innerHTML = initializer.innerHTML; // Copy the content of the initializer to each page.
28+
});
29+
});
30+
}
31+
32+
updatePageNumberElements() {
33+
const pages = document.querySelectorAll('.pagedjs_page')
34+
// Inject the total amount of pages into .total-page-number elements.
35+
const amount = pages.length;
36+
document.querySelectorAll('.total-page-number').forEach(total => {
37+
total.innerText = amount;
38+
});
39+
40+
pages.forEach(page => {
41+
// Inject the current page number into .current-page-number elements.
42+
const number = page.getAttribute('data-page-number');
43+
page.querySelectorAll('.current-page-number').forEach(pageNumber => {
44+
pageNumber.innerText = number;
45+
});
46+
});
47+
}
48+
49+
beforeReady(content) {
50+
super.beforeReady(content);
51+
super.removeAllPageMarginInitializers()
52+
}
53+
54+
setupBeforeReadyHook() {
55+
class PagedBeforeReadyHandler extends Paged.Handler {
56+
beforeParsed(content) {
57+
doc.beforeReady(content);
58+
}
59+
}
60+
Paged.registerHandlers(PagedBeforeReadyHandler);
61+
}
62+
63+
setupAfterReadyHook() {
64+
class PagedAfterReadyHandler extends Paged.Handler {
65+
afterPreview() {
66+
executeQueue();
67+
}
68+
}
69+
Paged.registerHandlers(PagedAfterReadyHandler);
70+
}
71+
}
72+
73+
// Sets the column count of each page.
74+
// For some unknown reason, this has to be applied after the page is rendered to avoid visual glitches.
75+
// For non-paged documents, the column count is applied directly via CSS instead (see global.css).
76+
function setColumnCount() {
77+
const columnCount = getComputedStyle(document.body).getPropertyValue('--property-column-count')?.trim()
78+
if (!columnCount || columnCount === '') return; // No value set.
79+
80+
document.querySelectorAll('.pagedjs_page_content > div').forEach(content => {
81+
content.style.columnCount = columnCount;
82+
});
83+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// Actions to be executed after the document has been loaded.
3+
4+
let executionQueue = [];
5+
6+
let ready = false;
7+
8+
function executeQueue() {
9+
executionQueue.forEach((fn) => fn());
10+
ready = true;
11+
}
12+
13+
//
14+
// Different kinds of documents.
15+
16+
/**
17+
* A Quarkdown document, inherited by each specific document type.
18+
*/
19+
class QuarkdownDocument {
20+
pageMarginInitializers;
21+
22+
/**
23+
* Prepares the stages of the document runtime.
24+
*/
25+
prepare() {
26+
this.populateExecutionQueue();
27+
this.setupBeforeReadyHook();
28+
this.setupAfterReadyHook();
29+
}
30+
31+
/**
32+
* Hook to be executed before the document is ready.
33+
* For instance, this is run before paged.js or Reveal.js processes the content.
34+
* @param content pre-processed content
35+
*/
36+
beforeReady(content) {
37+
// A page margin content initializer is an element that will be copied into each section,
38+
// and is placed on one of the page margins.
39+
this.pageMarginInitializers = content.querySelectorAll('.page-margin-content');
40+
}
41+
42+
/**
43+
* Removes all page margin initializers from the document.
44+
*/
45+
removeAllPageMarginInitializers() {
46+
this.pageMarginInitializers.forEach(initializer => initializer.remove());
47+
}
48+
49+
/**
50+
* To be run after the document is ready.
51+
* This pastes the previously-loaded page margin initializers into each new processed page.
52+
*/
53+
copyPageMarginInitializers() {
54+
if (!this.pageMarginInitializers) {
55+
console.error('pageMarginInitializers not set');
56+
}
57+
}
58+
59+
/**
60+
* Updates the content of `.current-page-number` and `.total-page-number` elements.
61+
*/
62+
updatePageNumberElements() {}
63+
64+
/**
65+
* Populates the execution queue with the necessary functions to be executed after the document is ready.
66+
*/
67+
populateExecutionQueue() {
68+
executionQueue.push(
69+
() => this.copyPageMarginInitializers(),
70+
() => this.updatePageNumberElements()
71+
);
72+
}
73+
74+
/**
75+
* Sets up a hook called before the document is processed.
76+
*/
77+
setupBeforeReadyHook() {
78+
document.addEventListener('DOMContentLoaded', () => this.beforeReady(document));
79+
}
80+
81+
/**
82+
* Sets up a hook called after the document is processed.
83+
*/
84+
setupAfterReadyHook() {
85+
document.addEventListener('DOMContentLoaded', executeQueue);
86+
}
87+
}
88+
89+
class PlainDocument extends QuarkdownDocument {}
90+
91+
let doc = new PlainDocument(); // Overridden externally by html-wrapper
92+
93+
//
94+
// Enables toggling of the collapsed/expanded state of inline elements.
95+
96+
executionQueue.push(() => {
97+
// Add click event listener to the collapsible spans.
98+
const collapsibles = document.querySelectorAll('.inline-collapse');
99+
collapsibles.forEach((span) => {
100+
span.addEventListener('click', () => toggleCollapse(span));
101+
});
102+
});
103+
104+
function toggleCollapse(span) {
105+
const fullText = span.dataset.fullText;
106+
const collapsedText = span.dataset.collapsedText;
107+
const collapsed = span.dataset.collapsed === 'true';
108+
109+
// Toggle between the full and collapsed text.
110+
const content = collapsed ? fullText : collapsedText;
111+
112+
span.dataset.collapsed = (!collapsed).toString();
113+
114+
const isUserDefined = span.closest('.error') === null;
115+
if (isUserDefined) {
116+
span.innerHTML = content;
117+
} else {
118+
span.textContent = content;
119+
}
120+
}

0 commit comments

Comments
 (0)