svelte-preprocess-org 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/.editorconfig +15 -0
- package/.eslintrc.cjs +25 -0
- package/.gitmodules +3 -0
- package/.prettierrc.cjs +3 -0
- package/README.md +11 -0
- package/dist/emacs.d.ts +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/lisp/convert.el +86 -0
- package/dist/lisp/kono_subarashii_kuromajutsu_ni_shukufuku_o_part_2.org +537 -0
- package/dist/lisp/ox-svelte/LICENSE +674 -0
- package/dist/lisp/ox-svelte/README.org +3 -0
- package/dist/lisp/ox-svelte/ox-svelte.el +297 -0
- package/package.json +39 -0
- package/rollup.config.js +22 -0
- package/src/emacs.ts +46 -0
- package/src/index.ts +29 -0
- package/src/lisp/convert.el +86 -0
- package/src/lisp/ox-svelte/LICENSE +674 -0
- package/src/lisp/ox-svelte/README.org +3 -0
- package/src/lisp/ox-svelte/ox-svelte.el +297 -0
- package/tsconfig.json +9 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This is the top-level editorconfig
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
# General file conventions
|
|
5
|
+
charset = utf-8
|
|
6
|
+
trim_trailing_whitespace = true
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
max_line_length = 120
|
|
10
|
+
|
|
11
|
+
# JavaScript and TypeScript files
|
|
12
|
+
[*.{js,cjs,mjs,ts,cts,mts}]
|
|
13
|
+
indent_style = space
|
|
14
|
+
indent_size = 2
|
|
15
|
+
|
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
es2021: true,
|
|
4
|
+
node: true,
|
|
5
|
+
},
|
|
6
|
+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
env: {
|
|
10
|
+
node: true,
|
|
11
|
+
},
|
|
12
|
+
files: [".eslintrc.{js,cjs}"],
|
|
13
|
+
parserOptions: {
|
|
14
|
+
sourceType: "script",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
parser: "@typescript-eslint/parser",
|
|
19
|
+
parserOptions: {
|
|
20
|
+
ecmaVersion: "latest",
|
|
21
|
+
sourceType: "module",
|
|
22
|
+
},
|
|
23
|
+
plugins: ["@typescript-eslint"],
|
|
24
|
+
rules: {},
|
|
25
|
+
};
|
package/.gitmodules
ADDED
package/.prettierrc.cjs
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Svelte Preprocessor for Org-mode Documents
|
|
2
|
+
|
|
3
|
+
[Svelte](https://svelte.dev/) preprocessor to import [Org mode](https://orgmode.org)
|
|
4
|
+
documents as a component, powered by [ox-svelte](https://github.com/RangHo/ox-svelte).
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
This package deliberately refrains from parsing Org mode documents.
|
|
9
|
+
These processes are delegated to an actual instance of Emacs.
|
|
10
|
+
|
|
11
|
+
Therefore, you need **Emacs 29** or newer installed on your system.
|
package/dist/emacs.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { PreprocessorGroup } from "svelte/compiler";
|
|
3
|
+
import { type OxSvelteOptions } from "./emacs.js";
|
|
4
|
+
export interface OrgPreprocessorOptions extends OxSvelteOptions {
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function orgPreprocess(options?: OrgPreprocessorOptions): PreprocessorGroup;
|
|
8
|
+
export default orgPreprocess;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execSync as t}from"node:child_process";import{join as e}from"node:path";function r(r,o){const{latexEnvironmentFormat:n,latexFragmentFormat:m,srcBlockFormat:a,imports:i}=o||{};let s=`/usr/bin/env emacs --script ${e(import.meta.dirname,"lisp","convert.el")}`;var c;return n&&(s+=` --latex-environment-format ${n}`),m&&(s+=` --latex-fragment-format ${m}`),a&&(s+=` --src-block-format ${a}`),i&&(s+=` --preface "(setq og-svelte-component-import-alist ${c=i,`'(${Object.entries(c).map((([t,e])=>`("${t}" . "${e}")`))})`})"`),t(s,{input:r}).toString()}function o(t){const{extensions:e=[".org"],...o}=t||{};return{markup({content:t,filename:n}){if(n&&!e.some((t=>n.endsWith(t))))return{code:t};return{code:r(t,o)}}}}export{o as default,o as orgPreprocess};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
;;; convert.el --- Read Org-mode files from stdin and write Svelte components to stdout.
|
|
2
|
+
|
|
3
|
+
;; Author: RangHo Lee <hello@rangho.me>
|
|
4
|
+
|
|
5
|
+
;;; Commentary:
|
|
6
|
+
|
|
7
|
+
;; This script accepts the content of an Org-mode file from stdin, converts it
|
|
8
|
+
;; to a Svelte component, and writes the result to stdout. This is an Emacs
|
|
9
|
+
;; Lisp script; that is, it needs to be run with Emacs in batch mode.
|
|
10
|
+
;;
|
|
11
|
+
;; It uses `ox-svelte' to perform the conversion. Make sure that `ox-svelte'
|
|
12
|
+
;; repository is checked out in the same directory, preferably as a git
|
|
13
|
+
;; submodule.
|
|
14
|
+
;;
|
|
15
|
+
;; This script accepts the following command line arguments:
|
|
16
|
+
;; --preface <elisp-code>
|
|
17
|
+
;; Evaluate the given Elisp code before processing.
|
|
18
|
+
;; --latex-environment-format <format>
|
|
19
|
+
;; Set the format of LaTeX environment to <format>. The format string
|
|
20
|
+
;; should contain a single `%s' with which the LaTeX environment content
|
|
21
|
+
;; will be replaced as a JavaScript raw string.
|
|
22
|
+
;; --latex-fragment-format <format>
|
|
23
|
+
;; Set the format of LaTeX fragment to <format>. The format string
|
|
24
|
+
;; should contain a single `%s' with which the LaTeX fragment content
|
|
25
|
+
;; will be replaced as a JavaScript raw string.
|
|
26
|
+
;; --src-block-format <format>
|
|
27
|
+
;; Set the format of source block to <format>. The format string should
|
|
28
|
+
;; contain two `%s' with which the language and the content of the src
|
|
29
|
+
;; block will be replaced as a JavaScript raw string.
|
|
30
|
+
;;
|
|
31
|
+
;; To allow more smooth preprocessor chaning, this script sets some arbitrary
|
|
32
|
+
;; options to Org-mode exporter engine. You can customize the behavior of the
|
|
33
|
+
;; exporter by setting command line arguments, or by providing preface S-exps.
|
|
34
|
+
|
|
35
|
+
;;; Code:
|
|
36
|
+
|
|
37
|
+
(require 'ox-svelte
|
|
38
|
+
(expand-file-name "ox-svelte/ox-svelte.el"
|
|
39
|
+
(file-name-directory load-file-name)))
|
|
40
|
+
|
|
41
|
+
;; Set default settings
|
|
42
|
+
(setq org-export-with-section-numbers nil)
|
|
43
|
+
|
|
44
|
+
;; Process command line arguments
|
|
45
|
+
(let ((i 0))
|
|
46
|
+
(while (elt argv i)
|
|
47
|
+
(cond
|
|
48
|
+
;; Evaluate the preface S-exp if provided
|
|
49
|
+
((string= (elt argv i) "--preface")
|
|
50
|
+
(eval (car (read-from-string (elt argv (1+ i)))))
|
|
51
|
+
(setq i (1+ i)))
|
|
52
|
+
|
|
53
|
+
;; Set the LaTeX environment format
|
|
54
|
+
((string= (elt argv i) "--latex-environment-format")
|
|
55
|
+
(setq org-svelte-latex-environment-format (elt argv (1+ i)))
|
|
56
|
+
(setq i (1+ i)))
|
|
57
|
+
|
|
58
|
+
;; Set the LaTeX fragment format
|
|
59
|
+
((string= (elt argv i) "--latex-fragment-format")
|
|
60
|
+
(setq org-svelte-latex-fragment-format (elt argv (1+ i)))
|
|
61
|
+
(setq i (1+ i)))
|
|
62
|
+
|
|
63
|
+
;; Set the source block format
|
|
64
|
+
((string= (elt argv i) "--src-block-format")
|
|
65
|
+
(setq org-svelte-src-block-format (elt argv (1+ i)))
|
|
66
|
+
(setq i (1+ i)))
|
|
67
|
+
|
|
68
|
+
;; No match found, warn the user and do nothing
|
|
69
|
+
(t
|
|
70
|
+
(warn (format "Unsupported argument: %s" (elt argv i)))))
|
|
71
|
+
|
|
72
|
+
(setq i (1+ i))))
|
|
73
|
+
|
|
74
|
+
;; Read the content of the Org-mode file from stdin and convert
|
|
75
|
+
(with-temp-buffer
|
|
76
|
+
(while (condition-case err
|
|
77
|
+
(setq line (read-from-minibuffer ""))
|
|
78
|
+
(error nil))
|
|
79
|
+
(insert line "\n"))
|
|
80
|
+
(org-svelte-export-as-svelte)
|
|
81
|
+
(princ (buffer-string)))
|
|
82
|
+
|
|
83
|
+
;; Exit Emacs after conversion to prevent unnecessary errors
|
|
84
|
+
(kill-emacs 0)
|
|
85
|
+
|
|
86
|
+
;;; convert.el ends here
|