marp-dev-preview 0.1.6 → 0.1.7

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.7",
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/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);
@@ -149,9 +149,6 @@ chokidar.watch(markdownFile).on('change', async () => {
149
149
 
150
150
  initializeMarp(themeDir).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);
@@ -15,15 +15,31 @@ export async function initializeMarp(themeDir) {
15
15
  .use(markdownItMark)
16
16
  .use(markdownItContainer, 'note');
17
17
 
18
- if (themeDir) {
19
- const themeFiles = await fs.readdir(themeDir);
20
- for (const file of themeFiles) {
21
- if (path.extname(file) === '.css') {
22
- const css = await fs.readFile(path.join(themeDir, file), 'utf8');
23
- marp.themeSet.add(css);
24
- }
18
+ if (!themeDir) {
19
+ return marp;
20
+ }
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
+ }
27
+
28
+ if(!stats.isDirectory()) {
29
+ console.warn(`Theme directory "${themeDir}" is not a directory.`);
30
+ return marp;
31
+ }
32
+
33
+ console.log("Loading themes from:", themeDir);
34
+
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);
25
40
  }
26
41
  }
42
+
27
43
  return marp;
28
44
  }
29
45