marp-dev-preview 0.1.6 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marp-dev-preview",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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
  }
package/src/client.js CHANGED
@@ -53,6 +53,11 @@ document.addEventListener('DOMContentLoaded', () => {
53
53
  try {
54
54
  const data = JSON.parse(event.data);
55
55
  if (data.type === 'update') {
56
+ // TODO: support force rebuild
57
+ // if(data.rebuild == true) {
58
+ // window.location.reload();
59
+ // return;
60
+ // }
56
61
  const marpContainer = document.getElementById('marp-container');
57
62
  if (marpContainer) {
58
63
  morphdom(marpContainer, `<div id="marp-container">${data.html}</div>`);
@@ -65,6 +70,8 @@ document.addEventListener('DOMContentLoaded', () => {
65
70
  goToSlide(parseInt(data.slide, 10));
66
71
  } else if (data.command === 'find' && data.string) {
67
72
  findSlideByString(data.string);
73
+ } else if (data.command === 'close_preview') {
74
+ window.close();
68
75
  }
69
76
  } catch (e) {
70
77
  console.error('Failed to parse WebSocket message:', e);
@@ -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,11 +147,8 @@ 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
- if (themeDir) {
153
- console.log(`Using custom themes from ${themeDir}`);
154
- }
155
152
  }).catch(error => {
156
153
  console.error("Failed to initialize Marp:", error);
157
154
  process.exit(1);
@@ -8,14 +8,34 @@ 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
+ return marp;
20
+ }
21
+
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
+ }
31
+
32
+ if(!stats.isDirectory()) {
33
+ console.warn(` Path is not a directory.`);
34
+ continue;
35
+ }
36
+
37
+ console.log(" Loading themes from:", themeDir);
38
+
19
39
  const themeFiles = await fs.readdir(themeDir);
20
40
  for (const file of themeFiles) {
21
41
  if (path.extname(file) === '.css') {
@@ -24,6 +44,7 @@ export async function initializeMarp(themeDir) {
24
44
  }
25
45
  }
26
46
  }
47
+
27
48
  return marp;
28
49
  }
29
50