vite-plugin-norg 0.1.0 → 1.0.0

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 CHANGED
@@ -1,26 +1,178 @@
1
1
  # vite-plugin-norg
2
2
 
3
- A Vite plugin that enables importing and processing `.norg` files (Neorg markup format) in your Vite projects with support for HTML, Svelte, and React output targets.
3
+ [![npm version](https://img.shields.io/npm/v/vite-plugin-norg.svg)](https://www.npmjs.com/package/vite-plugin-norg)
4
+ [![build status](https://img.shields.io/github/actions/workflow/status/bottd/vite-plugin-norg/ci.yml?branch=main)](https://github.com/bottd/vite-plugin-norg/actions)
5
+ [![typescript](https://img.shields.io/badge/TypeScript-blue.svg)](https://www.typescriptlang.org/)
6
+ [![license](https://img.shields.io/npm/l/vite-plugin-norg.svg)](LICENSE)
4
7
 
5
- - Built on top of the [rust-norg](https://github.com/nvim-neorg/rust-norg) parser
8
+ **Neorg processor for Vite** - Transform `.norg` files into HTML, React, or Svelte with full TypeScript support.
9
+
10
+ > **Built for [Neorg](https://github.com/nvim-neorg/neorg) users, powered by [rust-norg](https://github.com/nvim-neorg/rust-norg)**
6
11
 
7
12
  ## Installation
8
13
 
9
14
  ```bash
10
- npm install vite-plugin-norg
15
+ npm install -D vite-plugin-norg
11
16
  ```
12
17
 
13
- ## Usage
14
-
15
- ### Basic Setup
18
+ ## Quick Setup
16
19
 
17
- Add the plugin to your `vite.config.js`:
20
+ ### HTML Output
18
21
 
19
- ```js
22
+ ```javascript
20
23
  import { norgPlugin } from 'vite-plugin-norg';
21
24
  import { defineConfig } from 'vite';
22
25
 
23
26
  export default defineConfig({
24
- plugins: [norgPlugin({ mode: 'html', include: ['/**/*.norg'] })],
27
+ plugins: [
28
+ norgPlugin({
29
+ mode: 'html',
30
+ include: ['**/*.norg'],
31
+ }),
32
+ ],
33
+ });
34
+ ```
35
+
36
+ ```javascript
37
+ import { metadata, html } from './document.norg';
38
+ console.log(metadata.title); // "My Document"
39
+ document.body.innerHTML = html;
40
+ ```
41
+
42
+ ### React Components
43
+
44
+ ```javascript
45
+ export default defineConfig({
46
+ plugins: [
47
+ norgPlugin({
48
+ mode: 'react',
49
+ include: ['**/*.norg'],
50
+ }),
51
+ ],
52
+ });
53
+ ```
54
+
55
+ ```jsx
56
+ import { metadata, Component } from './document.norg';
57
+
58
+ export default function App() {
59
+ return (
60
+ <div>
61
+ <h1>{metadata.title}</h1>
62
+ <Component />
63
+ </div>
64
+ );
65
+ }
66
+ ```
67
+
68
+ ### Svelte Components
69
+
70
+ ```javascript
71
+ export default defineConfig({
72
+ plugins: [
73
+ norgPlugin({
74
+ mode: 'svelte',
75
+ include: ['**/*.norg'],
76
+ }),
77
+ ],
25
78
  });
26
79
  ```
80
+
81
+ ```svelte
82
+ <script>
83
+ import Document, { metadata } from './document.norg';
84
+ </script>
85
+
86
+ <h1>{metadata.title}</h1>
87
+ <Document />
88
+ ```
89
+
90
+ ## Architecture
91
+
92
+ ```mermaid
93
+ graph LR
94
+ A(📝 .norg files) ==> B(⚡ Rust Parser)
95
+ B ==> C(🔧 WASM Module)
96
+ C ==> D(🚀 Vite Plugin)
97
+ D ==> E{🎨 Generator}
98
+ E ==> F(📄 HTML)
99
+ E ==> G(⚛️ React)
100
+ E ==> H(🔥 Svelte)
101
+ F ==> I(💎 TypeScript Module)
102
+
103
+ linkStyle default stroke-width:3px
104
+ ```
105
+
106
+ Built with:
107
+
108
+ - **[rust-norg](https://github.com/nvim-neorg/rust-norg)** compiled to WASM for robust parsing
109
+ - **[vite-plugin-wasm](https://github.com/Menci/vite-plugin-wasm)** to load Rust HTML transformer
110
+ - **TypeScript** for the sanity of all involved
111
+ - **Vite integration** with HMR support
112
+
113
+ ## Plugin API Reference
114
+
115
+ ```typescript
116
+ import type { FilterPattern } from 'vite';
117
+
118
+ interface NorgPluginOptions {
119
+ mode: 'html' | 'react' | 'svelte';
120
+ include?: FilterPattern;
121
+ exclude?: FilterPattern;
122
+ }
123
+ ```
124
+
125
+ **Requirements:**
126
+
127
+ - Vite 7.0+
128
+ - Node.js 20+
129
+
130
+ ## Development
131
+
132
+ This project uses Nix flakes and direnv for reproducible development environments.
133
+
134
+ ### Setup
135
+
136
+ ```bash
137
+ # Install direnv (if not already installed)
138
+ curl -sfL https://direnv.net/install.sh | bash
139
+
140
+ # Enable direnv for this project
141
+ direnv allow
142
+
143
+ # Build the project
144
+ npm run build
145
+ ```
146
+
147
+ ### Development Workflow
148
+
149
+ ```bash
150
+ npm run build
151
+
152
+ # Run tests
153
+ npm test
154
+
155
+ # Lint code
156
+ npm run lint
157
+
158
+ # Format code
159
+ nix fmt
160
+ ```
161
+
162
+ ### Nix Flake
163
+
164
+ The `flake.nix` provides:
165
+
166
+ - Rust toolchain with [wasm-pack](https://github.com/rustwasm/wasm-pack)
167
+ - Node.js and npm
168
+ - Development tools and dependencies
169
+
170
+ To enter the development shell if not using direnv:
171
+
172
+ ```bash
173
+ nix develop
174
+ ```
175
+
176
+ ## Contributing
177
+
178
+ PRs and issues welcome! To open a PR please fork and ensure tests and linters pass.
@@ -1,5 +1,7 @@
1
1
  import { norgPlugin } from './plugin';
2
2
  import { NorgMetadata } from './wasm';
3
+ import { SvelteComponent } from 'svelte';
4
+ import { FC } from 'react';
3
5
  export { norgPlugin } from './plugin';
4
6
  export type { NorgMetadata, NorgParseResult, TocEntry } from './wasm';
5
7
  export default norgPlugin;
@@ -15,18 +17,12 @@ export interface HtmlModule {
15
17
  */
16
18
  export interface ReactModule {
17
19
  metadata: NorgMetadata;
18
- Component: () => unknown;
20
+ Component: FC;
19
21
  }
20
22
  /**
21
23
  * Module type for .norg files processed by the Svelte generator
22
24
  */
23
25
  export interface SvelteModule {
24
26
  metadata: NorgMetadata;
25
- default: new (options: {
26
- target: unknown;
27
- props?: Record<string, unknown>;
28
- }) => {
29
- $destroy(): void;
30
- $set(props: Record<string, unknown>): void;
31
- };
27
+ default: typeof SvelteComponent;
32
28
  }