Skip to content

API ​

ts
type WritingMode = 'horizontal-tb' | 'vertical-rl' | 'vertical-lr';

interface VerticalWritingOptions {
  mode?: WritingMode;
  lineLength?: number;
}

verticalWriting(options) ​

Registers the layout plugin with Milkdown. It returns a Milkdown plugin array, so pass it directly to editor.use.

ts
editor.use(verticalWriting({
  mode: 'vertical-rl',
  lineLength: 40,
}));
OptionTypeDefaultMeaning
modeWritingModehorizontal-tbThe initial CSS writing mode.
lineLengthpositive integerunrestrictedMaximum advance per line in full-width ideographic character units.

lineLength uses rendered advance, not a character counter. Line-breaking rules can move punctuation around the nominal boundary, and Latin text or inline nodes do not each equal one full-width character. Omit lineLength to remove the limit.

The package CSS must be imported explicitly:

ts
import '@illusions-lab/milkdown-plugin-vertical-writing/style.css';

changeWritingMode(mode) ​

Returns an action that changes the writing mode without rebuilding the editor.

ts
editor.action(changeWritingMode('horizontal-tb'));
editor.action(changeWritingMode('vertical-rl'));
editor.action(changeWritingMode('vertical-lr'));

The change keeps the document, selection, and undo history. The plugin preserves logical scroll progress across the new layout.

changeLineLength(number | null) ​

Returns an action that updates the maximum line length. Pass a positive integer to set a limit, or null to remove it.

ts
editor.action(changeLineLength(40));
editor.action(changeLineLength(null));

With a line length enabled, images are constrained only with max-inline-size. An image is not forced to a new size and its intrinsic aspect ratio is preserved.

WritingMode ​

The exported WritingMode type has exactly three legal values:

ValueLayout
horizontal-tbHorizontal lines, top to bottom.
vertical-rlVertical lines, progressing right to left.
vertical-lrVertical lines, progressing left to right.

Invalid modes and non-positive or non-integer line lengths throw a TypeError when the plugin or action is created.

Live demo ​

Use the controls to invoke the same writing-mode and line-length behaviour described above:

Released under the MIT License.