ippon-slides 0.1.0 → 0.1.1
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 +13 -0
- package/assets/deck.js +187 -201
- package/bin/ippon.js +1 -1
- package/dist/cli.d.ts +20 -0
- package/dist/cli.js +236 -0
- package/dist/highlight.d.ts +2 -0
- package/dist/highlight.js +105 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/markdown.d.ts +15 -0
- package/dist/markdown.js +219 -0
- package/dist/pdf.d.ts +11 -0
- package/dist/pdf.js +83 -0
- package/dist/render.d.ts +14 -0
- package/dist/render.js +51 -0
- package/package.json +15 -4
- package/src/cli.js +0 -236
- package/src/highlight.js +0 -113
- package/src/index.js +0 -3
- package/src/markdown.js +0 -232
- package/src/pdf.js +0 -89
- package/src/render.js +0 -64
package/src/render.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// スライドの HTML を 1 ファイルに組み立てる(CSS / JS も全部埋め込む)
|
|
2
|
-
|
|
3
|
-
import { readFileSync } from 'node:fs'
|
|
4
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
-
import { esc } from './highlight.js'
|
|
7
|
-
import { parse } from './markdown.js'
|
|
8
|
-
|
|
9
|
-
const assets = join(dirname(fileURLToPath(import.meta.url)), '..', 'assets')
|
|
10
|
-
|
|
11
|
-
const EXTERNAL = /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 相対パスの画像を、出力先から見たパスに書き換える。
|
|
15
|
-
* - outDir を渡す → 出力先からの相対パス(HTML 用)
|
|
16
|
-
* - outDir なし → file:// の絶対 URL(PDF の一時ファイル用)
|
|
17
|
-
*/
|
|
18
|
-
function rewriteImages(html, baseDir, outDir) {
|
|
19
|
-
return html.replace(/(<img src=")([^"]+)(")/g, (all, pre, src, post) => {
|
|
20
|
-
if (EXTERNAL.test(src) || isAbsolute(src)) return all
|
|
21
|
-
const abs = resolve(baseDir, decodeURI(src))
|
|
22
|
-
const url = outDir ? encodeURI(relative(outDir, abs).split(sep).join('/')) : pathToFileURL(abs).href
|
|
23
|
-
return pre + url + post
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} md Markdown
|
|
29
|
-
* @param {object} opts
|
|
30
|
-
* @param {string} opts.baseDir 画像の相対パスの基準(= Markdown のあるディレクトリ)
|
|
31
|
-
* @param {string} [opts.outDir] 出力先ディレクトリ。省略すると画像は file:// URL になる
|
|
32
|
-
* @param {string} [opts.css] 追加の CSS(--css)
|
|
33
|
-
* @returns {{ html: string, count: number }}
|
|
34
|
-
*/
|
|
35
|
-
export function render(md, { baseDir, outDir, css = '' }) {
|
|
36
|
-
const { meta, sections } = parse(md)
|
|
37
|
-
const style = readFileSync(join(assets, 'style.css'), 'utf8') + (css ? `\n/* --css */\n${css}` : '')
|
|
38
|
-
const script = readFileSync(join(assets, 'deck.js'), 'utf8')
|
|
39
|
-
const body = rewriteImages(sections.join('\n'), baseDir, outDir)
|
|
40
|
-
|
|
41
|
-
const html = `<!doctype html>
|
|
42
|
-
<html lang="${esc(meta.lang || 'ja')}">
|
|
43
|
-
<head>
|
|
44
|
-
<meta charset="utf-8">
|
|
45
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
46
|
-
<title>${esc(meta.title || 'slides')}</title>
|
|
47
|
-
${meta.description ? `<meta name="description" content="${esc(meta.description)}">\n` : ''}${meta.author ? `<meta name="author" content="${esc(meta.author)}">\n` : ''}<meta name="generator" content="ippon-slides">
|
|
48
|
-
<style>${style}</style>
|
|
49
|
-
</head>
|
|
50
|
-
<body>
|
|
51
|
-
<div id="deck">
|
|
52
|
-
${body}
|
|
53
|
-
</div>
|
|
54
|
-
<div id="overview"></div>
|
|
55
|
-
<div id="progress"></div>
|
|
56
|
-
<div id="timer"></div>
|
|
57
|
-
<div id="counter"></div>
|
|
58
|
-
<div id="hint">← → 移動 ・ f フルスクリーン ・ o 一覧</div>
|
|
59
|
-
<script>${script}</script>
|
|
60
|
-
</body>
|
|
61
|
-
</html>
|
|
62
|
-
`
|
|
63
|
-
return { html, count: sections.length }
|
|
64
|
-
}
|