marp-dev-preview 0.1.7 → 0.1.8
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/package.json +1 -1
- package/src/args.mjs +6 -6
- package/src/marp-dev-preview.mjs +3 -3
- package/src/marp-utils.mjs +22 -17
package/package.json
CHANGED
package/src/args.mjs
CHANGED
|
@@ -3,15 +3,16 @@ import { hideBin } from 'yargs/helpers';
|
|
|
3
3
|
|
|
4
4
|
export function parseArgs() {
|
|
5
5
|
return yargs(hideBin(process.argv))
|
|
6
|
-
.usage('Usage: $0
|
|
7
|
-
.
|
|
6
|
+
.usage('Usage: $0 [options]')
|
|
7
|
+
.option('markdown-file', {
|
|
8
|
+
alias: 'm',
|
|
8
9
|
describe: 'Path to the markdown file to preview',
|
|
9
10
|
type: 'string'
|
|
10
11
|
})
|
|
11
|
-
.option('theme-
|
|
12
|
+
.option('theme-set', {
|
|
12
13
|
alias: 't',
|
|
13
|
-
describe: '
|
|
14
|
-
type: '
|
|
14
|
+
describe: 'Directories for custom themes',
|
|
15
|
+
type: 'array'
|
|
15
16
|
})
|
|
16
17
|
.option('port', {
|
|
17
18
|
alias: 'p',
|
|
@@ -27,6 +28,5 @@ export function parseArgs() {
|
|
|
27
28
|
})
|
|
28
29
|
.config('config', 'Path to a JSON config file')
|
|
29
30
|
.default('config', '.mp-config.json')
|
|
30
|
-
.demandCommand(1, 'You must provide a markdown file.')
|
|
31
31
|
.argv;
|
|
32
32
|
}
|
package/src/marp-dev-preview.mjs
CHANGED
|
@@ -15,8 +15,8 @@ const __dirname = path.dirname(__filename);
|
|
|
15
15
|
|
|
16
16
|
const argv = parseArgs();
|
|
17
17
|
|
|
18
|
-
const markdownFile = argv.
|
|
19
|
-
const
|
|
18
|
+
const markdownFile = argv.markdownFile;
|
|
19
|
+
const themeSet = argv.themeSet;
|
|
20
20
|
const port = argv.port;
|
|
21
21
|
const verbose = argv.verbose;
|
|
22
22
|
|
|
@@ -147,7 +147,7 @@ chokidar.watch(markdownFile).on('change', async () => {
|
|
|
147
147
|
await reload(md);
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
initializeMarp(
|
|
150
|
+
initializeMarp(themeSet).then(() => {
|
|
151
151
|
createServer(port, markdownFile, markdownDir, renderMarp, reload, wss, __dirname);
|
|
152
152
|
}).catch(error => {
|
|
153
153
|
console.error("Failed to initialize Marp:", error);
|
package/src/marp-utils.mjs
CHANGED
|
@@ -8,35 +8,40 @@ import markdownItContainer from 'markdown-it-container';
|
|
|
8
8
|
|
|
9
9
|
let marp;
|
|
10
10
|
|
|
11
|
-
export async function initializeMarp(
|
|
11
|
+
export async function initializeMarp(themeSet) {
|
|
12
12
|
const options = { html: true, linkify: true, };
|
|
13
13
|
marp = new Marp(options)
|
|
14
14
|
.use(markdownItFootnote)
|
|
15
15
|
.use(markdownItMark)
|
|
16
16
|
.use(markdownItContainer, 'note');
|
|
17
17
|
|
|
18
|
-
if (!
|
|
18
|
+
if (!themeSet) {
|
|
19
19
|
return marp;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
console.log("Initializing Marp with themes...");
|
|
23
|
+
for( const index in themeSet ) {
|
|
24
|
+
let themeDir = themeSet[index];
|
|
25
|
+
console.log("Processing theme directory:", themeDir);
|
|
26
|
+
let stats = await fs.stat(themeDir).catch(() => null);
|
|
27
|
+
if (!stats) {
|
|
28
|
+
console.warn(` Theme directory does not exist.`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
if(!stats.isDirectory()) {
|
|
33
|
+
console.warn(` Path is not a directory.`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
console.log(" Loading themes from:", themeDir);
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const themeFiles = await fs.readdir(themeDir);
|
|
40
|
+
for (const file of themeFiles) {
|
|
41
|
+
if (path.extname(file) === '.css') {
|
|
42
|
+
const css = await fs.readFile(path.join(themeDir, file), 'utf8');
|
|
43
|
+
marp.themeSet.add(css);
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
|