nizel-plugin-gfm 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gfm.iife.js +166 -83
- package/package.json +1 -1
package/dist/gfm.iife.js
CHANGED
|
@@ -26,87 +26,6 @@ var NizelGfm = (() => {
|
|
|
26
26
|
gfmPlugins: () => gfmPlugins
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
// ../plugin-alert/dist/index.js
|
|
30
|
-
var ALERT_TYPES = ["note", "tip", "important", "warning", "caution"];
|
|
31
|
-
var alertPlugin = (options = {}) => {
|
|
32
|
-
const blocks = Object.fromEntries(ALERT_TYPES.map((alertType) => [alertType, createAlertBlock(alertType, options)]));
|
|
33
|
-
return {
|
|
34
|
-
name: "alert",
|
|
35
|
-
blocks,
|
|
36
|
-
hooks: {
|
|
37
|
-
beforeParse: transformGitHubAlerts
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
var transformGitHubAlerts = (markdown) => {
|
|
42
|
-
const lines = markdown.split("\n");
|
|
43
|
-
const result = [];
|
|
44
|
-
let index = 0;
|
|
45
|
-
while (index < lines.length) {
|
|
46
|
-
const opener = /^ {0,3}> ?\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i.exec(lines[index]);
|
|
47
|
-
if (!opener) {
|
|
48
|
-
result.push(lines[index]);
|
|
49
|
-
index += 1;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const alertType = opener[1].toLowerCase();
|
|
53
|
-
const content = [];
|
|
54
|
-
index += 1;
|
|
55
|
-
while (index < lines.length) {
|
|
56
|
-
const quoteLine = /^ {0,3}> ?(.*)$/.exec(lines[index]);
|
|
57
|
-
if (!quoteLine)
|
|
58
|
-
break;
|
|
59
|
-
content.push(quoteLine[1]);
|
|
60
|
-
index += 1;
|
|
61
|
-
}
|
|
62
|
-
result.push(`::${alertType} ${alertTitle(alertType)}`);
|
|
63
|
-
result.push(...trimAlertContent(content));
|
|
64
|
-
result.push("::");
|
|
65
|
-
}
|
|
66
|
-
return result.join("\n");
|
|
67
|
-
};
|
|
68
|
-
var createAlertBlock = (alertType, options) => {
|
|
69
|
-
return {
|
|
70
|
-
name: alertType,
|
|
71
|
-
parse({ args, props }) {
|
|
72
|
-
const title = props.title ?? args[0] ?? "";
|
|
73
|
-
return { alertType, title: String(title) };
|
|
74
|
-
},
|
|
75
|
-
formats: {
|
|
76
|
-
html(node, ctx) {
|
|
77
|
-
if (node.type !== "customBlock" || !isAlertValue(node.value))
|
|
78
|
-
return "";
|
|
79
|
-
return renderAlert(node.value, node.children ?? [], ctx, options);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
var renderAlert = (value, children, ctx, options) => {
|
|
85
|
-
const rootClass = options.className ?? "alert";
|
|
86
|
-
const titleHtml = value.title ? `<p class="${rootClass}__title">${ctx.escape(value.title)}</p>` : "";
|
|
87
|
-
const contentHtml = ctx.render(children);
|
|
88
|
-
const escapedType = ctx.escape(value.alertType);
|
|
89
|
-
return `<div class="${ctx.escape(rootClass)} ${ctx.escape(rootClass)}--${escapedType}" data-alert="${escapedType}">${titleHtml}<div class="${ctx.escape(rootClass)}__content">${contentHtml}</div></div>`;
|
|
90
|
-
};
|
|
91
|
-
var trimAlertContent = (lines) => {
|
|
92
|
-
let start = 0;
|
|
93
|
-
let end = lines.length;
|
|
94
|
-
while (start < end && !lines[start].trim())
|
|
95
|
-
start += 1;
|
|
96
|
-
while (end > start && !lines[end - 1].trim())
|
|
97
|
-
end -= 1;
|
|
98
|
-
return lines.slice(start, end);
|
|
99
|
-
};
|
|
100
|
-
var alertTitle = (alertType) => {
|
|
101
|
-
return alertType.charAt(0).toUpperCase() + alertType.slice(1);
|
|
102
|
-
};
|
|
103
|
-
var isAlertValue = (value) => {
|
|
104
|
-
if (!value || typeof value !== "object")
|
|
105
|
-
return false;
|
|
106
|
-
const candidate = value;
|
|
107
|
-
return typeof candidate.title === "string" && ALERT_TYPES.includes(candidate.alertType);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
29
|
// ../nizel/dist/collect.js
|
|
111
30
|
function collect(ast) {
|
|
112
31
|
const headings = [];
|
|
@@ -4507,6 +4426,121 @@ ${body}
|
|
|
4507
4426
|
return plugin;
|
|
4508
4427
|
};
|
|
4509
4428
|
|
|
4429
|
+
// ../nizel/dist/html-to-markdown.js
|
|
4430
|
+
var htmlChildElements = (node) => node.type === "element" || node.type === "root" ? node.children.filter((child) => child.type === "element") : [];
|
|
4431
|
+
var findHtmlElement = (node, predicate) => htmlChildElements(node).find(predicate);
|
|
4432
|
+
var hasHtmlClass = (node, className) => node.type === "element" && (node.attrs.class ?? "").split(/\s+/).includes(className);
|
|
4433
|
+
var findHtmlDescendant = (node, predicate) => {
|
|
4434
|
+
for (const child of htmlChildElements(node)) {
|
|
4435
|
+
if (predicate(child))
|
|
4436
|
+
return child;
|
|
4437
|
+
const nested = findHtmlDescendant(child, predicate);
|
|
4438
|
+
if (nested)
|
|
4439
|
+
return nested;
|
|
4440
|
+
}
|
|
4441
|
+
return void 0;
|
|
4442
|
+
};
|
|
4443
|
+
var htmlRoot = (children) => ({ type: "root", children });
|
|
4444
|
+
|
|
4445
|
+
// ../plugin-alert/dist/index.js
|
|
4446
|
+
var ALERT_TYPES = ["note", "tip", "important", "warning", "caution"];
|
|
4447
|
+
var alertPlugin = (options = {}) => {
|
|
4448
|
+
const blocks = Object.fromEntries(ALERT_TYPES.map((alertType) => [alertType, createAlertBlock(alertType, options)]));
|
|
4449
|
+
return {
|
|
4450
|
+
name: "alert",
|
|
4451
|
+
blocks,
|
|
4452
|
+
hooks: {
|
|
4453
|
+
beforeParse: transformGitHubAlerts
|
|
4454
|
+
},
|
|
4455
|
+
htmlToMarkdown: alertToMarkdown(options)
|
|
4456
|
+
};
|
|
4457
|
+
};
|
|
4458
|
+
var alertToMarkdown = (options = {}) => {
|
|
4459
|
+
const rootClass = options.className ?? "alert";
|
|
4460
|
+
return (node, ctx) => {
|
|
4461
|
+
if (node.type !== "element" || node.tag !== "div")
|
|
4462
|
+
return void 0;
|
|
4463
|
+
const type = node.attrs["data-alert"];
|
|
4464
|
+
if (!type)
|
|
4465
|
+
return void 0;
|
|
4466
|
+
const titleEl = findHtmlElement(node, (el) => el.tag === "p" && hasHtmlClass(el, `${rootClass}__title`));
|
|
4467
|
+
const contentEl = findHtmlElement(node, (el) => hasHtmlClass(el, `${rootClass}__content`));
|
|
4468
|
+
const title = titleEl ? ctx.text(titleEl).trim() : "";
|
|
4469
|
+
const body = contentEl ? ctx.block(contentEl) : "";
|
|
4470
|
+
return `${title ? `::${type} ${title}` : `::${type}`}
|
|
4471
|
+
${body}
|
|
4472
|
+
::`;
|
|
4473
|
+
};
|
|
4474
|
+
};
|
|
4475
|
+
var transformGitHubAlerts = (markdown) => {
|
|
4476
|
+
const lines = markdown.split("\n");
|
|
4477
|
+
const result = [];
|
|
4478
|
+
let index = 0;
|
|
4479
|
+
while (index < lines.length) {
|
|
4480
|
+
const opener = /^ {0,3}> ?\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i.exec(lines[index]);
|
|
4481
|
+
if (!opener) {
|
|
4482
|
+
result.push(lines[index]);
|
|
4483
|
+
index += 1;
|
|
4484
|
+
continue;
|
|
4485
|
+
}
|
|
4486
|
+
const alertType = opener[1].toLowerCase();
|
|
4487
|
+
const content = [];
|
|
4488
|
+
index += 1;
|
|
4489
|
+
while (index < lines.length) {
|
|
4490
|
+
const quoteLine = /^ {0,3}> ?(.*)$/.exec(lines[index]);
|
|
4491
|
+
if (!quoteLine)
|
|
4492
|
+
break;
|
|
4493
|
+
content.push(quoteLine[1]);
|
|
4494
|
+
index += 1;
|
|
4495
|
+
}
|
|
4496
|
+
result.push(`::${alertType} ${alertTitle(alertType)}`);
|
|
4497
|
+
result.push(...trimAlertContent(content));
|
|
4498
|
+
result.push("::");
|
|
4499
|
+
}
|
|
4500
|
+
return result.join("\n");
|
|
4501
|
+
};
|
|
4502
|
+
var createAlertBlock = (alertType, options) => {
|
|
4503
|
+
return {
|
|
4504
|
+
name: alertType,
|
|
4505
|
+
parse({ args, props }) {
|
|
4506
|
+
const title = props.title ?? args[0] ?? "";
|
|
4507
|
+
return { alertType, title: String(title) };
|
|
4508
|
+
},
|
|
4509
|
+
formats: {
|
|
4510
|
+
html(node, ctx) {
|
|
4511
|
+
if (node.type !== "customBlock" || !isAlertValue(node.value))
|
|
4512
|
+
return "";
|
|
4513
|
+
return renderAlert(node.value, node.children ?? [], ctx, options);
|
|
4514
|
+
}
|
|
4515
|
+
}
|
|
4516
|
+
};
|
|
4517
|
+
};
|
|
4518
|
+
var renderAlert = (value, children, ctx, options) => {
|
|
4519
|
+
const rootClass = options.className ?? "alert";
|
|
4520
|
+
const titleHtml = value.title ? `<p class="${rootClass}__title">${ctx.escape(value.title)}</p>` : "";
|
|
4521
|
+
const contentHtml = ctx.render(children);
|
|
4522
|
+
const escapedType = ctx.escape(value.alertType);
|
|
4523
|
+
return `<div class="${ctx.escape(rootClass)} ${ctx.escape(rootClass)}--${escapedType}" data-alert="${escapedType}">${titleHtml}<div class="${ctx.escape(rootClass)}__content">${contentHtml}</div></div>`;
|
|
4524
|
+
};
|
|
4525
|
+
var trimAlertContent = (lines) => {
|
|
4526
|
+
let start = 0;
|
|
4527
|
+
let end = lines.length;
|
|
4528
|
+
while (start < end && !lines[start].trim())
|
|
4529
|
+
start += 1;
|
|
4530
|
+
while (end > start && !lines[end - 1].trim())
|
|
4531
|
+
end -= 1;
|
|
4532
|
+
return lines.slice(start, end);
|
|
4533
|
+
};
|
|
4534
|
+
var alertTitle = (alertType) => {
|
|
4535
|
+
return alertType.charAt(0).toUpperCase() + alertType.slice(1);
|
|
4536
|
+
};
|
|
4537
|
+
var isAlertValue = (value) => {
|
|
4538
|
+
if (!value || typeof value !== "object")
|
|
4539
|
+
return false;
|
|
4540
|
+
const candidate = value;
|
|
4541
|
+
return typeof candidate.title === "string" && ALERT_TYPES.includes(candidate.alertType);
|
|
4542
|
+
};
|
|
4543
|
+
|
|
4510
4544
|
// ../plugin-autolink/dist/index.js
|
|
4511
4545
|
var resolveAutolinkPluginOptions = (options = {}) => {
|
|
4512
4546
|
return {
|
|
@@ -4520,9 +4554,21 @@ ${body}
|
|
|
4520
4554
|
name: "autolink",
|
|
4521
4555
|
options: {
|
|
4522
4556
|
autolinks: resolveAutolinkPluginOptions(options)
|
|
4523
|
-
}
|
|
4557
|
+
},
|
|
4558
|
+
htmlToMarkdown: autolinkToMarkdown()
|
|
4524
4559
|
});
|
|
4525
4560
|
};
|
|
4561
|
+
var autolinkToMarkdown = () => (node, ctx) => {
|
|
4562
|
+
if (node.type !== "element" || node.tag !== "a")
|
|
4563
|
+
return void 0;
|
|
4564
|
+
const href = node.attrs.href;
|
|
4565
|
+
if (!href)
|
|
4566
|
+
return void 0;
|
|
4567
|
+
const extras = Object.keys(node.attrs).filter((key) => key !== "href" && key !== "target" && key !== "rel");
|
|
4568
|
+
if (extras.length > 0)
|
|
4569
|
+
return void 0;
|
|
4570
|
+
return ctx.text(node).trim() === href ? href : void 0;
|
|
4571
|
+
};
|
|
4526
4572
|
|
|
4527
4573
|
// ../plugin-task-list/dist/index.js
|
|
4528
4574
|
var taskListPlugin = (options = {}) => {
|
|
@@ -4533,9 +4579,46 @@ ${body}
|
|
|
4533
4579
|
afterParse(ast) {
|
|
4534
4580
|
return transformTaskLists(ast, mode);
|
|
4535
4581
|
}
|
|
4536
|
-
}
|
|
4582
|
+
},
|
|
4583
|
+
htmlToMarkdown: taskListToMarkdown()
|
|
4537
4584
|
};
|
|
4538
4585
|
};
|
|
4586
|
+
var CHECKBOX_ATTR = "data-nizel-task-checkbox";
|
|
4587
|
+
var isCheckbox = (node) => node.type === "element" && node.tag === "input" && node.attrs?.[CHECKBOX_ATTR] !== void 0;
|
|
4588
|
+
var taskListToMarkdown = () => (node, ctx) => {
|
|
4589
|
+
if (node.type !== "element" || node.tag !== "ul" && node.tag !== "ol")
|
|
4590
|
+
return void 0;
|
|
4591
|
+
const items = htmlChildElements(node).filter((el) => el.tag === "li");
|
|
4592
|
+
if (!items.some((item) => findHtmlDescendant(item, isCheckbox)))
|
|
4593
|
+
return void 0;
|
|
4594
|
+
const ordered = node.tag === "ol";
|
|
4595
|
+
const start = Number(node.attrs.start ?? 1);
|
|
4596
|
+
return items.map((item, index) => {
|
|
4597
|
+
const checkbox = findHtmlDescendant(item, isCheckbox);
|
|
4598
|
+
const body = ctx.block(htmlRoot(cleanTaskChildren(item.children))).trim();
|
|
4599
|
+
const baseMarker = ordered ? `${start + index}. ` : "- ";
|
|
4600
|
+
const marker = checkbox ? `${baseMarker}${checkbox.attrs.checked !== void 0 ? "[x] " : "[ ] "}` : baseMarker;
|
|
4601
|
+
return ctx.indent(`${marker}${body}`, marker.length);
|
|
4602
|
+
}).join("\n");
|
|
4603
|
+
};
|
|
4604
|
+
var cleanTaskChildren = (nodes) => {
|
|
4605
|
+
const result = [];
|
|
4606
|
+
for (const node of nodes) {
|
|
4607
|
+
if (node.type === "element") {
|
|
4608
|
+
if (isCheckbox(node))
|
|
4609
|
+
continue;
|
|
4610
|
+
const cleaned = { ...node, children: cleanTaskChildren(node.children) };
|
|
4611
|
+
if (hasHtmlClass(cleaned, "nizel-task-list__label") || hasHtmlClass(cleaned, "nizel-task-list__content")) {
|
|
4612
|
+
result.push(...cleaned.children);
|
|
4613
|
+
} else {
|
|
4614
|
+
result.push(cleaned);
|
|
4615
|
+
}
|
|
4616
|
+
} else {
|
|
4617
|
+
result.push(node);
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
return result;
|
|
4621
|
+
};
|
|
4539
4622
|
var transformTaskLists = (ast, mode = "view") => {
|
|
4540
4623
|
return { ...ast, children: ast.children.map((node) => transformBlock(node, mode)) };
|
|
4541
4624
|
};
|