@goldstack/utils-docs 0.4.0 → 0.4.1

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.
@@ -1,5 +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";
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
5
  //# sourceMappingURL=githubConstants.d.ts.map
@@ -1,8 +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';
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
8
  //# sourceMappingURL=githubConstants.js.map
@@ -1,2 +1,2 @@
1
- export declare function markdownToHtml(filePath: any, tag: any, md: any): Promise<string>;
1
+ export declare function markdownToHtml(filePath: any, tag: any, md: any): Promise<string>;
2
2
  //# sourceMappingURL=markdownToHtml.d.ts.map
@@ -1,64 +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;
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
64
  //# sourceMappingURL=markdownToHtml.js.map
@@ -1,3 +1,3 @@
1
- declare const permalinkIcon: import("unist").Node;
2
- export default permalinkIcon;
1
+ declare const permalinkIcon: import("unist").Node;
2
+ export default permalinkIcon;
3
3
  //# sourceMappingURL=permalinkIconAst.d.ts.map
@@ -1,10 +1,10 @@
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"));
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
8
  const ICON_HTML = `<svg viewBox="0 0 16 16" width="16" height="16">
9
9
  <g strokeWidth="1" fill="#000000" stroke="#000000">
10
10
  <path
@@ -23,10 +23,10 @@ const ICON_HTML = `<svg viewBox="0 0 16 16" width="16" height="16">
23
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
24
  />
25
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;
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
32
  //# sourceMappingURL=permalinkIconAst.js.map
@@ -1,6 +1,6 @@
1
- export default function rehypeDocs({ filePath, tag, processor }: {
2
- filePath: any;
3
- tag: any;
4
- processor: any;
5
- }): (tree: any) => void;
1
+ export default function rehypeDocs({ filePath, tag, processor }: {
2
+ filePath: any;
3
+ tag: any;
4
+ processor: any;
5
+ }): (tree: any) => void;
6
6
  //# sourceMappingURL=rehypeDocs.d.ts.map
@@ -1,76 +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;
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
76
  //# sourceMappingURL=rehypeDocs.js.map
@@ -1,6 +1,6 @@
1
- export default function rehypeDocs({ filePath, tag, processor }: {
2
- filePath: any;
3
- tag: any;
4
- processor: any;
5
- }): any;
1
+ export default function rehypeDocs({ filePath, tag, processor }: {
2
+ filePath: any;
3
+ tag: any;
4
+ processor: any;
5
+ }): any;
6
6
  //# sourceMappingURL=rehypeMarkdownToHtml.d.ts.map
@@ -1,50 +1,50 @@
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 combinedPath = path_2.default.normalize((0, path_1.dirname)(filePath) + '/' + file);
34
- if (!fs_1.default.existsSync(combinedPath)) {
35
- throw Error(`Invalid fragment specified; no such file "${combinedPath}"`);
36
- }
37
- const code = fs_1.default.readFileSync(combinedPath, '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) {
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 combinedPath = path_2.default.normalize((0, path_1.dirname)(filePath) + '/' + file);
34
+ if (!fs_1.default.existsSync(combinedPath)) {
35
+ throw Error(`Invalid fragment specified; no such file "${combinedPath}"`);
36
+ }
37
+ const code = fs_1.default.readFileSync(combinedPath, '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
48
  node.value = `
49
49
  <div class="card card-bordered bg-soft-info">
50
50
  <div class="card-body">
@@ -55,23 +55,23 @@ function rehypeDocs({ filePath, tag, processor }) {
55
55
  </div>
56
56
  </div>
57
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;
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
77
  //# sourceMappingURL=rehypeMarkdownToHtml.js.map
@@ -1,4 +1,4 @@
1
- export default function rehypeDocs({ filePath }: {
2
- filePath: any;
3
- }): any;
1
+ export default function rehypeDocs({ filePath }: {
2
+ filePath: any;
3
+ }): any;
4
4
  //# sourceMappingURL=rehypeMarkdownToMarkdown.d.ts.map
@@ -1,73 +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;
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
73
  //# sourceMappingURL=rehypeMarkdownToMarkdown.js.map
@@ -1,2 +1,2 @@
1
- export declare function resolveMarkdown(filePath: string): Promise<string>;
1
+ export declare function resolveMarkdown(filePath: string): Promise<string>;
2
2
  //# sourceMappingURL=resolveMarkdown.d.ts.map
@@ -1,37 +1,37 @@
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 mdast_util_gfm_table_1 = __importDefault(require("mdast-util-gfm-table"));
13
- const gray_matter_1 = __importDefault(require("gray-matter"));
14
- const utils_sh_1 = require("@goldstack/utils-sh");
15
- async function resolveMarkdown(filePath) {
16
- try {
17
- let tree = undefined;
18
- tree = (0, unified_1.default)()
19
- .use(remark_parse_1.default)
20
- // .use(rehypeMarkdown, { filePath })
21
- .parse((0, gray_matter_1.default)((0, utils_sh_1.read)(filePath)).content);
22
- tree = (0, rehypeMarkdownToMarkdown_1.default)({ filePath })(tree);
23
- // const file = await processor.process(md);
24
- // console.log(JSON.stringify(tree, null, 2));
25
- const file = (0, mdast_util_to_markdown_1.default)(tree, {
26
- extensions: [mdast_util_gfm_table_1.default.toMarkdown()],
27
- });
28
- // Replace non-breaking spaces (char code 160) with normal spaces to avoid style issues
29
- return file.replace(/\xA0/g, ' ');
30
- }
31
- catch (error) {
32
- console.error(`Markdown to Markdown error: ${error}`);
33
- throw error;
34
- }
35
- }
36
- exports.resolveMarkdown = resolveMarkdown;
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 mdast_util_gfm_table_1 = __importDefault(require("mdast-util-gfm-table"));
13
+ const gray_matter_1 = __importDefault(require("gray-matter"));
14
+ const utils_sh_1 = require("@goldstack/utils-sh");
15
+ async function resolveMarkdown(filePath) {
16
+ try {
17
+ let tree = undefined;
18
+ tree = (0, unified_1.default)()
19
+ .use(remark_parse_1.default)
20
+ // .use(rehypeMarkdown, { filePath })
21
+ .parse((0, gray_matter_1.default)((0, utils_sh_1.read)(filePath)).content);
22
+ tree = (0, rehypeMarkdownToMarkdown_1.default)({ filePath })(tree);
23
+ // const file = await processor.process(md);
24
+ // console.log(JSON.stringify(tree, null, 2));
25
+ const file = (0, mdast_util_to_markdown_1.default)(tree, {
26
+ extensions: [mdast_util_gfm_table_1.default.toMarkdown()],
27
+ });
28
+ // Replace non-breaking spaces (char code 160) with normal spaces to avoid style issues
29
+ return file.replace(/\xA0/g, ' ');
30
+ }
31
+ catch (error) {
32
+ console.error(`Markdown to Markdown error: ${error}`);
33
+ throw error;
34
+ }
35
+ }
36
+ exports.resolveMarkdown = resolveMarkdown;
37
37
  //# sourceMappingURL=resolveMarkdown.js.map
@@ -1,8 +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>;
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
8
  //# sourceMappingURL=utilsDocs.d.ts.map
@@ -1,25 +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;
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
25
  //# sourceMappingURL=utilsDocs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goldstack/utils-docs",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Utilities for working with Markdown documentation",
5
5
  "keywords": [
6
6
  "goldstack",
@@ -40,7 +40,7 @@
40
40
  "version:apply:force": "yarn version $@ && yarn version apply"
41
41
  },
42
42
  "dependencies": {
43
- "@goldstack/utils-sh": "0.5.0",
43
+ "@goldstack/utils-sh": "0.5.1",
44
44
  "@mapbox/rehype-prism": "0.3.1",
45
45
  "github-slugger": "1.2.0",
46
46
  "gray-matter": "^4.0.2",
@@ -57,7 +57,7 @@
57
57
  "unist-util-visit": "2.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@goldstack/utils-git": "0.2.0",
60
+ "@goldstack/utils-git": "0.2.1",
61
61
  "@types/jest": "^28.1.8",
62
62
  "@types/node": "^18.7.13",
63
63
  "jest": "^28.1.0",