-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_flow.js
More file actions
44 lines (38 loc) · 1.79 KB
/
fix_flow.js
File metadata and controls
44 lines (38 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import fs from 'fs';
const filePath = '/home/ga/md/public/modules/layout-preprocessor.js';
let content = fs.readFileSync(filePath, 'utf8');
// 1. Add data-layout to markers
content = content.replace(
/case 'columns-open':\s+marker\.className = 'md-columns-token-start';\s+marker\.dataset\.count = token\.attrs\.count \|\| '2';\s+marker\.dataset\.gap = token\.attrs\.gap \|\| '20pt';\s+marker\.dataset\.rule = token\.attrs\.rule \|\| 'false';\s+break;/g,
"case 'columns-open':\\n marker.className = 'md-columns-token-start';\\n marker.dataset.count = token.attrs.count || '2';\\n marker.dataset.gap = token.attrs.gap || '20pt';\\n marker.dataset.rule = token.attrs.rule || 'false';\\n marker.dataset.layout = 'columns';\\n break;"
);
// 2. Insert applyColumnsGuard call in postProcessHTML
content = content.replace(
/this\.applyTableLayouts\(doc\);/g,
"this.applyTableLayouts(doc);\\n this.applyColumnsGuard(doc);"
);
// 3. Add applyColumnsGuard method
const newMethod = \`
/**
* Column Guard
* Prevents content following a column block from being pulled into empty space
* on the page where the column block started, which can cause reordering.
*/
applyColumnsGuard(doc) {
doc.querySelectorAll('.md-columns').forEach(el => {
let next = el.nextElementSibling;
while (next && (next.classList.contains('md-columns-token-end') || next.tagName === 'BR')) {
next = next.nextElementSibling;
}
if (next && (next.tagName.startsWith('H') || next.tagName === 'P')) {
next.style.breakBefore = 'column';
next.style.pageBreakBefore = 'column';
}
});
}
\`;
content = content.replace(
/applySectionBreaks\(doc\) \{/g,
newMethod + "\\n applySectionBreaks(doc) {"
);
fs.writeFileSync(filePath, content);