markdown-to-html-cli 3.2.12 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -9
- package/lib/create.js +56 -92
- package/lib/create.js.map +1 -1
- package/lib/index.d.ts +3 -9
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/nodes/copy.d.ts +2 -0
- package/lib/nodes/copy.js +76 -1
- package/lib/nodes/copy.js.map +1 -1
- package/lib/nodes/dark-mode.d.ts +6 -0
- package/lib/nodes/dark-mode.js +29 -0
- package/lib/nodes/dark-mode.js.map +1 -0
- package/lib/nodes/{githubCornersFork.d.ts → github-corners-fork.d.ts} +0 -0
- package/lib/nodes/github-corners-fork.js +122 -0
- package/lib/nodes/github-corners-fork.js.map +1 -0
- package/lib/nodes/{githubCorners.d.ts → github-corners.d.ts} +1 -1
- package/lib/nodes/github-corners.js +110 -0
- package/lib/nodes/github-corners.js.map +1 -0
- package/lib/nodes/markdown-style.d.ts +2 -0
- package/lib/nodes/markdown-style.js +107 -0
- package/lib/nodes/markdown-style.js.map +1 -0
- package/package.json +7 -16
- package/src/cli.ts +5 -0
- package/src/create.ts +103 -0
- package/src/index.ts +118 -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 +109 -0
- package/src/nodes/octiconLink.ts +12 -0
- package/src/utils.ts +50 -0
- package/github.css +0 -930
- package/lib/nodes/githubCorners.js +0 -59
- package/lib/nodes/githubCorners.js.map +0 -1
- package/lib/nodes/githubCornersFork.js +0 -20
- package/lib/nodes/githubCornersFork.js.map +0 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
interface GithubCorners {
|
|
4
|
+
href?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @uiw/github-corners@1.5.10
|
|
9
|
+
* https://github.com/uiwjs/react-github-corners
|
|
10
|
+
*/
|
|
11
|
+
const scriptString = `const TEMPLATE = document.createElement("template");
|
|
12
|
+
TEMPLATE.innerHTML = \`
|
|
13
|
+
<style>
|
|
14
|
+
:host a:hover .octo-arm {
|
|
15
|
+
animation: octocat-wave 560ms ease-in-out;
|
|
16
|
+
}
|
|
17
|
+
@keyframes octocat-wave {
|
|
18
|
+
0%, 100% {
|
|
19
|
+
transform: rotate(0);
|
|
20
|
+
}
|
|
21
|
+
20%, 60% {
|
|
22
|
+
transform: rotate(-25deg);
|
|
23
|
+
}
|
|
24
|
+
40%, 80% {
|
|
25
|
+
transform: rotate(10deg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
@media (max-width:500px) {
|
|
29
|
+
:host a:hover .octo-arm {
|
|
30
|
+
animation: none;
|
|
31
|
+
}
|
|
32
|
+
:host .octo-arm {
|
|
33
|
+
animation: octocat-wave 560ms ease-in-out;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
37
|
+
<svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true" style="position: absolute; border: 0px; top: 0px;">
|
|
38
|
+
<a xlink:href="https://github.com/uiwjs/react-github-corners" target="_blank" rel="nofollow sponsored" style="fill: rgb(21, 21, 19); color: rgb(255, 255, 255);">
|
|
39
|
+
<g>
|
|
40
|
+
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
|
|
41
|
+
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" class="octo-arm" style="transform-origin: 130px 106px;"></path>
|
|
42
|
+
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
|
|
43
|
+
</g>
|
|
44
|
+
</a>
|
|
45
|
+
</svg>
|
|
46
|
+
\`;
|
|
47
|
+
export class GithubCorners extends HTMLElement {
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
this.right = '0';
|
|
51
|
+
this.shadow = this.attachShadow({ mode: 'open' });
|
|
52
|
+
this.shadow.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true));
|
|
53
|
+
this.update();
|
|
54
|
+
}
|
|
55
|
+
static get observedAttributes() {
|
|
56
|
+
return ['z-index', 'target', 'height', 'width', 'href', 'color', 'fill', 'position', 'top', 'left', 'right', 'bottom', 'transform'];
|
|
57
|
+
}
|
|
58
|
+
setAttr(name, value) {
|
|
59
|
+
const svg = this.shadow.querySelector('svg');
|
|
60
|
+
if (/(href)/.test(name.toLocaleLowerCase())) {
|
|
61
|
+
svg.lastElementChild.setAttribute('xlink:href', value);
|
|
62
|
+
}
|
|
63
|
+
else if (/(color|fill)/.test(name.toLocaleLowerCase())) {
|
|
64
|
+
svg.firstElementChild.style[name] = value;
|
|
65
|
+
}
|
|
66
|
+
else if (/(z-index|height|width|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
|
|
67
|
+
svg.style[name] = value;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
svg.setAttribute(name, value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
update() {
|
|
74
|
+
;
|
|
75
|
+
[...this.getAttributeNames(), 'right'].forEach((name) => {
|
|
76
|
+
const value = this.getAttribute(name) || this[name] || '';
|
|
77
|
+
this.setAttr(name, value);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
81
|
+
if (oldValue !== newValue) {
|
|
82
|
+
this.setAttr(name, newValue);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
customElements.define('github-corners', GithubCorners);`;
|
|
87
|
+
|
|
88
|
+
export function githubCorners(opts: GithubCorners): Element[] {
|
|
89
|
+
const { href } = opts;
|
|
90
|
+
if (!href) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
type: 'element',
|
|
96
|
+
tagName: 'github-corners',
|
|
97
|
+
properties: {
|
|
98
|
+
target: '__blank',
|
|
99
|
+
position: 'fixed',
|
|
100
|
+
href,
|
|
101
|
+
},
|
|
102
|
+
children: []
|
|
103
|
+
}, {
|
|
104
|
+
type: 'element',
|
|
105
|
+
tagName: 'script',
|
|
106
|
+
properties: {
|
|
107
|
+
type: 'module',
|
|
108
|
+
// src: 'https://unpkg.com/@uiw/github-corners?module',
|
|
109
|
+
},
|
|
110
|
+
children: [{
|
|
111
|
+
type: 'text',
|
|
112
|
+
value: scriptString,
|
|
113
|
+
}]
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Element, ElementContent } from 'hast';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @wcj/markdown-to-html@2.0.1
|
|
5
|
+
* https://github.com/jaywcjlove/markdown-to-html
|
|
6
|
+
*/
|
|
7
|
+
const scriptString = `
|
|
8
|
+
const __TEMPLATE__ = document.createElement('template');
|
|
9
|
+
__TEMPLATE__.innerHTML = \`
|
|
10
|
+
<style>
|
|
11
|
+
:host [data-color-mode*='light'] { --color-prettylights-syntax-comment: #6e7781; --color-prettylights-syntax-constant: #0550ae; --color-prettylights-syntax-entity: #8250df; --color-prettylights-syntax-storage-modifier-import: #24292f; --color-prettylights-syntax-entity-tag: #116329; --color-prettylights-syntax-keyword: #cf222e; --color-prettylights-syntax-string: #0a3069; --color-prettylights-syntax-variable: #953800; --color-prettylights-syntax-brackethighlighter-unmatched: #82071e; --color-prettylights-syntax-invalid-illegal-text: #f6f8fa; --color-prettylights-syntax-invalid-illegal-bg: #82071e; --color-prettylights-syntax-carriage-return-text: #f6f8fa; --color-prettylights-syntax-carriage-return-bg: #cf222e; --color-prettylights-syntax-string-regexp: #116329; --color-prettylights-syntax-markup-list: #3b2300; --color-prettylights-syntax-markup-heading: #0550ae; --color-prettylights-syntax-markup-italic: #24292f; --color-prettylights-syntax-markup-bold: #24292f; --color-prettylights-syntax-markup-deleted-text: #82071e; --color-prettylights-syntax-markup-deleted-bg: #FFEBE9; --color-prettylights-syntax-markup-inserted-text: #116329; --color-prettylights-syntax-markup-inserted-bg: #dafbe1; --color-prettylights-syntax-markup-changed-text: #953800; --color-prettylights-syntax-markup-changed-bg: #ffd8b5; --color-prettylights-syntax-markup-ignored-text: #eaeef2; --color-prettylights-syntax-markup-ignored-bg: #0550ae; --color-prettylights-syntax-meta-diff-range: #8250df; --color-prettylights-syntax-brackethighlighter-angle: #57606a; --color-prettylights-syntax-sublimelinter-gutter-mark: #8c959f; --color-prettylights-syntax-constant-other-reference-link: #0a3069; --color-fg-default: #24292f; --color-fg-muted: #57606a; --color-fg-subtle: #6e7781; --color-canvas-default: #ffffff; --color-canvas-subtle: #f6f8fa; --color-border-default: #d0d7de; --color-border-muted: hsla(210,18%,87%,1); --color-neutral-muted: rgba(175,184,193,0.2); --color-accent-fg: #0969da; --color-accent-emphasis: #0969da; --color-attention-subtle: #fff8c5; --color-danger-fg: #cf222e; } :host [data-color-mode*='dark'] { --color-prettylights-syntax-comment: #8b949e; --color-prettylights-syntax-constant: #79c0ff; --color-prettylights-syntax-entity: #d2a8ff; --color-prettylights-syntax-storage-modifier-import: #c9d1d9; --color-prettylights-syntax-entity-tag: #7ee787; --color-prettylights-syntax-keyword: #ff7b72; --color-prettylights-syntax-string: #a5d6ff; --color-prettylights-syntax-variable: #ffa657; --color-prettylights-syntax-brackethighlighter-unmatched: #f85149; --color-prettylights-syntax-invalid-illegal-text: #f0f6fc; --color-prettylights-syntax-invalid-illegal-bg: #8e1519; --color-prettylights-syntax-carriage-return-text: #f0f6fc; --color-prettylights-syntax-carriage-return-bg: #b62324; --color-prettylights-syntax-string-regexp: #7ee787; --color-prettylights-syntax-markup-list: #f2cc60; --color-prettylights-syntax-markup-heading: #1f6feb; --color-prettylights-syntax-markup-italic: #c9d1d9; --color-prettylights-syntax-markup-bold: #c9d1d9; --color-prettylights-syntax-markup-deleted-text: #ffdcd7; --color-prettylights-syntax-markup-deleted-bg: #67060c; --color-prettylights-syntax-markup-inserted-text: #aff5b4; --color-prettylights-syntax-markup-inserted-bg: #033a16; --color-prettylights-syntax-markup-changed-text: #ffdfb6; --color-prettylights-syntax-markup-changed-bg: #5a1e02; --color-prettylights-syntax-markup-ignored-text: #c9d1d9; --color-prettylights-syntax-markup-ignored-bg: #1158c7; --color-prettylights-syntax-meta-diff-range: #d2a8ff; --color-prettylights-syntax-brackethighlighter-angle: #8b949e; --color-prettylights-syntax-sublimelinter-gutter-mark: #484f58; --color-prettylights-syntax-constant-other-reference-link: #a5d6ff; --color-fg-default: #c9d1d9; --color-fg-muted: #8b949e; --color-fg-subtle: #484f58; --color-canvas-default: #0d1117; --color-canvas-subtle: #161b22; --color-border-default: #30363d; --color-border-muted: #21262d; --color-neutral-muted: rgba(110,118,129,0.4); --color-accent-fg: #58a6ff; --color-accent-emphasis: #1f6feb; --color-attention-subtle: rgba(187,128,9,0.15); --color-danger-fg: #f85149; } .markdown-body { -webkit-text-size-adjust: 100%; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; font-size: 16px; line-height: 1.5; word-wrap: break-word; color: var(--color-fg-default); background-color: var(--color-canvas-default); } :host details, :host figcaption, :host figure { display: block; } :host summary { display: list-item; } :host [hidden] { display: none !important; } :host a { background-color: transparent; color: var(--color-accent-fg); text-decoration: none; } :host a:active, :host a:hover { outline-width: 0; } :host abbr[title] { border-bottom: none; text-decoration: underline dotted; } :host b, :host strong { font-weight: 600; } :host dfn { font-style: italic; } :host h1 { margin: .67em 0; font-weight: 600; padding-bottom: .3em; font-size: 2em; border-bottom: 1px solid var(--color-border-muted); } :host mark { background-color: var(--color-attention-subtle); color: var(--color-text-primary); } :host small { font-size: 90%; } :host sub, :host sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } :host sub { bottom: -0.25em; } :host sup { top: -0.5em; } :host img { border-style: none; max-width: 100%; box-sizing: content-box; background-color: var(--color-canvas-default); } :host code, :host kbd, :host pre, :host samp { font-family: monospace,monospace; font-size: 1em; } :host figure { margin: 1em 40px; } :host hr { box-sizing: content-box; overflow: hidden; background: transparent; border-bottom: 1px solid var(--color-border-muted); height: .25em; padding: 0; margin: 24px 0; background-color: var(--color-border-default); border: 0; } :host input { font: inherit; margin: 0; overflow: visible; font-family: inherit; font-size: inherit; line-height: inherit; } :host [type=button], :host [type=reset], :host [type=submit] { -webkit-appearance: button; } :host [type=button]::-moz-focus-inner, :host [type=reset]::-moz-focus-inner, :host [type=submit]::-moz-focus-inner { border-style: none; padding: 0; } :host [type=button]:-moz-focusring, :host [type=reset]:-moz-focusring, :host [type=submit]:-moz-focusring { outline: 1px dotted ButtonText; } :host [type=checkbox], :host [type=radio] { box-sizing: border-box; padding: 0; } :host [type=number]::-webkit-inner-spin-button, :host [type=number]::-webkit-outer-spin-button { height: auto; } :host [type=search] { -webkit-appearance: textfield; outline-offset: -2px; } :host [type=search]::-webkit-search-cancel-button, :host [type=search]::-webkit-search-decoration { -webkit-appearance: none; } :host ::-webkit-input-placeholder { color: inherit; opacity: .54; } :host ::-webkit-file-upload-button { -webkit-appearance: button; font: inherit; } :host a:hover { text-decoration: underline; } :host hr::before { display: table; content: ""; } :host hr::after { display: table; clear: both; content: ""; } :host table { border-spacing: 0; border-collapse: collapse; display: block; width: max-content; max-width: 100%; overflow: auto; } :host td, :host th { padding: 0; } :host details summary { cursor: pointer; } :host details:not([open])>*:not(summary) { display: none !important; } :host kbd { display: inline-block; padding: 3px 5px; font: 11px ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; line-height: 10px; color: var(--color-fg-default); vertical-align: middle; background-color: var(--color-canvas-subtle); border: solid 1px var(--color-neutral-muted); border-bottom-color: var(--color-neutral-muted); border-radius: 6px; box-shadow: inset 0 -1px 0 var(--color-neutral-muted); } :host h1, :host h2, :host h3, :host h4, :host h5, :host h6 { margin-top: 24px; margin-bottom: 16px; font-weight: 600; line-height: 1.25; } :host h2 { font-weight: 600; padding-bottom: .3em; font-size: 1.5em; border-bottom: 1px solid var(--color-border-muted); } :host h3 { font-weight: 600; font-size: 1.25em; } :host h4 { font-weight: 600; font-size: 1em; } :host h5 { font-weight: 600; font-size: .875em; } :host h6 { font-weight: 600; font-size: .85em; color: var(--color-fg-muted); } :host p { margin-top: 0; margin-bottom: 10px; } :host blockquote { margin: 0; padding: 0 1em; color: var(--color-fg-muted); border-left: .25em solid var(--color-border-default); } :host ul, :host ol { margin-top: 0; margin-bottom: 0; padding-left: 2em; } :host ol ol, :host ul ol { list-style-type: lower-roman; } :host ul ul ol, :host ul ol ol, :host ol ul ol, :host ol ol ol { list-style-type: lower-alpha; } :host dd { margin-left: 0; } :host tt, :host code { font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; font-size: 12px; } :host pre { margin-top: 0; margin-bottom: 0; font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; font-size: 12px; word-wrap: normal; } :host .octicon { display: inline-block; overflow: visible !important; vertical-align: text-bottom; fill: currentColor; }
|
|
12
|
+
:host ::placeholder { color: var(--color-fg-subtle); opacity: 1; } :host input::-webkit-outer-spin-button, :host input::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; appearance: none; } .token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--color-prettylights-syntax-comment); } .token.namespace { opacity: 0.7; } .token.tag, .token.selector, .token.constant, .token.symbol, .token.deleted { color: var(--color-prettylights-syntax-entity-tag); } .token.maybe-class-name { color: var(--color-prettylights-syntax-variable); } .token.property-access, .token.operator, .token.boolean, .token.number, .token.selector .token.class, .token.attr-name, .token.string, .token.char, .token.builtin { color: var(--color-prettylights-syntax-constant); } .token.deleted { color: var(--color-prettylights-syntax-markup-deleted-text); } .token.property { color: var(--color-prettylights-syntax-constant); } .token.punctuation { color: var(--color-prettylights-syntax-markup-bold); } .token.function { color: var(--color-prettylights-syntax-entity); } .code-line .token.deleted { background-color: var(--color-prettylights-syntax-markup-deleted-bg); } .token.inserted { color: var(--color-prettylights-syntax-markup-inserted-text); } .code-line .token.inserted { background-color: var(--color-prettylights-syntax-markup-inserted-bg); } .token.variable { color: var(--color-prettylights-syntax-constant); } .token.entity, .token.url, .language-css .token.string, .style .token.string { color: var(--color-prettylights-syntax-string); } .token.color, .token.atrule, .token.attr-value, .token.function, .token.class-name { color: var(--color-prettylights-syntax-string); } .token.rule, .token.regex, .token.important, .token.keyword { color: var(--color-prettylights-syntax-keyword); } .token.coord { color: var(--color-prettylights-syntax-meta-diff-range); } .token.important, .token.bold { font-weight: bold; } .token.italic { font-style: italic; } .token.entity { cursor: help; } :host [data-catalyst] { display: block; } :host g-emoji { font-family: "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"; font-size: 1em; font-style: normal !important; font-weight: 400; line-height: 1; vertical-align: -0.075em; } :host g-emoji img { width: 1em; height: 1em; } .markdown-body::before { display: table; content: ""; } .markdown-body::after { display: table; clear: both; content: ""; } .markdown-body>*:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !important; } :host a:not([href]) { color: inherit; text-decoration: none; } :host .absent { color: var(--color-danger-fg); } :host .anchor { float: left; padding-right: 4px; margin-left: -20px; line-height: 1; } :host .anchor:focus { outline: none; } :host p, :host blockquote, :host ul, :host ol, :host dl, :host table, :host pre, :host details { margin-top: 0; margin-bottom: 16px; } :host blockquote>:first-child { margin-top: 0; } :host blockquote>:last-child { margin-bottom: 0; } :host sup>a::before { content: "["; } :host sup>a::after { content: "]"; } :host h1 .octicon-link, :host h2 .octicon-link, :host h3 .octicon-link, :host h4 .octicon-link, :host h5 .octicon-link, :host h6 .octicon-link { color: var(--color-fg-default); vertical-align: middle; visibility: hidden; } :host h1:hover .anchor, :host h2:hover .anchor, :host h3:hover .anchor, :host h4:hover .anchor, :host h5:hover .anchor, :host h6:hover .anchor { text-decoration: none; } :host h1:hover .anchor .octicon-link, :host h2:hover .anchor .octicon-link, :host h3:hover .anchor .octicon-link, :host h4:hover .anchor .octicon-link, :host h5:hover .anchor .octicon-link, :host h6:hover .anchor .octicon-link { visibility: visible; } :host h1 tt, :host h1 code, :host h2 tt, :host h2 code, :host h3 tt, :host h3 code, :host h4 tt, :host h4 code, :host h5 tt, :host h5 code, :host h6 tt, :host h6 code { padding: 0 .2em; font-size: inherit; } :host ul.no-list, :host ol.no-list { padding: 0; list-style-type: none; } :host ol[type="1"] { list-style-type: decimal; } :host ol[type=a] { list-style-type: lower-alpha; } :host ol[type=i] { list-style-type: lower-roman; } :host div>ol:not([type]) { list-style-type: decimal; } :host ul ul, :host ul ol, :host ol ol, :host ol ul { margin-top: 0; margin-bottom: 0; } :host li>p { margin-top: 16px; } :host li+li { margin-top: .25em; } :host dl { padding: 0; } :host dl dt { padding: 0; margin-top: 16px; font-size: 1em; font-style: italic; font-weight: 600; } :host dl dd { padding: 0 16px; margin-bottom: 16px; } :host table th { font-weight: 600; } :host table th, :host table td { padding: 6px 13px; border: 1px solid var(--color-border-default); } :host table tr { background-color: var(--color-canvas-default); border-top: 1px solid var(--color-border-muted); } :host table tr:nth-child(2n) { background-color: var(--color-canvas-subtle); } :host table img { background-color: transparent; } :host img[align=right] { padding-left: 20px; } :host img[align=left] { padding-right: 20px; } :host .emoji { max-width: none; vertical-align: text-top; background-color: transparent; } :host span.frame { display: block; overflow: hidden; } :host span.frame>span { display: block; float: left; width: auto; padding: 7px; margin: 13px 0 0; overflow: hidden; border: 1px solid var(--color-border-default); } :host span.frame span img { display: block; float: left; } :host span.frame span span { display: block; padding: 5px 0 0; clear: both; color: var(--color-fg-default); } :host span.align-center { display: block; overflow: hidden; clear: both; } :host span.align-center>span { display: block; margin: 13px auto 0; overflow: hidden; text-align: center; } :host span.align-center span img { margin: 0 auto; text-align: center; } :host span.align-right { display: block; overflow: hidden; clear: both; } :host span.align-right>span { display: block; margin: 13px 0 0; overflow: hidden; text-align: right; } :host span.align-right span img { margin: 0; text-align: right; } :host span.float-left { display: block; float: left; margin-right: 13px; overflow: hidden; } :host span.float-left span { margin: 13px 0 0; } :host span.float-right { display: block; float: right; margin-left: 13px; overflow: hidden; } :host span.float-right>span { display: block; margin: 13px auto 0; overflow: hidden; text-align: right; } :host code, :host tt { padding: .2em .4em; margin: 0; font-size: 85%; background-color: var(--color-neutral-muted); border-radius: 6px; } :host code br, :host tt br { display: none; } :host del code { text-decoration: inherit; } :host pre code { font-size: 100%; } :host pre>code { padding: 0; margin: 0; word-break: normal; white-space: pre; background: transparent; border: 0; } :host .highlight { margin-bottom: 16px; } :host .highlight pre { margin-bottom: 0; word-break: normal; } :host .highlight pre, :host pre { position: relative; padding: 16px; overflow: auto; font-size: 85%; line-height: 1.45; background-color: var(--color-canvas-subtle); border-radius: 6px; } :host pre code, :host pre tt { display: inline; max-width: auto; padding: 0; margin: 0; overflow: visible; line-height: inherit; word-wrap: normal; background-color: transparent; border: 0; } :host .csv-data td, :host .csv-data th { padding: 5px; overflow: hidden; font-size: 12px; line-height: 1; text-align: left; white-space: nowrap; } :host .csv-data .blob-num { padding: 10px 8px 9px; text-align: right; background: var(--color-canvas-default); border: 0; } :host .csv-data tr { border-top: 0; } :host .csv-data th { font-weight: 600; background: var(--color-canvas-subtle); border-top: 0; } :host .footnotes { font-size: 12px; color: var(--color-fg-muted); border-top: 1px solid var(--color-border-default); } :host .footnotes ol { padding-left: 16px; } :host .footnotes li { position: relative; } :host .footnotes li:target::before { position: absolute; top: -8px; right: -8px; bottom: -8px; left: -24px; pointer-events: none; content: ""; border: 2px solid var(--color-accent-emphasis); border-radius: 6px; } :host .footnotes li:target { color: var(--color-fg-default); } :host .footnotes .data-footnote-backref g-emoji { font-family: monospace; } :host .task-list-item { list-style-type: none; } :host .task-list-item label { font-weight: 400; } :host .task-list-item.enabled label { cursor: pointer; } :host .task-list-item+.task-list-item { margin-top: 3px; } :host .task-list-item .handle { display: none; } :host .task-list-item-checkbox, :host input[type="checkbox"] { margin: 0 .2em .25em -1.6em; vertical-align: middle; } :host .contains-task-list:dir(rtl) .task-list-item-checkbox, :host .contains-task-list:dir(rtl) input[type="checkbox"] { margin: 0 -1.6em .25em .2em; } :host ::-webkit-calendar-picker-indicator { filter: invert(50%); }
|
|
13
|
+
</style>
|
|
14
|
+
\`;
|
|
15
|
+
// See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html
|
|
16
|
+
// #reflecting-content-attributes-in-idl-attributes.
|
|
17
|
+
const installStringReflection = (obj, attrName, propName = attrName) => {
|
|
18
|
+
Object.defineProperty(obj, propName, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get() {
|
|
21
|
+
const value = this.getAttribute(attrName);
|
|
22
|
+
return value === null ? '' : value;
|
|
23
|
+
},
|
|
24
|
+
set(v) {
|
|
25
|
+
this.setAttribute(attrName, v);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export class MarkdownStyle extends HTMLElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super();
|
|
32
|
+
this.initTheme = this.getAttribute('theme');
|
|
33
|
+
installStringReflection(this, 'theme');
|
|
34
|
+
this.shadow = this.attachShadow({ mode: 'open' });
|
|
35
|
+
this.shadow.appendChild(__TEMPLATE__.content.cloneNode(true));
|
|
36
|
+
this.warpper = document.createElement('div');
|
|
37
|
+
this.warpper.classList.add('markdown-body');
|
|
38
|
+
this.shadow.appendChild(this.warpper);
|
|
39
|
+
Array.prototype.slice.call(this.shadow.host.childNodes).forEach((item) => this.warpper.appendChild(item));
|
|
40
|
+
this.setTheme();
|
|
41
|
+
}
|
|
42
|
+
setTheme() {
|
|
43
|
+
if (!this.initTheme) {
|
|
44
|
+
const { colorMode } = document.documentElement.dataset;
|
|
45
|
+
this.theme = colorMode;
|
|
46
|
+
if (this.theme === 'undefined') {
|
|
47
|
+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
48
|
+
this.theme = 'dark';
|
|
49
|
+
}
|
|
50
|
+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
|
51
|
+
this.theme = 'light';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
this.warpper.setAttribute('data-color-mode', this.theme);
|
|
56
|
+
}
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
if (!this.initTheme) {
|
|
59
|
+
this.setTheme();
|
|
60
|
+
const observer = new MutationObserver((mutationsList, observer) => {
|
|
61
|
+
this.theme = document.documentElement.dataset.colorMode;
|
|
62
|
+
this.setTheme();
|
|
63
|
+
});
|
|
64
|
+
// Start observing the target node with the above configuration
|
|
65
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
66
|
+
window.matchMedia('(prefers-color-scheme: light)').onchange = (event) => {
|
|
67
|
+
this.theme = event.matches ? 'light' : 'dark';
|
|
68
|
+
this.setTheme();
|
|
69
|
+
};
|
|
70
|
+
window.matchMedia('(prefers-color-scheme: dark)').onchange = (event) => {
|
|
71
|
+
this.theme = event.matches ? 'dark' : 'light';
|
|
72
|
+
this.setTheme();
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
customElements.define('markdown-style', MarkdownStyle);
|
|
78
|
+
`
|
|
79
|
+
|
|
80
|
+
export function markdownStyle(child: ElementContent[], darkMode: boolean): Element[] {
|
|
81
|
+
const properties: Record<string, string> = {}
|
|
82
|
+
if (!darkMode) {
|
|
83
|
+
properties.theme = "light";
|
|
84
|
+
}
|
|
85
|
+
return [{
|
|
86
|
+
type: 'element',
|
|
87
|
+
tagName: 'script',
|
|
88
|
+
properties: {
|
|
89
|
+
type: 'module',
|
|
90
|
+
// src: 'https://unpkg.com/@wcj/markdown-style?module',
|
|
91
|
+
},
|
|
92
|
+
children: [{
|
|
93
|
+
type: 'text',
|
|
94
|
+
value: scriptString
|
|
95
|
+
}]
|
|
96
|
+
}, {
|
|
97
|
+
type: 'element',
|
|
98
|
+
tagName: 'div',
|
|
99
|
+
properties: {
|
|
100
|
+
style: 'max-width: 960px; margin: 28px auto 60px auto; padding: 8px'
|
|
101
|
+
},
|
|
102
|
+
children: [{
|
|
103
|
+
type: 'element',
|
|
104
|
+
properties,
|
|
105
|
+
tagName: 'markdown-style',
|
|
106
|
+
children: child
|
|
107
|
+
}]
|
|
108
|
+
}]
|
|
109
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { RunArgvs, MDToHTMLOptions } from './';
|
|
4
|
+
|
|
5
|
+
export type Options = Omit<RunArgvs, '_'>
|
|
6
|
+
|
|
7
|
+
export function formatConfig(opts: Options) {
|
|
8
|
+
let options = { ...opts, document: { title: opts.title, meta: [], link: [] } } as MDToHTMLOptions;
|
|
9
|
+
const projectPkg = path.resolve(process.cwd(), opts.config || 'package.json');
|
|
10
|
+
let pgkData: any = {};
|
|
11
|
+
if (fs.existsSync(projectPkg)) {
|
|
12
|
+
pgkData = fs.readJSONSync(projectPkg);
|
|
13
|
+
if (pgkData.name && !options.document.title) {
|
|
14
|
+
options.document.title = pgkData.name;
|
|
15
|
+
}
|
|
16
|
+
if (pgkData.repository && !opts['github-corners']) {
|
|
17
|
+
opts['github-corners'] = typeof pgkData.repository === 'string' ? pgkData.repository : pgkData.repository.url;
|
|
18
|
+
}
|
|
19
|
+
if (pgkData['markdown-to-html']) {
|
|
20
|
+
const mth = pgkData['markdown-to-html'] as MDToHTMLOptions;
|
|
21
|
+
const { title, meta, link } = options.document;
|
|
22
|
+
options = { ...options, ...mth, document: { title, meta, link, ...mth.document } }
|
|
23
|
+
if (mth['github-corners']) {
|
|
24
|
+
opts['github-corners'] = mth['github-corners'];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (opts['github-corners']) {
|
|
29
|
+
opts['github-corners'] = opts['github-corners'].replace(/^git[+]/, '')
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(options.document.link) && options.favicon) {
|
|
32
|
+
options.document.link.push({ rel: 'icon', href: options.favicon, type: 'image/x-icon' });
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(options.document.meta)) {
|
|
35
|
+
if (options.description) {
|
|
36
|
+
options.document.meta.push({ description: options.description });
|
|
37
|
+
} else if (pgkData.description) {
|
|
38
|
+
options.document.meta.push({ description: pgkData.description });
|
|
39
|
+
}
|
|
40
|
+
if (options.keywords) {
|
|
41
|
+
options.document.meta.push({ keywords: options.keywords });
|
|
42
|
+
} else if (pgkData.keywords && Array.isArray(pgkData.keywords)) {
|
|
43
|
+
options.document.meta.push({ keywords: pgkData.keywords.join(',') });
|
|
44
|
+
}
|
|
45
|
+
if (typeof options.author === 'string') {
|
|
46
|
+
options.document.meta.push({ author: options.author });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|