hotdocs 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/javascript/controllers/fetcher_controller.js +29 -0
- data/app/assets/javascript/controllers/search_controller.js +14 -7
- data/app/assets/stylesheets/hotdocs/application.css +57 -20
- data/app/helpers/hotdocs/application_helper.rb +12 -1
- data/app/views/layouts/hotdocs/application.html.erb +107 -82
- data/config/importmap.rb +1 -1
- data/lib/hotdocs/engine.rb +1 -2
- data/lib/hotdocs/kramdown_alerts.rb +92 -0
- data/lib/hotdocs/markdown.rb +21 -24
- data/lib/hotdocs/version.rb +1 -1
- data/lib/install/install.rb +163 -182
- data/lib/tasks/hotdocs_tasks.rake +3 -1
- metadata +47 -4
- data/lib/hotdocs/markdown.mjs +0 -177
data/lib/hotdocs/markdown.mjs
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
// Example usage:
|
2
|
-
// echo "# title" || deno --allow-read --allow-env --node-modules-dir=auto config/initializers/markdown.mjs
|
3
|
-
|
4
|
-
import remarkParse from "npm:remark-parse";
|
5
|
-
import remarkPrism from "npm:remark-prism";
|
6
|
-
import remarkRehype from "npm:remark-rehype";
|
7
|
-
import rehypeStringify from "npm:rehype-stringify";
|
8
|
-
import { unified } from "npm:unified";
|
9
|
-
|
10
|
-
process.stdin.on("data", async (data) => {
|
11
|
-
try {
|
12
|
-
const file = await unified()
|
13
|
-
.use(remarkParse)
|
14
|
-
.use(remarkDirective)
|
15
|
-
.use(remarkAdmonitions)
|
16
|
-
.use(remarkPrism)
|
17
|
-
// `allowDangerousHtml` to avoid sanitizing the raw Html from `data`
|
18
|
-
.use(remarkRehype, { allowDangerousHtml: true })
|
19
|
-
.use(rehypeStringify, { allowDangerousHtml: true })
|
20
|
-
.process(data);
|
21
|
-
process.stdout.write(String(file));
|
22
|
-
} catch (error) {
|
23
|
-
console.error(`Error: ${error.message}\nStack trace:\n${error.stack}`);
|
24
|
-
process.stdout.write(
|
25
|
-
`Error: ${error.message}<br />Stack trace:\n${error.stack}`
|
26
|
-
);
|
27
|
-
}
|
28
|
-
});
|
29
|
-
|
30
|
-
const ADMONITIONS = {
|
31
|
-
tip: {
|
32
|
-
svg: {
|
33
|
-
xmlns: "http://www.w3.org/2000/svg",
|
34
|
-
fill: "none",
|
35
|
-
viewBox: "0 0 24 24",
|
36
|
-
strokeWidth: "1.5",
|
37
|
-
stroke: "currentColor",
|
38
|
-
},
|
39
|
-
paths: [
|
40
|
-
{
|
41
|
-
strokeLinecap: "round",
|
42
|
-
strokeLinejoin: "round",
|
43
|
-
d: "M12 18v-5.25m0 0a6.01 6.01 0 0 0 1.5-.189m-1.5.189a6.01 6.01 0 0 1-1.5-.189m3.75 7.478a12.06 12.06 0 0 1-4.5 0m3.75 2.383a14.406 14.406 0 0 1-3 0M14.25 18v-.192c0-.983.658-1.823 1.508-2.316a7.5 7.5 0 1 0-7.517 0c.85.493 1.509 1.333 1.509 2.316V18",
|
44
|
-
},
|
45
|
-
],
|
46
|
-
},
|
47
|
-
info: {
|
48
|
-
svg: {
|
49
|
-
xmlns: "http://www.w3.org/2000/svg",
|
50
|
-
fill: "none",
|
51
|
-
viewBox: "0 0 24 24",
|
52
|
-
strokeWidth: "1.5",
|
53
|
-
stroke: "currentColor",
|
54
|
-
},
|
55
|
-
paths: [
|
56
|
-
{
|
57
|
-
strokeLinecap: "round",
|
58
|
-
strokeLinejoin: "round",
|
59
|
-
d: "m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z",
|
60
|
-
},
|
61
|
-
],
|
62
|
-
},
|
63
|
-
warning: {
|
64
|
-
svg: {
|
65
|
-
xmlns: "http://www.w3.org/2000/svg",
|
66
|
-
fill: "none",
|
67
|
-
viewBox: "0 0 24 24",
|
68
|
-
strokeWidth: "1.5",
|
69
|
-
stroke: "currentColor",
|
70
|
-
},
|
71
|
-
paths: [
|
72
|
-
{
|
73
|
-
strokeLinecap: "round",
|
74
|
-
strokeLinejoin: "round",
|
75
|
-
d: "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z",
|
76
|
-
},
|
77
|
-
],
|
78
|
-
},
|
79
|
-
danger: {
|
80
|
-
svg: {
|
81
|
-
xmlns: "http://www.w3.org/2000/svg",
|
82
|
-
fill: "none",
|
83
|
-
viewBox: "0 0 24 24",
|
84
|
-
strokeWidth: "1.5",
|
85
|
-
stroke: "currentColor",
|
86
|
-
},
|
87
|
-
paths: [
|
88
|
-
{
|
89
|
-
strokeLinecap: "round",
|
90
|
-
strokeLinejoin: "round",
|
91
|
-
d: "M15.362 5.214A8.252 8.252 0 0 1 12 21 8.25 8.25 0 0 1 6.038 7.047 8.287 8.287 0 0 0 9 9.601a8.983 8.983 0 0 1 3.361-6.867 8.21 8.21 0 0 0 3 2.48Z",
|
92
|
-
},
|
93
|
-
{
|
94
|
-
strokeLinecap: "round",
|
95
|
-
strokeLinejoin: "round",
|
96
|
-
d: "M12 18a3.75 3.75 0 0 0 .495-7.468 5.99 5.99 0 0 0-1.925 3.547 5.975 5.975 0 0 1-2.133-1.001A3.75 3.75 0 0 0 12 18Z",
|
97
|
-
},
|
98
|
-
],
|
99
|
-
},
|
100
|
-
};
|
101
|
-
|
102
|
-
import { directiveFromMarkdown } from "npm:mdast-util-directive";
|
103
|
-
import { directive } from "npm:micromark-extension-directive";
|
104
|
-
|
105
|
-
// https://github.com/remarkjs/remark-directive/blob/23b8f416da165b6ddaa4c5e7e82addaf6dcb96a9/lib/index.js
|
106
|
-
function remarkDirective() {
|
107
|
-
const self = this;
|
108
|
-
const data = self.data();
|
109
|
-
|
110
|
-
const micromarkExtensions =
|
111
|
-
data.micromarkExtensions || (data.micromarkExtensions = []);
|
112
|
-
const fromMarkdownExtensions =
|
113
|
-
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
|
114
|
-
|
115
|
-
const directiveContainer = directive();
|
116
|
-
// From:
|
117
|
-
// {
|
118
|
-
// text: {[codes.colon]: directiveText},
|
119
|
-
// flow: {[codes.colon]: [directiveContainer, directiveLeaf]}
|
120
|
-
// }
|
121
|
-
// To:
|
122
|
-
// {
|
123
|
-
// text: {},
|
124
|
-
// flow: {[codes.colon]: [directiveContainer]}
|
125
|
-
// }
|
126
|
-
directiveContainer.text = {};
|
127
|
-
directiveContainer.flow[Object.keys(directiveContainer.flow)[0]].pop();
|
128
|
-
|
129
|
-
micromarkExtensions.push(directiveContainer);
|
130
|
-
fromMarkdownExtensions.push(directiveFromMarkdown());
|
131
|
-
}
|
132
|
-
|
133
|
-
import { h, s } from "npm:hastscript";
|
134
|
-
import { visit } from "npm:unist-util-visit";
|
135
|
-
|
136
|
-
function remarkAdmonitions() {
|
137
|
-
return (tree) => {
|
138
|
-
visit(tree, (node) => {
|
139
|
-
if (node.type === "containerDirective") {
|
140
|
-
const level = node.name;
|
141
|
-
const admonition = ADMONITIONS[level];
|
142
|
-
if (!admonition) return;
|
143
|
-
|
144
|
-
const svg = s(
|
145
|
-
"svg.admonition__icon",
|
146
|
-
admonition.svg,
|
147
|
-
admonition.paths.map((path) => s("path", path))
|
148
|
-
);
|
149
|
-
|
150
|
-
const label = h("span.admonition__label", level.toLocaleUpperCase());
|
151
|
-
const header = h("div", { class: "admonition__header" }, [svg, label]);
|
152
|
-
const content = h("div", { class: "admonition__content" }, [
|
153
|
-
...node.children,
|
154
|
-
]);
|
155
|
-
|
156
|
-
node.tagName = "div";
|
157
|
-
node.properties = h("div", {
|
158
|
-
class: `admonition admonition--${level}`,
|
159
|
-
}).properties;
|
160
|
-
node.children = [header, content];
|
161
|
-
|
162
|
-
const decorateHast = (node) => {
|
163
|
-
Object.assign(node.data ?? (node.data = {}), {
|
164
|
-
hName: node.tagName,
|
165
|
-
hProperties: node.properties,
|
166
|
-
});
|
167
|
-
|
168
|
-
if (node.children && Array.isArray(node.children)) {
|
169
|
-
node.children.forEach(decorateHast);
|
170
|
-
}
|
171
|
-
};
|
172
|
-
|
173
|
-
decorateHast(node);
|
174
|
-
}
|
175
|
-
});
|
176
|
-
};
|
177
|
-
}
|