marp-dev-preview 0.1.7 → 0.1.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marp-dev-preview",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "A CLI tool to preview Marp markdown files.",
5
5
  "main": "src/marp-dev-preview.mjs",
6
6
  "type": "module",
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 <markdown-file> [options]')
7
- .positional('markdown-file', {
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-dir', {
12
+ .option('theme-set', {
12
13
  alias: 't',
13
- describe: 'Directory for custom themes',
14
- type: 'string'
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
  }
@@ -15,8 +15,8 @@ const __dirname = path.dirname(__filename);
15
15
 
16
16
  const argv = parseArgs();
17
17
 
18
- const markdownFile = argv._[0]
19
- const themeDir = argv.themeDir;
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(themeDir).then(() => {
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);
@@ -8,35 +8,39 @@ import markdownItContainer from 'markdown-it-container';
8
8
 
9
9
  let marp;
10
10
 
11
- export async function initializeMarp(themeDir) {
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 (!themeDir) {
18
+ if (!themeSet) {
19
19
  return marp;
20
20
  }
21
21
 
22
- let stats = await fs.stat(themeDir).catch(() => null);
23
- if (!stats) {
24
- console.warn(`Theme directory "${themeDir}" does not exist.`);
25
- return marp;
26
- }
22
+ console.log("Initializing Marp with themes...");
23
+ for( const index in themeSet ) {
24
+ let themeDir = themeSet[index];
25
+ let stats = await fs.stat(themeDir).catch(() => null);
26
+ if (!stats) {
27
+ console.warn(`Theme ${themeDir} directory does not exist.`);
28
+ continue;
29
+ }
27
30
 
28
- if(!stats.isDirectory()) {
29
- console.warn(`Theme directory "${themeDir}" is not a directory.`);
30
- return marp;
31
- }
31
+ if(!stats.isDirectory()) {
32
+ console.warn(`Path ${themeDir} is not a directory.`);
33
+ continue;
34
+ }
32
35
 
33
- console.log("Loading themes from:", themeDir);
36
+ console.log("Loading themes from ", themeDir);
34
37
 
35
- const themeFiles = await fs.readdir(themeDir);
36
- for (const file of themeFiles) {
37
- if (path.extname(file) === '.css') {
38
- const css = await fs.readFile(path.join(themeDir, file), 'utf8');
39
- marp.themeSet.add(css);
38
+ const themeFiles = await fs.readdir(themeDir);
39
+ for (const file of themeFiles) {
40
+ if (path.extname(file) === '.css') {
41
+ const css = await fs.readFile(path.join(themeDir, file), 'utf8');
42
+ marp.themeSet.add(css);
43
+ }
40
44
  }
41
45
  }
42
46