@goldstack/utils-docs 0.3.17
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/README.md +7 -0
- package/dist/githubConstants.d.ts +5 -0
- package/dist/githubConstants.d.ts.map +1 -0
- package/dist/githubConstants.js +8 -0
- package/dist/githubConstants.js.map +1 -0
- package/dist/markdownToHtml.d.ts +2 -0
- package/dist/markdownToHtml.d.ts.map +1 -0
- package/dist/markdownToHtml.js +64 -0
- package/dist/markdownToHtml.js.map +1 -0
- package/dist/markdownToHtml.spec.d.ts +2 -0
- package/dist/markdownToHtml.spec.d.ts.map +1 -0
- package/dist/markdownToHtml.spec.js +18 -0
- package/dist/markdownToHtml.spec.js.map +1 -0
- package/dist/permalinkIconAst.d.ts +3 -0
- package/dist/permalinkIconAst.d.ts.map +1 -0
- package/dist/permalinkIconAst.js +32 -0
- package/dist/permalinkIconAst.js.map +1 -0
- package/dist/rehypeDocs.d.ts +6 -0
- package/dist/rehypeDocs.d.ts.map +1 -0
- package/dist/rehypeDocs.js +76 -0
- package/dist/rehypeDocs.js.map +1 -0
- package/dist/rehypeMarkdownToHtml.d.ts +6 -0
- package/dist/rehypeMarkdownToHtml.d.ts.map +1 -0
- package/dist/rehypeMarkdownToHtml.js +77 -0
- package/dist/rehypeMarkdownToHtml.js.map +1 -0
- package/dist/rehypeMarkdownToMarkdown.d.ts +4 -0
- package/dist/rehypeMarkdownToMarkdown.d.ts.map +1 -0
- package/dist/rehypeMarkdownToMarkdown.js +73 -0
- package/dist/rehypeMarkdownToMarkdown.js.map +1 -0
- package/dist/resolveMarkdown.d.ts +2 -0
- package/dist/resolveMarkdown.d.ts.map +1 -0
- package/dist/resolveMarkdown.js +34 -0
- package/dist/resolveMarkdown.js.map +1 -0
- package/dist/resolveMarkdown.spec.d.ts +2 -0
- package/dist/resolveMarkdown.spec.d.ts.map +1 -0
- package/dist/resolveMarkdown.spec.js +16 -0
- package/dist/resolveMarkdown.spec.js.map +1 -0
- package/dist/utilsDocs.d.ts +8 -0
- package/dist/utilsDocs.d.ts.map +1 -0
- package/dist/utilsDocs.js +25 -0
- package/dist/utilsDocs.js.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Goldstack Documentation Utilities
|
|
2
|
+
|
|
3
|
+
Utilities for generating documentation based on the way [Next.js are generating their documentation](https://github.com/vercel/next-site/tree/e2cb07a057bf75bded2571a1b639b0017572f4b8/lib/docs)
|
|
4
|
+
|
|
5
|
+
The logic for embedding Markdown files draws from [gatsby-remark-embed-markdown](https://github.com/jtstodola/gatsby-remark-embed-markdown).
|
|
6
|
+
|
|
7
|
+
This library is used for generating the [Goldstack Documentation](https://docs.goldstack.party/docs/goldstack/about).
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const GITHUB_URL = "https://github.com";
|
|
2
|
+
export declare const GITHUB_API_URL = "https://api.github.com";
|
|
3
|
+
export declare const RAW_GITHUB_URL = "https://raw.githubusercontent.com";
|
|
4
|
+
export declare const REPO_NAME = "goldstack/goldstack";
|
|
5
|
+
//# sourceMappingURL=githubConstants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubConstants.d.ts","sourceRoot":"","sources":["../src/githubConstants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,uBAAuB,CAAC;AAE/C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,eAAO,MAAM,cAAc,sCAAsC,CAAC;AAElE,eAAO,MAAM,SAAS,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPO_NAME = exports.RAW_GITHUB_URL = exports.GITHUB_API_URL = exports.GITHUB_URL = void 0;
|
|
4
|
+
exports.GITHUB_URL = 'https://github.com';
|
|
5
|
+
exports.GITHUB_API_URL = 'https://api.github.com';
|
|
6
|
+
exports.RAW_GITHUB_URL = 'https://raw.githubusercontent.com';
|
|
7
|
+
exports.REPO_NAME = 'goldstack/goldstack';
|
|
8
|
+
//# sourceMappingURL=githubConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubConstants.js","sourceRoot":"","sources":["../src/githubConstants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,oBAAoB,CAAC;AAElC,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAE1C,QAAA,cAAc,GAAG,mCAAmC,CAAC;AAErD,QAAA,SAAS,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownToHtml.d.ts","sourceRoot":"","sources":["../src/markdownToHtml.ts"],"names":[],"mappings":"AAkCA,wBAAsB,cAAc,CAAC,QAAQ,KAAA,EAAE,GAAG,KAAA,EAAE,EAAE,KAAA,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBvE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// based on https://github.com/vercel/next-site/blob/e2cb07a057bf75bded2571a1b639b0017572f4b8/lib/docs/markdown-to-html.js
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.markdownToHtml = void 0;
|
|
8
|
+
const unified_1 = __importDefault(require("unified"));
|
|
9
|
+
const remark_parse_1 = __importDefault(require("remark-parse"));
|
|
10
|
+
const remark_rehype_1 = __importDefault(require("remark-rehype"));
|
|
11
|
+
const rehype_raw_1 = __importDefault(require("rehype-raw"));
|
|
12
|
+
const rehype_prism_1 = __importDefault(require("@mapbox/rehype-prism"));
|
|
13
|
+
const rehype_stringify_1 = __importDefault(require("rehype-stringify"));
|
|
14
|
+
// https://github.com/syntax-tree/hast-util-sanitize/blob/master/lib/github.json
|
|
15
|
+
const github_json_1 = __importDefault(require("hast-util-sanitize/lib/github.json"));
|
|
16
|
+
const rehypeDocs_1 = __importDefault(require("./rehypeDocs"));
|
|
17
|
+
const rehypeMarkdownToHtml_1 = __importDefault(require("./rehypeMarkdownToHtml"));
|
|
18
|
+
// Allow className for all elements
|
|
19
|
+
github_json_1.default.attributes['*'].push('className');
|
|
20
|
+
const handlers = {
|
|
21
|
+
// Add a className to inlineCode so we can differentiate between it and code fragments
|
|
22
|
+
inlineCode(h, node) {
|
|
23
|
+
return {
|
|
24
|
+
...node,
|
|
25
|
+
type: 'element',
|
|
26
|
+
tagName: 'code',
|
|
27
|
+
properties: { className: 'inline' },
|
|
28
|
+
children: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
value: node.value,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
async function markdownToHtml(filePath, tag, md) {
|
|
38
|
+
try {
|
|
39
|
+
// Init the processor with our custom plugin
|
|
40
|
+
let processor = undefined;
|
|
41
|
+
processor = (0, unified_1.default)()
|
|
42
|
+
.use(remark_parse_1.default)
|
|
43
|
+
.use(rehypeMarkdownToHtml_1.default, { filePath, tag, processor: () => processor })
|
|
44
|
+
.use(remark_rehype_1.default, { handlers, allowDangerousHTML: true })
|
|
45
|
+
// Add custom HTML found in the markdown file to the AST
|
|
46
|
+
.use(rehype_raw_1.default)
|
|
47
|
+
// Sanitize the HTML
|
|
48
|
+
// .use(sanitize, githubSchema)
|
|
49
|
+
// Add syntax highlighting to the sanitized HTML
|
|
50
|
+
.use(rehype_prism_1.default)
|
|
51
|
+
.use(rehype_stringify_1.default)
|
|
52
|
+
.freeze()()
|
|
53
|
+
.use(rehypeDocs_1.default, { filePath, tag, processor });
|
|
54
|
+
const file = await processor.process(md);
|
|
55
|
+
// Replace non-breaking spaces (char code 160) with normal spaces to avoid style issues
|
|
56
|
+
return file.contents.replace(/\xA0/g, ' ');
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(`Markdown to HTML error: ${error}`);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.markdownToHtml = markdownToHtml;
|
|
64
|
+
//# sourceMappingURL=markdownToHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownToHtml.js","sourceRoot":"","sources":["../src/markdownToHtml.ts"],"names":[],"mappings":";AAAA,0HAA0H;;;;;;AAE1H,sDAA8B;AAC9B,gEAAoC;AACpC,kEAA2C;AAC3C,4DAA6B;AAC7B,wEAAyC;AACzC,wEAAoC;AACpC,gFAAgF;AAChF,qFAA8D;AAC9D,8DAAgC;AAChC,kFAAoD;AAEpD,mCAAmC;AACnC,qBAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAE/C,MAAM,QAAQ,GAAG;IACf,sFAAsF;IACtF,UAAU,CAAC,CAAC,EAAE,IAAI;QAChB,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE;YACnC,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEK,KAAK,UAAU,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE;IACpD,IAAI;QACF,4CAA4C;QAC5C,IAAI,SAAS,GAAQ,SAAS,CAAC;QAC/B,SAAS,GAAG,IAAA,iBAAO,GAAE;aAClB,GAAG,CAAC,sBAAe,CAAC;aACpB,GAAG,CAAC,8BAAc,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;aAClE,GAAG,CAAC,uBAAc,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;YAC5D,wDAAwD;aACvD,GAAG,CAAC,oBAAG,CAAC;YACT,oBAAoB;YACpB,+BAA+B;YAC/B,gDAAgD;aAC/C,GAAG,CAAC,sBAAK,CAAC;aACV,GAAG,CAAC,0BAAI,CAAC;aACT,MAAM,EAAE,EAAE;aACV,GAAG,CAAC,oBAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAEzC,uFAAuF;QACvF,OAAQ,IAAI,CAAC,QAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;KACrD;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;QAClD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAzBD,wCAyBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownToHtml.spec.d.ts","sourceRoot":"","sources":["../src/markdownToHtml.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const markdownToHtml_1 = require("./markdownToHtml");
|
|
4
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
5
|
+
describe('markdownToHtml', () => {
|
|
6
|
+
it('Should render documentation markdown to html', async () => {
|
|
7
|
+
const result = await (0, markdownToHtml_1.markdownToHtml)(__dirname + '/markdown/configure.md', {}, (0, utils_sh_1.read)(__dirname + '/markdown/configure.md'));
|
|
8
|
+
expect(result).toContain('<p>');
|
|
9
|
+
expect(result).toContain('<a');
|
|
10
|
+
});
|
|
11
|
+
it('Should render documentation with embedded documents', async () => {
|
|
12
|
+
const file = __dirname + '/markdown/template-s3.md';
|
|
13
|
+
const result = await (0, markdownToHtml_1.markdownToHtml)(file, {}, (0, utils_sh_1.read)(file));
|
|
14
|
+
expect(result).toContain('<p>');
|
|
15
|
+
expect(result).toContain('<a');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=markdownToHtml.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownToHtml.spec.js","sourceRoot":"","sources":["../src/markdownToHtml.spec.ts"],"names":[],"mappings":";;AAAA,qDAAkD;AAClD,kDAA2C;AAE3C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAc,EACjC,SAAS,GAAG,wBAAwB,EACpC,EAAE,EACF,IAAA,eAAI,EAAC,SAAS,GAAG,wBAAwB,CAAC,CAC3C,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,IAAI,GAAG,SAAS,GAAG,0BAA0B,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAc,EAAC,IAAI,EAAE,EAAE,EAAE,IAAA,eAAI,EAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permalinkIconAst.d.ts","sourceRoot":"","sources":["../src/permalinkIconAst.ts"],"names":[],"mappings":"AAuBA,QAAA,MAAM,aAAa,KAGjB,CAAC;AAEH,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const unified_1 = __importDefault(require("unified"));
|
|
7
|
+
const rehype_raw_1 = __importDefault(require("rehype-raw"));
|
|
8
|
+
const ICON_HTML = `<svg viewBox="0 0 16 16" width="16" height="16">
|
|
9
|
+
<g strokeWidth="1" fill="#000000" stroke="#000000">
|
|
10
|
+
<path
|
|
11
|
+
fill="none"
|
|
12
|
+
strokeLinecap="round"
|
|
13
|
+
strokeLinejoin="round"
|
|
14
|
+
strokeMiterlimit="10"
|
|
15
|
+
d="M8.995,7.005 L8.995,7.005c1.374,1.374,1.374,3.601,0,4.975l-1.99,1.99c-1.374,1.374-3.601,1.374-4.975,0l0,0c-1.374-1.374-1.374-3.601,0-4.975 l1.748-1.698"
|
|
16
|
+
/>
|
|
17
|
+
<path
|
|
18
|
+
fill="none"
|
|
19
|
+
stroke="#000000"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
strokeLinejoin="round"
|
|
22
|
+
strokeMiterlimit="10"
|
|
23
|
+
d="M7.005,8.995 L7.005,8.995c-1.374-1.374-1.374-3.601,0-4.975l1.99-1.99c1.374-1.374,3.601-1.374,4.975,0l0,0c1.374,1.374,1.374,3.601,0,4.975 l-1.748,1.698"
|
|
24
|
+
/>
|
|
25
|
+
</g>
|
|
26
|
+
</svg>`;
|
|
27
|
+
const permalinkIcon = (0, unified_1.default)().use(rehype_raw_1.default).runSync({
|
|
28
|
+
type: 'raw',
|
|
29
|
+
value: ICON_HTML,
|
|
30
|
+
});
|
|
31
|
+
exports.default = permalinkIcon;
|
|
32
|
+
//# sourceMappingURL=permalinkIconAst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permalinkIconAst.js","sourceRoot":"","sources":["../src/permalinkIconAst.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,4DAA6B;AAE7B,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;OAkBX,CAAC;AAER,MAAM,aAAa,GAAG,IAAA,iBAAO,GAAE,CAAC,GAAG,CAAC,oBAAG,CAAC,CAAC,OAAO,CAAC;IAC/C,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC;AAEH,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeDocs.d.ts","sourceRoot":"","sources":["../src/rehypeDocs.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE;;;;CAAA,UAmE3B,GAAG,KAAG,IAAI,CAI7C"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
7
|
+
const mdast_util_to_string_1 = __importDefault(require("mdast-util-to-string"));
|
|
8
|
+
const github_slugger_1 = __importDefault(require("github-slugger"));
|
|
9
|
+
const permalinkIconAst_1 = __importDefault(require("./permalinkIconAst"));
|
|
10
|
+
const ABSOLUTE_URL = /^(https?:\/\/|\/\/)/i;
|
|
11
|
+
// The headers will be updated to include a link to their hash
|
|
12
|
+
const HEADINGS = ['h2', 'h3', 'h4', 'h5', 'h6'];
|
|
13
|
+
function rehypeDocs({ filePath, tag, processor }) {
|
|
14
|
+
const slugger = new github_slugger_1.default();
|
|
15
|
+
const anchorSlugger = new github_slugger_1.default();
|
|
16
|
+
function visitAnchor(node) {
|
|
17
|
+
const props = node.properties;
|
|
18
|
+
const href = props === null || props === void 0 ? void 0 : props.href;
|
|
19
|
+
if (!href)
|
|
20
|
+
return;
|
|
21
|
+
if (props.href === href) {
|
|
22
|
+
const isAbsoluteUrl = ABSOLUTE_URL.test(href);
|
|
23
|
+
// const isHash = href[0] === '#';
|
|
24
|
+
// const isRepoUrl = !isHash;
|
|
25
|
+
if (isAbsoluteUrl) {
|
|
26
|
+
props.className = 'absolute';
|
|
27
|
+
props.target = '_blank';
|
|
28
|
+
props.rel = 'noopener noreferrer';
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const [relativePath, hash] = props.href.split('#');
|
|
33
|
+
// Reset the slugger because single pages can have multiple urls to the same hash
|
|
34
|
+
anchorSlugger.reset();
|
|
35
|
+
// The URL is relative at this point
|
|
36
|
+
props.className = 'relative';
|
|
37
|
+
// Update the hash used by anchors to match the one set for headers
|
|
38
|
+
props.href = hash
|
|
39
|
+
? `${relativePath}#${anchorSlugger.slug(hash)}`
|
|
40
|
+
: relativePath;
|
|
41
|
+
}
|
|
42
|
+
function visitHeading(node) {
|
|
43
|
+
const text = (0, mdast_util_to_string_1.default)(node);
|
|
44
|
+
if (!text)
|
|
45
|
+
return;
|
|
46
|
+
const id = slugger.slug(text);
|
|
47
|
+
node.properties.className = 'heading';
|
|
48
|
+
node.children = [
|
|
49
|
+
{
|
|
50
|
+
type: 'element',
|
|
51
|
+
tagName: 'span',
|
|
52
|
+
properties: { id },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'element',
|
|
56
|
+
tagName: 'a',
|
|
57
|
+
properties: {
|
|
58
|
+
href: `#${id}`,
|
|
59
|
+
},
|
|
60
|
+
children: node.children,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'element',
|
|
64
|
+
tagName: 'span',
|
|
65
|
+
properties: { className: 'permalink' },
|
|
66
|
+
children: [permalinkIconAst_1.default],
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
return function transformer(tree) {
|
|
71
|
+
(0, unist_util_visit_1.default)(tree, (node) => node.tagName === 'a', visitAnchor);
|
|
72
|
+
(0, unist_util_visit_1.default)(tree, (node) => HEADINGS.includes(node.tagName), visitHeading);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.default = rehypeDocs;
|
|
76
|
+
//# sourceMappingURL=rehypeDocs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeDocs.js","sourceRoot":"","sources":["../src/rehypeDocs.ts"],"names":[],"mappings":";;;;;AAAA,wEAAqC;AACrC,gFAA4C;AAC5C,oEAA2C;AAC3C,0EAA+C;AAE/C,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAC5C,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEhD,SAAwB,UAAU,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE;IAC7D,MAAM,OAAO,GAAG,IAAI,wBAAa,EAAE,CAAC;IACpC,MAAM,aAAa,GAAG,IAAI,wBAAa,EAAE,CAAC;IAE1C,SAAS,WAAW,CAAC,IAAS;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9B,MAAM,IAAI,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC;QAEzB,IAAI,CAAC,IAAI;YAAE,OAAO;QAElB,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE;YACvB,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9C,kCAAkC;YAClC,6BAA6B;YA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,CAAC;aAC1B;SACF,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,WAAW,CAAC,IAAS;QACnC,IAAA,0BAAK,EAAC,IAAI,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,GAAG,EAAE,WAAW,CAAC,CAAC;QAC9D,IAAA,0BAAK,EAAC,IAAI,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC;IAC5E,CAAC,CAAC;AACJ,CAAC;AAvED,6BAuEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeMarkdownToHtml.d.ts","sourceRoot":"","sources":["../src/rehypeMarkdownToHtml.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE;;;;CAAA,GAAG,GAAG,CAkFpE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
9
|
+
const path_2 = __importDefault(require("path"));
|
|
10
|
+
function rehypeDocs({ filePath, tag, processor }) {
|
|
11
|
+
function visitInlineCode(node) {
|
|
12
|
+
const value = node.value;
|
|
13
|
+
if (value.startsWith('markdown:')) {
|
|
14
|
+
const file = value.substr(9);
|
|
15
|
+
const combinedPath = path_2.default.normalize((0, path_1.dirname)(filePath) + '/' + file);
|
|
16
|
+
if (!fs_1.default.existsSync(combinedPath)) {
|
|
17
|
+
throw Error(`Invalid fragment specified; no such file "${combinedPath}"`);
|
|
18
|
+
}
|
|
19
|
+
const code = fs_1.default.readFileSync(combinedPath, 'utf8');
|
|
20
|
+
const markdown = processor();
|
|
21
|
+
try {
|
|
22
|
+
node.value = `<div class=\"markdown-fragment\">${markdown.processSync(code)}</div>`;
|
|
23
|
+
node.type = 'html';
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw Error(`${e.message} \nFile: ${file}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function visitLink(node) {
|
|
31
|
+
if (node.children.length > 0 && node.children[0].value === '!embed') {
|
|
32
|
+
const file = node.url;
|
|
33
|
+
const path = (0, path_1.dirname)(filePath) + '/' + file;
|
|
34
|
+
if (!fs_1.default.existsSync(path)) {
|
|
35
|
+
throw Error(`Invalid fragment specified; no such file "${path}"`);
|
|
36
|
+
}
|
|
37
|
+
const code = fs_1.default.readFileSync(path, 'utf8');
|
|
38
|
+
const markdown = processor();
|
|
39
|
+
try {
|
|
40
|
+
node.value = `<div class=\"markdown-fragment\">${markdown.processSync(code)}</div>`;
|
|
41
|
+
node.type = 'html';
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw Error(`${e.message} \nFile: ${file}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (node.children.length > 0 && node.children[0].value.indexOf('%') === 0) {
|
|
48
|
+
node.value = `
|
|
49
|
+
<div class="card card-bordered bg-soft-info">
|
|
50
|
+
<div class="card-body">
|
|
51
|
+
<h5 class="card-title">${node.children[0].value.substring(1)}</h5>
|
|
52
|
+
<div class="card-text">
|
|
53
|
+
<div class="embed-responsive embed-responsive-16by9">
|
|
54
|
+
<iframe class="embed-responsive-item" src="${node.url}" allowfullscreen></iframe>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</div>`;
|
|
59
|
+
// node.value = `<iframe
|
|
60
|
+
// width="560"
|
|
61
|
+
// height="315"
|
|
62
|
+
// src="${node.url}"
|
|
63
|
+
// frameborder="0"
|
|
64
|
+
// allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
65
|
+
// allowfullscreen>
|
|
66
|
+
// </iframe>`;
|
|
67
|
+
node.type = 'html';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return function transformer(tree) {
|
|
71
|
+
(0, unist_util_visit_1.default)(tree, 'inlineCode', visitInlineCode);
|
|
72
|
+
(0, unist_util_visit_1.default)(tree, (node) => node.type === 'link', visitLink);
|
|
73
|
+
return tree;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.default = rehypeDocs;
|
|
77
|
+
//# sourceMappingURL=rehypeMarkdownToHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeMarkdownToHtml.js","sourceRoot":"","sources":["../src/rehypeMarkdownToHtml.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA+B;AAC/B,wEAAqC;AAErC,gDAAwB;AAExB,SAAwB,UAAU,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE;IAC7D,SAAS,eAAe,CAAC,IAAS;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;YACjC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAE7B,MAAM,YAAY,GAAG,cAAI,CAAC,SAAS,CAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;YAEpE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;gBAChC,MAAM,KAAK,CACT,6CAA6C,YAAY,GAAG,CAC7D,CAAC;aACH;YAED,MAAM,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,YAAY,EA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AAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACzE,IAAI,CAAC,KAAK,GAAG;;;iCAGc,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;;;2DAIpD,IAAI,CAAC,GACP;;;;aAID,CAAC;YACR,wBAAwB;YACxB,gBAAgB;YAChB,iBAAiB;YACjB,sBAAsB;YACtB,oBAAoB;YACpB,qGAAqG;YACrG,qBAAqB;YACrB,cAAc;YACd,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;SACpB;IACH,CAAC;IAED,OAAO,SAAS,WAAW,CAAC,IAAS;QACnC,IAAA,0BAAK,EAAC,IAAI,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC;QAC3C,IAAA,0BAAK,EAAC,IAAI,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,SAAS,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAlFD,6BAkFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeMarkdownToMarkdown.d.ts","sourceRoot":"","sources":["../src/rehypeMarkdownToMarkdown.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE;;CAAA,GAAG,GAAG,CA8DpD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const unist_util_visit_1 = __importDefault(require("unist-util-visit"));
|
|
9
|
+
const path_2 = __importDefault(require("path"));
|
|
10
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
11
|
+
const unified_1 = __importDefault(require("unified"));
|
|
12
|
+
const remark_parse_1 = __importDefault(require("remark-parse"));
|
|
13
|
+
const gray_matter_1 = __importDefault(require("gray-matter"));
|
|
14
|
+
function fileToMarkdownTree(filePath) {
|
|
15
|
+
const data = (0, gray_matter_1.default)((0, utils_sh_1.read)(filePath)).content;
|
|
16
|
+
const tree = (0, unified_1.default)()
|
|
17
|
+
.use(remark_parse_1.default)
|
|
18
|
+
.parse(data);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
20
|
+
return rehypeDocs({ filePath })(tree);
|
|
21
|
+
}
|
|
22
|
+
function rehypeDocs({ filePath }) {
|
|
23
|
+
function visitInlineCode(node) {
|
|
24
|
+
const value = node.value;
|
|
25
|
+
if (value.startsWith('markdown:')) {
|
|
26
|
+
const file = value.substr(9);
|
|
27
|
+
const combinedPath = path_2.default.normalize((0, path_1.dirname)(filePath) + '/' + file);
|
|
28
|
+
if (!fs_1.default.existsSync(combinedPath)) {
|
|
29
|
+
throw Error(`Invalid fragment specified; no such file "${combinedPath}"`);
|
|
30
|
+
}
|
|
31
|
+
const tree = fileToMarkdownTree(combinedPath);
|
|
32
|
+
try {
|
|
33
|
+
node.children = tree.children;
|
|
34
|
+
node.value = '';
|
|
35
|
+
node.type = 'root';
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw Error(`${e.message} \nFile: ${file}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function visitLink(node) {
|
|
43
|
+
if (node.children.length > 0 && node.children[0].value === '!embed') {
|
|
44
|
+
const file = node.url;
|
|
45
|
+
const path = (0, path_1.dirname)(filePath) + '/' + file;
|
|
46
|
+
if (!fs_1.default.existsSync(path)) {
|
|
47
|
+
throw Error(`Invalid fragment specified; no such file "${path}"`);
|
|
48
|
+
}
|
|
49
|
+
const tree = fileToMarkdownTree(path);
|
|
50
|
+
try {
|
|
51
|
+
node.children = tree.children;
|
|
52
|
+
node.value = '';
|
|
53
|
+
node.type = 'root';
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw Error(`${e.message} \nFile: ${file}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (node.children.length > 0 &&
|
|
60
|
+
node.children[0].value &&
|
|
61
|
+
node.children[0].value.indexOf('%') === 0) {
|
|
62
|
+
node.value = `[Video: ${node.children[0].value.substring(1)}](${node.url})`;
|
|
63
|
+
node.type = 'text';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return function transformer(tree) {
|
|
67
|
+
(0, unist_util_visit_1.default)(tree, 'inlineCode', visitInlineCode);
|
|
68
|
+
(0, unist_util_visit_1.default)(tree, (node) => node.type === 'link', visitLink);
|
|
69
|
+
return tree;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
exports.default = rehypeDocs;
|
|
73
|
+
//# sourceMappingURL=rehypeMarkdownToMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehypeMarkdownToMarkdown.js","sourceRoot":"","sources":["../src/rehypeMarkdownToMarkdown.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAA+B;AAC/B,wEAAqC;AAErC,gDAAwB;AAExB,kDAA2C;AAE3C,sDAA8B;AAC9B,gEAAoC;AAEpC,8DAAiC;AACjC,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,IAAI,GAAG,IAAA,qBAAM,EAAC,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5C,MAAM,IAAI,GAAG,IAAA,iBAAO,GAAE;SACnB,GAAG,CAAC,sBAAe,CAAC;SACpB,KAAK,CAAC,IAAI,CAAC,CAAC;IACf,mEAAmE;IACnE,OAAO,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,C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,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBvE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveMarkdown = void 0;
|
|
7
|
+
const unified_1 = __importDefault(require("unified"));
|
|
8
|
+
const remark_parse_1 = __importDefault(require("remark-parse"));
|
|
9
|
+
const rehypeMarkdownToMarkdown_1 = __importDefault(require("./rehypeMarkdownToMarkdown"));
|
|
10
|
+
// import stringify from 'rehype-stringify';
|
|
11
|
+
const mdast_util_to_markdown_1 = __importDefault(require("mdast-util-to-markdown"));
|
|
12
|
+
const gray_matter_1 = __importDefault(require("gray-matter"));
|
|
13
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
14
|
+
async function resolveMarkdown(filePath) {
|
|
15
|
+
try {
|
|
16
|
+
let tree = undefined;
|
|
17
|
+
tree = (0, unified_1.default)()
|
|
18
|
+
.use(remark_parse_1.default)
|
|
19
|
+
// .use(rehypeMarkdown, { filePath })
|
|
20
|
+
.parse((0, gray_matter_1.default)((0, utils_sh_1.read)(filePath)).content);
|
|
21
|
+
tree = (0, rehypeMarkdownToMarkdown_1.default)({ filePath })(tree);
|
|
22
|
+
// const file = await processor.process(md);
|
|
23
|
+
// console.log(JSON.stringify(tree, null, 2));
|
|
24
|
+
const file = (0, mdast_util_to_markdown_1.default)(tree, {});
|
|
25
|
+
// Replace non-breaking spaces (char code 160) with normal spaces to avoid style issues
|
|
26
|
+
return file.replace(/\xA0/g, ' ');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Markdown to Markdown error: ${error}`);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.resolveMarkdown = resolveMarkdown;
|
|
34
|
+
//# sourceMappingURL=resolveMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveMarkdown.js","sourceRoot":"","sources":["../src/resolveMarkdown.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,gEAAoC;AACpC,0FAAwD;AACxD,4CAA4C;AAC5C,oFAA+C;AAE/C,8DAAiC;AACjC,kDAA2C;AAEpC,KAAK,UAAU,eAAe,CAAC,QAAgB;IACpD,IAAI;QACF,IAAI,IAAI,GAAQ,SAAS,CAAC;QAC1B,IAAI,GAAG,IAAA,iBAAO,GAAE;aACb,GAAG,CAAC,sBAAe,CAAC;YACrB,qCAAqC;aACpC,KAAK,CAAC,IAAA,qBAAM,EAAC,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,GAAG,IAAA,kCAAc,EAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1C,4CAA4C;QAC5C,8CAA8C;QAC9C,MAAM,IAAI,GAAG,IAAA,gCAAS,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEjC,uFAAuF;QACvF,OAAQ,IAAY,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;KAC5C;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;QACtD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAlBD,0CAkBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveMarkdown.spec.d.ts","sourceRoot":"","sources":["../src/resolveMarkdown.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const resolveMarkdown_1 = require("./resolveMarkdown");
|
|
4
|
+
describe('markdownToMarkdown', () => {
|
|
5
|
+
it('Should render documentation markdown to markdown', async () => {
|
|
6
|
+
const result = await (0, resolveMarkdown_1.resolveMarkdown)(__dirname + '/markdown/configure.md');
|
|
7
|
+
expect(result).toContain('[AWS region]');
|
|
8
|
+
});
|
|
9
|
+
it('Should render documentation with embedded documents', async () => {
|
|
10
|
+
const file = __dirname + '/markdown/template-s3.md';
|
|
11
|
+
const result = await (0, resolveMarkdown_1.resolveMarkdown)(file);
|
|
12
|
+
expect(result).toContain('[AWS region]');
|
|
13
|
+
expect(result).toContain('s3 = connect()');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=resolveMarkdown.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveMarkdown.spec.js","sourceRoot":"","sources":["../src/resolveMarkdown.spec.ts"],"names":[],"mappings":";;AAAA,uDAAoD;AAEpD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAe,EAAC,SAAS,GAAG,wBAAwB,CAAC,CAAC;QAC3E,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACnE,MAAM,IAAI,GAAG,SAAS,GAAG,0BAA0B,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QACzC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { markdownToHtml } from './markdownToHtml';
|
|
2
|
+
export { resolveMarkdown } from './resolveMarkdown';
|
|
3
|
+
export interface RenderPageResult {
|
|
4
|
+
html: string;
|
|
5
|
+
data: any;
|
|
6
|
+
}
|
|
7
|
+
export declare const renderPage: (filePath: string) => Promise<RenderPageResult>;
|
|
8
|
+
//# sourceMappingURL=utilsDocs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilsDocs.d.ts","sourceRoot":"","sources":["../src/utilsDocs.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;CACX;AAED,eAAO,MAAM,UAAU,aACX,MAAM,KACf,QAAQ,gBAAgB,CAS1B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.renderPage = exports.resolveMarkdown = exports.markdownToHtml = void 0;
|
|
7
|
+
const gray_matter_1 = __importDefault(require("gray-matter"));
|
|
8
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
9
|
+
const markdownToHtml_1 = require("./markdownToHtml");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
var markdownToHtml_2 = require("./markdownToHtml");
|
|
12
|
+
Object.defineProperty(exports, "markdownToHtml", { enumerable: true, get: function () { return markdownToHtml_2.markdownToHtml; } });
|
|
13
|
+
var resolveMarkdown_1 = require("./resolveMarkdown");
|
|
14
|
+
Object.defineProperty(exports, "resolveMarkdown", { enumerable: true, get: function () { return resolveMarkdown_1.resolveMarkdown; } });
|
|
15
|
+
const renderPage = async (filePath) => {
|
|
16
|
+
const fileContent = (0, utils_sh_1.read)(filePath);
|
|
17
|
+
const { data, content } = (0, gray_matter_1.default)(fileContent);
|
|
18
|
+
const result = await (0, markdownToHtml_1.markdownToHtml)(path_1.default.resolve(filePath), data, content);
|
|
19
|
+
return {
|
|
20
|
+
html: result,
|
|
21
|
+
data,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.renderPage = renderPage;
|
|
25
|
+
//# sourceMappingURL=utilsDocs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilsDocs.js","sourceRoot":"","sources":["../src/utilsDocs.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAEjC,kDAA2C;AAC3C,qDAAkD;AAClD,gDAAwB;AAExB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAOjB,MAAM,UAAU,GAAG,KAAK,EAC7B,QAAgB,EACW,EAAE;IAC7B,MAAM,WAAW,GAAG,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAA,qBAAM,EAAC,WAAW,CAAC,CAAC;IAE9C,MAAM,MAAM,GAAG,MAAM,IAAA,+BAAc,EAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3E,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI;KACL,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,UAAU,cAWrB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goldstack/utils-docs",
|
|
3
|
+
"version": "0.3.17",
|
|
4
|
+
"description": "Utilities for working with Markdown documentation",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"goldstack",
|
|
7
|
+
"utility",
|
|
8
|
+
"documentation",
|
|
9
|
+
"markdown",
|
|
10
|
+
"html",
|
|
11
|
+
"markdown to html",
|
|
12
|
+
"rehype",
|
|
13
|
+
"generator"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://goldstack.party",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/goldstack/goldstack/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/goldstack/goldstack.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Max Rohde",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"main": "dist/utilsDocs.js",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "yarn clean && yarn compile",
|
|
29
|
+
"build:watch": "yarn clean && yarn compile:watch",
|
|
30
|
+
"clean": "rm -rf ./dist",
|
|
31
|
+
"compile": "tsc -p tsconfig.json",
|
|
32
|
+
"compile:watch": "tsc -p tsconfig.json --watch",
|
|
33
|
+
"compile:watch:light": "nodemon --watch ./src/ -e '*' --exec 'yarn compile'",
|
|
34
|
+
"coverage": "jest --collect-coverage --passWithNoTests --config=./jest.config.js",
|
|
35
|
+
"prepublishOnly": "yarn run build",
|
|
36
|
+
"publish": "utils-git changed --exec \"yarn npm publish $@\"",
|
|
37
|
+
"test": "jest --config=./jest.config.js --watch",
|
|
38
|
+
"test:ci": "jest --passWithNoTests --config=./jest.config.js",
|
|
39
|
+
"version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\"",
|
|
40
|
+
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@goldstack/utils-sh": "0.4.13",
|
|
44
|
+
"@mapbox/rehype-prism": "0.3.1",
|
|
45
|
+
"github-slugger": "1.2.0",
|
|
46
|
+
"gray-matter": "^4.0.2",
|
|
47
|
+
"hast-util-sanitize": "^3.0.0",
|
|
48
|
+
"mdast-util-to-markdown": "0.5.3",
|
|
49
|
+
"mdast-util-to-string": "1.0.7",
|
|
50
|
+
"rehype-raw": "4.0.1",
|
|
51
|
+
"rehype-sanitize": "3.0.0",
|
|
52
|
+
"rehype-stringify": "6.0.0",
|
|
53
|
+
"remark-parse": "7.0.1",
|
|
54
|
+
"remark-rehype": "5.0.0",
|
|
55
|
+
"unified": "8.4.1",
|
|
56
|
+
"unist-util-visit": "2.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@goldstack/utils-git": "0.1.26",
|
|
60
|
+
"@types/jest": "^26.0.21",
|
|
61
|
+
"@types/node": "^14.0.6",
|
|
62
|
+
"jest": "^26.6.3",
|
|
63
|
+
"ts-jest": "^26.5.4",
|
|
64
|
+
"typescript": "^4.4.3"
|
|
65
|
+
}
|
|
66
|
+
}
|