Installation
Requirements
- PHP 8.4 or later with
ext-dom. 8.4 is required for its native HTML5 parser: the server-side sanitiser reads HTML with the same rules browsers do. - Laravel 12 or 13 for the Laravel integration (Blade components, cast, service provider). The editor itself and the sanitiser do not need Laravel.
ext-gdfor image uploads (see Image uploads). Not needed if you switch uploads off.
Install the package
composer require 2bo-velocity/ohashirichtexteditor
php artisan vendor:publish --tag=ohashi-editor-assets
The second command copies the prebuilt editor (a single JavaScript file) to
public/vendor/ohashi-editor/. Run it again after updating the package.
To change the defaults, publish the configuration file as well:
php artisan vendor:publish --tag=ohashi-editor-config
Blade
<script type="module" src="{{ asset('vendor/ohashi-editor/ohashi-editor.js') }}"></script>
<form method="POST" action="{{ route('posts.store') }}">
@csrf
<x-ohashi-editor name="body" :value="old('body', $post->body)" label="Article body" />
<button type="submit">Save</button>
</form>
The element takes part in the form like a <textarea>: it is submitted under
its name.
| Attribute | Meaning |
|---|---|
name | Field name used when the form is submitted |
value | Initial HTML. It is cleaned before it is shown (see Security) |
label | Accessible name of the editing area, read by screen readers. Default: "Rich text editor" |
Then save and display the HTML safely.
Inertia (Vue 3 / React)
The JavaScript is installed from the Composer package itself, so the editor and
the server-side code are always the same version. Run composer install
before npm install — in CI and Docker builds too.
npm install ./vendor/2bo-velocity/ohashirichtexteditor
Vue 3
<script setup>
import { useForm } from '@inertiajs/vue3'
import { OhashiEditor } from '@2bo-velocity/ohashirichtexteditor/vue'
const form = useForm({ body: '' })
</script>
<template>
<form @submit.prevent="form.post('/posts')">
<OhashiEditor v-model="form.body" name="body" />
<button type="submit">Save</button>
</form>
</template>
React
import { useForm } from '@inertiajs/react'
import { OhashiEditor } from '@2bo-velocity/ohashirichtexteditor/react'
export default function Create() {
const { data, setData, post } = useForm({ body: '' })
return (
<form onSubmit={(e) => { e.preventDefault(); post('/posts') }}>
<OhashiEditor value={data.body} onChange={(html) => setData('body', html)} name="body" />
<button type="submit">Save</button>
</form>
)
}
The wrappers load the editor for you and can be imported under Inertia's server-side rendering.
Livewire
Put wire:model on the Blade component. Livewire 3.8.3+ and 4 are supported.
<x-ohashi-editor wire:model="body" label="Article body" />
class EditPost extends Component
{
public string $body = '';
public function save(): void
{
$this->validate(['body' => 'required|max:65535']);
$this->post->update(['body' => $this->body]); // sanitised by the SanitizedHtml cast
}
}
- Every change reaches the property — typing, toolbar buttons, undo, paste and uploads — as the editor's normalised HTML.
wire:model.live,.blurand.changework as for any input. With.live, answers from the server do not overwrite what was typed meanwhile, and a round trip in the middle of an IME composition does not break it (checked in Chromium, where IME input can be automated).- Setting the property on the server (
$this->body = '…') replaces the content. - Re-renders of the component and
wire:navigateleave the editor intact; nowire:ignoreis needed. - Save through the
SanitizedHtmlcast as with a normal form: a Livewire property is user input too (see Saving and displaying safely).
These are checked in Chromium, Firefox and WebKit against a real Livewire server, for both Livewire 3 and 4.