markdown-to-html-cli 3.2.13 → 3.2.14
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/lib/nodes/dark-mode.js +1 -1
- package/lib/nodes/dark-mode.js.map +1 -1
- package/lib/nodes/github-corners.js +36 -33
- package/lib/nodes/github-corners.js.map +1 -1
- package/package.json +3 -4
- package/src/cli.ts +5 -0
- package/src/create.ts +101 -0
- package/src/index.ts +113 -0
- package/src/nodes/copy.ts +148 -0
- package/src/nodes/dark-mode.ts +31 -0
- package/{github-fork-ribbon.css → src/nodes/github-corners-fork.ts} +38 -1
- package/src/nodes/github-corners.ts +116 -0
- package/src/nodes/markdown-style.ts +1047 -0
- package/src/nodes/octiconLink.ts +12 -0
- package/src/utils.ts +50 -0
- package/github.css +0 -32
package/lib/nodes/dark-mode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dark-mode.js","sourceRoot":"","sources":["../../src/nodes/dark-mode.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,o8GAAo8G,CAAA;AAEz9G;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,QAAQ;YACjB,gBAAgB;YAChB,6CAA6C;YAC7C,KAAK;YACL,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY;iBACpB,CAAC;SACH,EAAE;YACD,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,WAAW;YACpB,UAAU,EAAE;gBACV,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"dark-mode.js","sourceRoot":"","sources":["../../src/nodes/dark-mode.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,o8GAAo8G,CAAA;AAEz9G;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,QAAQ;YACjB,gBAAgB;YAChB,6CAA6C;YAC7C,KAAK;YACL,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY;iBACpB,CAAC;SACH,EAAE;YACD,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,WAAW;YACpB,UAAU,EAAE;gBACV,SAAS,EAAE,IAAI;gBACf,KAAK,EAAE,sDAAsD;gBAC7D,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,OAAO;aACf;YACD,QAAQ,EAAE,EAAE;SACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -39,41 +39,44 @@ TEMPLATE.innerHTML = \`
|
|
|
39
39
|
</svg>
|
|
40
40
|
\`;
|
|
41
41
|
export class GithubCorners extends HTMLElement {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
static get observedAttributes() {
|
|
50
|
-
return ['z-index', 'target', 'height', 'width', 'href', 'color', 'fill', 'position', 'top', 'left', 'right', 'bottom', 'transform'];
|
|
51
|
-
}
|
|
52
|
-
setAttr(name, value) {
|
|
53
|
-
const svg = this.shadow.querySelector('svg');
|
|
54
|
-
if (/(color|fill)/.test(name.toLocaleLowerCase())) {
|
|
55
|
-
svg.firstElementChild.style[name] = value;
|
|
56
|
-
} else
|
|
57
|
-
if (/(z-index|height|width|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
|
|
58
|
-
svg.style[name] = value;
|
|
59
|
-
} else
|
|
60
|
-
{
|
|
61
|
-
svg.setAttribute(name, value);
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
this.right = '0';
|
|
45
|
+
this.shadow = this.attachShadow({ mode: 'open' });
|
|
46
|
+
this.shadow.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true));
|
|
47
|
+
this.update();
|
|
62
48
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
;
|
|
66
|
-
[...this.getAttributeNames(), 'right'].forEach(name => {
|
|
67
|
-
const value = this.getAttribute(name) || this[name] || '';
|
|
68
|
-
this.setAttr(name, value);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
72
|
-
if (oldValue !== newValue) {
|
|
73
|
-
this.setAttr(name, newValue);
|
|
49
|
+
static get observedAttributes() {
|
|
50
|
+
return ['z-index', 'target', 'height', 'width', 'href', 'color', 'fill', 'position', 'top', 'left', 'right', 'bottom', 'transform'];
|
|
74
51
|
}
|
|
75
|
-
|
|
76
|
-
|
|
52
|
+
setAttr(name, value) {
|
|
53
|
+
const svg = this.shadow.querySelector('svg');
|
|
54
|
+
if (/(href)/.test(name.toLocaleLowerCase())) {
|
|
55
|
+
svg.lastElementChild.setAttribute('xlink:href', value);
|
|
56
|
+
}
|
|
57
|
+
else if (/(color|fill)/.test(name.toLocaleLowerCase())) {
|
|
58
|
+
svg.firstElementChild.style[name] = value;
|
|
59
|
+
}
|
|
60
|
+
else if (/(z-index|height|width|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
|
|
61
|
+
svg.style[name] = value;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
svg.setAttribute(name, value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
update() {
|
|
68
|
+
;
|
|
69
|
+
[...this.getAttributeNames(), 'right'].forEach((name) => {
|
|
70
|
+
const value = this.getAttribute(name) || this[name] || '';
|
|
71
|
+
this.setAttr(name, value);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
75
|
+
if (oldValue !== newValue) {
|
|
76
|
+
this.setAttr(name, newValue);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
77
80
|
customElements.define('github-corners', GithubCorners);`;
|
|
78
81
|
export function githubCorners(opts) {
|
|
79
82
|
const { href } = opts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-corners.js","sourceRoot":"","sources":["../../src/nodes/github-corners.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,YAAY,GAAG
|
|
1
|
+
{"version":3,"file":"github-corners.js","sourceRoot":"","sources":["../../src/nodes/github-corners.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA2EmC,CAAC;AAEzD,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,IAAI,EAAE;QACT,OAAO;KACR;IACD,OAAO;QACL;YACE,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,gBAAgB;YACzB,UAAU,EAAE;gBACV,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,OAAO;gBACjB,IAAI;aACL;YACD,QAAQ,EAAE,EAAE;SACb,EAAE;YACD,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,QAAQ;YACjB,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,uDAAuD;aACxD;YACD,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY;iBACpB,CAAC;SACH;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-html-cli",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Command line tool generates markdown as html.",
|
|
6
6
|
"homepage": "https://jaywcjlove.github.io/markdown-to-html-cli",
|
|
@@ -34,15 +34,14 @@
|
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"lib",
|
|
37
|
-
"
|
|
38
|
-
"github.css"
|
|
37
|
+
"src"
|
|
39
38
|
],
|
|
40
39
|
"dependencies": {
|
|
41
40
|
"@types/fs-extra": "~9.0.13",
|
|
42
41
|
"@types/minimist": "~1.2.2",
|
|
43
42
|
"@uiw/github-corners": "~1.5.10",
|
|
44
43
|
"@wcj/markdown-style": "~1.0.1",
|
|
45
|
-
"@wcj/markdown-to-html": "~2.0.
|
|
44
|
+
"@wcj/markdown-to-html": "~2.0.2",
|
|
46
45
|
"fs-extra": "~10.0.0",
|
|
47
46
|
"minimist": "~1.2.5",
|
|
48
47
|
"rehype-autolink-headings": "~6.1.0",
|
package/src/cli.ts
ADDED
package/src/create.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import markdown, { Options } from '@wcj/markdown-to-html';
|
|
2
|
+
import { getCodeString } from 'rehype-rewrite';
|
|
3
|
+
import rehypeDocument from 'rehype-document';
|
|
4
|
+
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
5
|
+
import rehypeSlug from 'rehype-slug';
|
|
6
|
+
import remarkGemoji from 'remark-gemoji';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import rehypeUrls from 'rehype-urls';
|
|
9
|
+
import rehypeFormat from 'rehype-format';
|
|
10
|
+
import { githubCorners } from './nodes/github-corners';
|
|
11
|
+
import { githubCornersFork } from './nodes/github-corners-fork';
|
|
12
|
+
import { octiconLink } from './nodes/octiconLink';
|
|
13
|
+
import { markdownStyle } from './nodes/markdown-style';
|
|
14
|
+
import { copyElement, copyStyle, copyScript } from './nodes/copy';
|
|
15
|
+
import { darkMode } from './nodes/dark-mode';
|
|
16
|
+
import { MDToHTMLOptions } from './';
|
|
17
|
+
|
|
18
|
+
// https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-when-using-the-experimental-modules-flag
|
|
19
|
+
// export const _dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
// const filename = fileURLToPath(import.meta.url);
|
|
21
|
+
// const dirname = path.dirname(filename);
|
|
22
|
+
|
|
23
|
+
export const _dirname = __dirname;
|
|
24
|
+
export interface CreateOptions extends MDToHTMLOptions { }
|
|
25
|
+
|
|
26
|
+
export function create(options: MDToHTMLOptions = {}) {
|
|
27
|
+
const { markdown: string, document, rewrite, reurls = {} } = options;
|
|
28
|
+
|
|
29
|
+
const mdOptions: Options = {
|
|
30
|
+
hastNode: false,
|
|
31
|
+
remarkPlugins: [remarkGemoji],
|
|
32
|
+
rehypePlugins: [
|
|
33
|
+
[rehypeUrls, (url: any) => {
|
|
34
|
+
if (reurls[url.href]) {
|
|
35
|
+
url.path = reurls[url.href];
|
|
36
|
+
return url.path;
|
|
37
|
+
}
|
|
38
|
+
}],
|
|
39
|
+
[rehypeSlug],
|
|
40
|
+
[rehypeAutolinkHeadings],
|
|
41
|
+
[rehypeFormat],
|
|
42
|
+
],
|
|
43
|
+
rewrite: (node, index, parent) => {
|
|
44
|
+
if ((node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root')) {
|
|
45
|
+
node.children = markdownStyle(node.children as any);
|
|
46
|
+
darkMode().forEach(item => node.children.unshift(item));
|
|
47
|
+
}
|
|
48
|
+
if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
|
|
49
|
+
node.children = Array.isArray(node.children) ? node.children : [];
|
|
50
|
+
if (options['github-corners-fork']) {
|
|
51
|
+
node.children.unshift(githubCornersFork({ href: options['github-corners'] }));
|
|
52
|
+
} else {
|
|
53
|
+
githubCorners({ href: options['github-corners'] }).forEach(item => {
|
|
54
|
+
node.children.unshift(item)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
|
|
59
|
+
const child = node.children[0];
|
|
60
|
+
if (child && child.type === 'element' && child.properties) {
|
|
61
|
+
child.properties = { className: 'anchor', ...child.properties };
|
|
62
|
+
child.children = [octiconLink()];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (node.type == 'element' && node.tagName === 'markdown-style') {
|
|
66
|
+
node.children.unshift(copyStyle())
|
|
67
|
+
node.children.unshift(copyScript())
|
|
68
|
+
}
|
|
69
|
+
if (node.type == 'element' && node.tagName === 'pre') {
|
|
70
|
+
const code = getCodeString(node.children);
|
|
71
|
+
node.children.push(copyElement(code));
|
|
72
|
+
}
|
|
73
|
+
if (rewrite && typeof rewrite === 'function') {
|
|
74
|
+
rewrite(node, index, parent);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (document) {
|
|
80
|
+
const documentOptions = { ...document };
|
|
81
|
+
if (document.js) {
|
|
82
|
+
documentOptions.js = Array.isArray(document.js) ? document.js : [document.js];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (document.script) {
|
|
86
|
+
documentOptions.script = Array.isArray(document.script) ? document.script : [document.script];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (document.link) {
|
|
90
|
+
documentOptions.link = Array.isArray(document.link) ? document.link : [document.link];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (document.style) {
|
|
94
|
+
documentOptions.style = Array.isArray(document.style) ? document.style : [document.style];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
mdOptions.rehypePlugins.unshift([rehypeDocument, documentOptions]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return markdown(string || '', mdOptions) as string;
|
|
101
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import minimist, { ParsedArgs } from 'minimist';
|
|
4
|
+
import { Options } from 'rehype-document';
|
|
5
|
+
import { RehypeRewriteOptions } from 'rehype-rewrite';
|
|
6
|
+
import { create, _dirname } from './create';
|
|
7
|
+
import { formatConfig } from './utils';
|
|
8
|
+
|
|
9
|
+
export * from './create';
|
|
10
|
+
export * from './utils';
|
|
11
|
+
|
|
12
|
+
export interface RunArgvs extends Omit<ParsedArgs, '_'> {
|
|
13
|
+
version?: string;
|
|
14
|
+
source?: string;
|
|
15
|
+
output?: string;
|
|
16
|
+
/** Add a Github corner to your project page. */
|
|
17
|
+
'github-corners'?: string;
|
|
18
|
+
/** Github corners style. */
|
|
19
|
+
'github-corners-fork'?: boolean;
|
|
20
|
+
/** Markdown string. */
|
|
21
|
+
markdown?: string;
|
|
22
|
+
/** The `<title>` tag is required in HTML documents! */
|
|
23
|
+
title?: string;
|
|
24
|
+
/** Specify the configuration file. Default: `<process.cwd()>/package.json` */
|
|
25
|
+
config?: string;
|
|
26
|
+
/** Define a description of your web page */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Define keywords for search engines */
|
|
29
|
+
keywords?: string;
|
|
30
|
+
/** Add a Favicon to your Site */
|
|
31
|
+
favicon?: string;
|
|
32
|
+
/** Define the author of a page */
|
|
33
|
+
author?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MDToHTMLOptions extends RunArgvs {
|
|
37
|
+
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
|
|
38
|
+
document?: Options;
|
|
39
|
+
/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
|
|
40
|
+
rewrite?: RehypeRewriteOptions['rewrite'];
|
|
41
|
+
/** rewrite URLs of href and src attributes. */
|
|
42
|
+
reurls?: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function run(opts = {} as Omit<RunArgvs, '_'>) {
|
|
46
|
+
const argvs = minimist<RunArgvs>(process.argv.slice(2), {
|
|
47
|
+
alias: {
|
|
48
|
+
help: 'h',
|
|
49
|
+
version: 'v',
|
|
50
|
+
config: 'c',
|
|
51
|
+
source: 's',
|
|
52
|
+
output: 'o',
|
|
53
|
+
},
|
|
54
|
+
default: {
|
|
55
|
+
version: opts.v || opts.version || false,
|
|
56
|
+
help: opts.h || opts.help || false,
|
|
57
|
+
source: opts.s || opts.source || 'README.md',
|
|
58
|
+
markdown: opts.markdown || '',
|
|
59
|
+
description: opts.description || '',
|
|
60
|
+
output: opts.o || opts.output || 'index.html',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
if (argvs.h || argvs.help) {
|
|
64
|
+
console.log(`${cliHelp}${exampleHelp}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const pkgPath = path.resolve(_dirname, '..', 'package.json')
|
|
68
|
+
if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
|
|
69
|
+
const pkg = fs.readJSONSync(pkgPath);
|
|
70
|
+
console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
|
|
71
|
+
return pkg.version;
|
|
72
|
+
}
|
|
73
|
+
if (argvs.source && !argvs.markdown) {
|
|
74
|
+
argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
|
|
75
|
+
}
|
|
76
|
+
const options = formatConfig({ ...opts, ...argvs });
|
|
77
|
+
const output = path.resolve(argvs.output);
|
|
78
|
+
|
|
79
|
+
const strMarkdown = create({ ...argvs, ...options });
|
|
80
|
+
fs.writeFileSync(output, strMarkdown);
|
|
81
|
+
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
|
|
85
|
+
|
|
86
|
+
Options:\n
|
|
87
|
+
--author Define the author of a page.
|
|
88
|
+
--config, -o Specify the configuration file. Default: "<process.cwd()>/package.json".
|
|
89
|
+
--description Define a description of your web page.
|
|
90
|
+
--favicon Add a Favicon to your Site.
|
|
91
|
+
--github-corners Add a Github corner to your project page.
|
|
92
|
+
--github-corners-fork Github corners style.
|
|
93
|
+
--keywords Define keywords for search engines.
|
|
94
|
+
--markdown Markdown string.
|
|
95
|
+
--output, -o Output static pages to the specified directory. Default: "index.html"
|
|
96
|
+
--source, -s The path of the target file "README.md". Default: "README.md"
|
|
97
|
+
--title The \`<title>\` tag is required in HTML documents!
|
|
98
|
+
--version, -v Show version number
|
|
99
|
+
--help, -h Displays help information.
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
export const exampleHelp: string =`\n Example:
|
|
103
|
+
|
|
104
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli
|
|
105
|
+
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
|
|
106
|
+
\x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
|
|
107
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
|
|
108
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli
|
|
109
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove --github-corners-fork
|
|
110
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html
|
|
111
|
+
\x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--source\x1b[0m README.md
|
|
112
|
+
|
|
113
|
+
`;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
const style = `.markdown-body pre .copied {
|
|
4
|
+
display: flex;
|
|
5
|
+
position: absolute;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
color: #a5afbb;
|
|
8
|
+
top: 6px;
|
|
9
|
+
right: 6px;
|
|
10
|
+
border-radius: 5px;
|
|
11
|
+
background: #82828226;
|
|
12
|
+
padding: 6px;
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
transition: all .3s;
|
|
15
|
+
}
|
|
16
|
+
.markdown-body pre .copied:not(.active) {
|
|
17
|
+
visibility: hidden;
|
|
18
|
+
}
|
|
19
|
+
.markdown-body pre:hover .copied {
|
|
20
|
+
visibility: visible;
|
|
21
|
+
}
|
|
22
|
+
.markdown-body pre:hover .copied:hover {
|
|
23
|
+
background: #4caf50;
|
|
24
|
+
color: #fff;
|
|
25
|
+
}
|
|
26
|
+
.markdown-body pre:hover .copied:active,
|
|
27
|
+
.markdown-body pre .copied.active {
|
|
28
|
+
background: #2e9b33;
|
|
29
|
+
color: #fff;
|
|
30
|
+
}
|
|
31
|
+
.markdown-body pre .copied .octicon-copy {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
.markdown-body pre .copied .octicon-check {
|
|
35
|
+
display: none;
|
|
36
|
+
}
|
|
37
|
+
.markdown-body pre .active .octicon-copy {
|
|
38
|
+
display: none;
|
|
39
|
+
}
|
|
40
|
+
.markdown-body pre .active .octicon-check {
|
|
41
|
+
display: block;
|
|
42
|
+
}`;
|
|
43
|
+
|
|
44
|
+
export function copyStyle(): Element {
|
|
45
|
+
return {
|
|
46
|
+
type: 'element',
|
|
47
|
+
tagName: 'style',
|
|
48
|
+
children: [
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
value: style
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const script = `/*! @uiw/copy-to-clipboard v1.0.12 | MIT (c) 2021 Kenny Wang | https://github.com/uiwjs/copy-to-clipboard.git */
|
|
58
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).copyTextToClipboard=t()}(this,(function(){"use strict";return function(e,t){const o=document.createElement("textarea");o.value=e,o.setAttribute("readonly",""),o.style={position:"absolute",left:"-9999px"},document.body.appendChild(o);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);o.select();let c=!1;try{c=!!document.execCommand("copy")}catch(e){c=!1}document.body.removeChild(o),n&&document.getSelection&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n)),t&&t(c)}}));
|
|
59
|
+
|
|
60
|
+
function copied(target, str) {
|
|
61
|
+
target.classList.add('active');
|
|
62
|
+
copyTextToClipboard(target.dataset.code, function() {
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
target.classList.remove('active');
|
|
65
|
+
}, 2000);
|
|
66
|
+
});
|
|
67
|
+
}`;
|
|
68
|
+
|
|
69
|
+
export function copyScript(): Element {
|
|
70
|
+
return {
|
|
71
|
+
type: 'element',
|
|
72
|
+
tagName: 'script',
|
|
73
|
+
children: [
|
|
74
|
+
{
|
|
75
|
+
type: 'text',
|
|
76
|
+
value: script
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function copyElement(str: string = ''): Element {
|
|
83
|
+
return {
|
|
84
|
+
type: 'element',
|
|
85
|
+
tagName: 'div',
|
|
86
|
+
properties: {
|
|
87
|
+
onclick: 'copied(this)',
|
|
88
|
+
'data-code': str,
|
|
89
|
+
className: 'copied',
|
|
90
|
+
},
|
|
91
|
+
children: [
|
|
92
|
+
{
|
|
93
|
+
type: 'element',
|
|
94
|
+
tagName: 'svg',
|
|
95
|
+
properties: {
|
|
96
|
+
className: 'octicon-copy',
|
|
97
|
+
ariaHidden: 'true',
|
|
98
|
+
viewBox: '0 0 16 16',
|
|
99
|
+
fill: 'currentColor',
|
|
100
|
+
height: 12,
|
|
101
|
+
width: 12,
|
|
102
|
+
},
|
|
103
|
+
children: [
|
|
104
|
+
{
|
|
105
|
+
type: 'element',
|
|
106
|
+
tagName: 'path',
|
|
107
|
+
properties: {
|
|
108
|
+
fillRule: 'evenodd',
|
|
109
|
+
d: 'M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z'
|
|
110
|
+
},
|
|
111
|
+
children: []
|
|
112
|
+
}, {
|
|
113
|
+
type: 'element',
|
|
114
|
+
tagName: 'path',
|
|
115
|
+
properties: {
|
|
116
|
+
fillRule: 'evenodd',
|
|
117
|
+
d: 'M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z'
|
|
118
|
+
},
|
|
119
|
+
children: []
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
type: 'element',
|
|
125
|
+
tagName: 'svg',
|
|
126
|
+
properties: {
|
|
127
|
+
className: 'octicon-check',
|
|
128
|
+
ariaHidden: 'true',
|
|
129
|
+
viewBox: '0 0 16 16',
|
|
130
|
+
fill: 'currentColor',
|
|
131
|
+
height: 12,
|
|
132
|
+
width: 12,
|
|
133
|
+
},
|
|
134
|
+
children: [
|
|
135
|
+
{
|
|
136
|
+
type: 'element',
|
|
137
|
+
tagName: 'path',
|
|
138
|
+
properties: {
|
|
139
|
+
fillRule: 'evenodd',
|
|
140
|
+
d: 'M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z'
|
|
141
|
+
},
|
|
142
|
+
children: []
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
const scriptString = `const t=document;const e="_dark_mode_theme_";const s="permanent";const o="colorschemechange";const i="permanentcolorscheme";const h="light";const r="dark";const n=(t,e,s=e)=>{Object.defineProperty(t,s,{enumerable:true,get(){const t=this.getAttribute(e);return t===null?"":t},set(t){this.setAttribute(e,t)}})};const c=(t,e,s=e)=>{Object.defineProperty(t,s,{enumerable:true,get(){return this.hasAttribute(e)},set(t){if(t){this.setAttribute(e,"")}else{this.removeAttribute(e)}}})};class a extends HTMLElement{static get observedAttributes(){return["mode",h,r,s]}LOCAL_NANE=e;constructor(){super();this.t()}connectedCallback(){n(this,"mode");n(this,r);n(this,h);c(this,s);const a=localStorage.getItem(e);if(a&&[h,r].includes(a)){this.mode=a;this.permanent=true}if(this.permanent&&!a){localStorage.setItem(e,this.mode)}const l=[h,r].includes(a);if(this.permanent&&a){this.o()}else{if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){this.mode=r;this.o()}if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches){this.mode=h;this.o()}}if(!this.permanent&&!l){window.matchMedia("(prefers-color-scheme: light)").onchange=t=>{this.mode=t.matches?h:r;this.o()};window.matchMedia("(prefers-color-scheme: dark)").onchange=t=>{this.mode=t.matches?r:h;this.o()}}const d=new MutationObserver(((s,h)=>{this.mode=t.documentElement.dataset.colorMode;if(this.permanent&&l){localStorage.setItem(e,this.mode);this.i(i,{permanent:this.permanent})}this.h();this.i(o,{colorScheme:this.mode})}));d.observe(t.documentElement,{attributes:true});this.i(o,{colorScheme:this.mode});this.h()}attributeChangedCallback(t,s,o){if(t==="mode"&&s!==o&&[h,r].includes(o)){const t=localStorage.getItem(e);if(this.mode===t){this.mode=o;this.h();this.o()}else if(this.mode&&this.mode!==t){this.h();this.o()}}else if((t===h||t===r)&&s!==o){this.h()}if(t==="permanent"&&typeof this.permanent==="boolean"){this.permanent?localStorage.setItem(e,this.mode):localStorage.removeItem(e)}}o(){t.documentElement.setAttribute("data-color-mode",this.mode)}h(){this.icon.textContent=this.mode===h?"🌒":"🌞";this.text.textContent=this.mode===h?this.getAttribute(r):this.getAttribute(h)}t(){var s=this.attachShadow({mode:"open"});this.label=t.createElement("span");this.label.setAttribute("class","wrapper");this.label.onclick=()=>{this.mode=this.mode===h?r:h;if(this.permanent){localStorage.setItem(e,this.mode)}this.o();this.h()};s.appendChild(this.label);this.icon=t.createElement("span");this.label.appendChild(this.icon);this.text=t.createElement("span");this.label.appendChild(this.text);const o=\`\n[data-color-mode*='dark'], [data-color-mode*='dark'] body {\n color-scheme: dark;\n --color-theme-bg: #0d1117;\n --color-theme-text: #c9d1d9;\n background-color: var(--color-theme-bg);\n color: var(--color-theme-text);\n}\n\n[data-color-mode*='light'], [data-color-mode*='light'] body {\n color-scheme: light;\n --color-theme-bg: #fff;\n --color-theme-text: #24292f;\n background-color: var(--color-theme-bg);\n color: var(--color-theme-text);\n}\`;const i="_dark_mode_style_";const n=t.getElementById(i);if(!n){var c=t.createElement("style");c.id=i;c.textContent=o;t.head.appendChild(c)}var a=t.createElement("style");a.textContent=\`\n .wrapper { cursor: pointer; user-select: none; position: relative; }\n .wrapper > span + span { margin-left: .4rem; }\n \`;s.appendChild(a)}i(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:true,composed:true,detail:e}))}}customElements.define("dark-mode",a);`
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @wcj/dark-mode@1.0.14
|
|
7
|
+
* https://github.com/jaywcjlove/dark-mode
|
|
8
|
+
*/
|
|
9
|
+
export function darkMode(): Element[] {
|
|
10
|
+
return [{
|
|
11
|
+
type: 'element',
|
|
12
|
+
tagName: 'script',
|
|
13
|
+
// properties: {
|
|
14
|
+
// src: 'https://unpkg.com/@wcj/dark-mode',
|
|
15
|
+
// },
|
|
16
|
+
children: [{
|
|
17
|
+
type: 'text',
|
|
18
|
+
value: scriptString,
|
|
19
|
+
}]
|
|
20
|
+
}, {
|
|
21
|
+
type: 'element',
|
|
22
|
+
tagName: 'dark-mode',
|
|
23
|
+
properties: {
|
|
24
|
+
permanent: true,
|
|
25
|
+
style: 'position: fixed; top: 8px; left: 10px; z-index: 999;',
|
|
26
|
+
dark: 'Dark',
|
|
27
|
+
light: 'Light',
|
|
28
|
+
},
|
|
29
|
+
children: []
|
|
30
|
+
}]
|
|
31
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
const style = `.github-fork-ribbon {
|
|
2
4
|
width: 12.1em;
|
|
3
5
|
height: 12.1em;
|
|
4
6
|
position: absolute;
|
|
@@ -88,4 +90,39 @@
|
|
|
88
90
|
border-style: dotted;
|
|
89
91
|
border-color: #fff;
|
|
90
92
|
border-color: rgba(255, 255, 255, 0.7);
|
|
93
|
+
}`;
|
|
94
|
+
|
|
95
|
+
interface GithubCorners {
|
|
96
|
+
href?: string;
|
|
91
97
|
}
|
|
98
|
+
|
|
99
|
+
export function githubCornersFork(opts: GithubCorners): Element {
|
|
100
|
+
const { href } = opts;
|
|
101
|
+
if (!href) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type: 'element',
|
|
106
|
+
tagName: 'a',
|
|
107
|
+
properties: {
|
|
108
|
+
'aria-label': 'Fork me on Github',
|
|
109
|
+
title: 'Fork me on GitHub',
|
|
110
|
+
target: '__blank',
|
|
111
|
+
className: 'github-fork-ribbon',
|
|
112
|
+
'data-ribbon': 'Fork me on GitHub',
|
|
113
|
+
href,
|
|
114
|
+
},
|
|
115
|
+
children: [
|
|
116
|
+
{
|
|
117
|
+
type: 'element',
|
|
118
|
+
tagName: 'style',
|
|
119
|
+
children: [
|
|
120
|
+
{
|
|
121
|
+
type: 'text',
|
|
122
|
+
value: style
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|