-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4c62124
Showing
12 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/biome.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-build | ||
cancel-in-progress: true | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
- run: bun install | ||
- uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: docker/setup-buildx-action@v3 | ||
- uses: docker/metadata-action@v5 | ||
id: meta | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=sha,format=short,prefix=,priority=100 | ||
type=raw,value=latest,priority=200 | ||
- uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
provenance: true | ||
no-cache: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: lint | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-lint | ||
cancel-in-progress: true | ||
jobs: | ||
actionlint: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: reviewdog/action-actionlint@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
reporter: github-pr-review | ||
javascript: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
- run: bun install | ||
- uses: biomejs/setup-biome@v2 | ||
- run: biome ci . | ||
typos: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: crate-ci/typos@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: test | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-test | ||
cancel-in-progress: true | ||
jobs: | ||
javascript: | ||
timeout-minutes: 30 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
- run: bun install | ||
- run: bun test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM oven/bun:latest | ||
COPY . . | ||
ENTRYPOINT ["bun", "./index.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# lexical-server | ||
|
||
リッチテキストエディタの[lexical](https://lexical.dev/)形式に合わせたHTML/JSON/Markdownを相互に変換できるサーバです。 | ||
|
||
## 仕組み | ||
lexicalは`@lexical/headless`パッケージを提供しており、フロントエンドの環境がなくともheadlessエディタ内で操作をすることができます。 | ||
例えば`/html_to_json`エンドポイントはlexical形式のHTMLをリクエストボディに受け取り、headlessエディタに取り込んだあとJSON形式で吐き出したものをレスポンスとして返却します。 | ||
|
||
## 起動方法 | ||
|
||
パッケージマネージャおよびランタイムに[bun](https://bun.sh/)を利用しています。 | ||
`bun install`で依存パッケージをインストールしたのち、`bun run`で起動させます。 | ||
|
||
```shell | ||
bun install | ||
``` | ||
|
||
```shell | ||
bun run --hot index.ts | ||
``` | ||
|
||
## 注意点 | ||
|
||
HTMLをパースするパッケージであるJSDOMがNode.js依存が強い(fsとか)パッケージであるためCloudflare Workersやdenoなどの互換ランタイム上ではうまく動作しません。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", | ||
"files": { | ||
"ignore": ["node_modules"], | ||
"ignoreUnknown": true | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space" | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"complexity": { | ||
"noBannedTypes": "off" | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createHeadlessEditor } from "@lexical/headless"; | ||
import { $generateNodesFromDOM } from "@lexical/html"; | ||
import { Hono } from "hono"; | ||
import { logger } from "hono/logger"; | ||
import { JSDOM } from "jsdom"; | ||
import { $getRoot, $getSelection } from "lexical"; | ||
|
||
export const runtime = "edge"; | ||
|
||
const app = new Hono(); | ||
app.use(logger()); | ||
|
||
app.get("/healthcheck", (c) => c.text("ok")); | ||
app.post("/html_to_json", async (c) => { | ||
const body = await c.req.text(); | ||
|
||
const editor = createHeadlessEditor({ | ||
nodes: [], | ||
onError: (e) => { | ||
console.error(e); | ||
}, | ||
}); | ||
await editor.update(() => { | ||
const dom = new JSDOM(body); | ||
const nodes = $generateNodesFromDOM(editor, dom.window.document); | ||
$getRoot().select(); | ||
const selection = $getSelection(); | ||
selection?.insertNodes(nodes); | ||
}); | ||
|
||
return c.json(editor.getEditorState().toJSON()); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "lexical-server", | ||
"module": "index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"@biomejs/biome": "1.6.1", | ||
"@types/bun": "latest" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/headless": "0.14.2", | ||
"@lexical/html": "0.14.2", | ||
"hono": "4.1.3", | ||
"jsdom": "24.0.0", | ||
"lexical": "0.14.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
// Enable latest features | ||
"lib": ["ESNext"], | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleDetection": "force", | ||
"jsx": "react-jsx", | ||
"allowJs": true, | ||
|
||
// Bundler mode | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"verbatimModuleSyntax": true, | ||
"noEmit": true, | ||
|
||
// Best practices | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
// Some stricter flags (disabled by default) | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noPropertyAccessFromIndexSignature": false | ||
} | ||
} |