Color mode

Search notes

Filter with tag:, lang:, or path:.

Hard Breaks

Render ordinary Markdown line breaks as <br> elements, matching Obsidian's behavior when "Strict line breaks" is turned off.

日本語

Overview

In standard Markdown, a single newline inside a paragraph is a soft break: it is rendered as a space. hardBreaks() registers the remark-breaks transformer on the Riebeckite Markdown pipeline so every soft break becomes a <br> element at build time.

The conversion happens on the Markdown AST before the tree is converted to HTML, so code blocks, inline code, and explicit hard breaks keep their meaning. The plugin adds no client JavaScript and no CSS.

Installation

ts
import { defineConfig } from "@riebeckite/core";
import { hardBreaks } from "@riebeckite/plugin-hard-breaks";
 
export default defineConfig({
  // ...
  plugins: [hardBreaks()],
});

Add hardBreaks() to the plugins array of riebeckite.config.ts. The plugin is opt-in: without this entry, the pipeline keeps the standard Markdown soft break behavior.

Usage

ts
import { hardBreaks } from "@riebeckite/plugin-hard-breaks";
 
hardBreaks();

The factory takes no options.

Before and after

Input:

md
今日はいい天気です。
散歩に行きました。
明日も晴れるといいな。

Without the plugin (standard Markdown), the three lines render on one line. With hardBreaks():

html
<p>今日はいい天気です。<br>
散歩に行きました。<br>
明日も晴れるといいな。</p>

Behavior

Input Result
A single newline inside a paragraph Becomes a <br>
A blank line between paragraphs Still splits paragraphs
A fenced code block Unchanged
Inline code Unchanged
Headings Keep their Markdown heading structure
Line breaks in list items Handled by the Markdown AST structure
Line breaks in blockquotes Treated like ordinary paragraphs
An explicit hard break (two trailing spaces or \) Not converted twice
Raw HTML in Markdown Left as-is

Limitations

  • The plugin converts soft breaks only. It does not change how blank lines, lists, or code blocks are parsed.
  • The result is decided at build time; rebuild the site after changing the plugin list.

Obsidian relationship

Obsidian has a setting called "Strict line breaks". When it is off, a single newline is shown as a line break. This plugin brings that same behavior to Riebeckite's rendered pages.

Exports

  • hardBreaks() — plugin factory
  • hardBreaksPlugin — alias of hardBreaks

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/hard-breaks/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Hard Breaks
4 +
5 + Render ordinary Markdown line breaks as `<br>` elements, matching Obsidian's
6 + behavior when "Strict line breaks" is turned off.
7 +
8 + [日本語](./hard-breaks.ja.md)
9 +
10 + ## Overview
11 +
12 + In standard Markdown, a single newline inside a paragraph is a soft break: it
13 + is rendered as a space. `hardBreaks()` registers the
14 + [`remark-breaks`](https://github.com/remarkjs/remark-breaks) transformer on the
15 + Riebeckite Markdown pipeline so every soft break becomes a `<br>` element at
16 + build time.
17 +
18 + The conversion happens on the Markdown AST before the tree is converted to
19 + HTML, so code blocks, inline code, and explicit hard breaks keep their meaning.
20 + The plugin adds no client JavaScript and no CSS.
21 +
22 + ## Installation
23 +
24 + ```ts
25 + import { defineConfig } from "@riebeckite/core";
26 + import { hardBreaks } from "@riebeckite/plugin-hard-breaks";
27 +
28 + export default defineConfig({
29 + // ...
30 + plugins: [hardBreaks()],
31 + });
32 + ```
33 +
34 + Add `hardBreaks()` to the `plugins` array of `riebeckite.config.ts`. The plugin
35 + is opt-in: without this entry, the pipeline keeps the standard Markdown soft
36 + break behavior.
37 +
38 + ## Usage
39 +
40 + ```ts
41 + import { hardBreaks } from "@riebeckite/plugin-hard-breaks";
42 +
43 + hardBreaks();
44 + ```
45 +
46 + The factory takes no options.
47 +
48 + ## Before and after
49 +
50 + Input:
51 +
52 + ```md
53 + 今日はいい天気です。
54 + 散歩に行きました。
55 + 明日も晴れるといいな。
56 + ```
57 +
58 + Without the plugin (standard Markdown), the three lines render on one line.
59 + With `hardBreaks()`:
60 +
61 + ```html
62 + <p>今日はいい天気です。<br>
63 + 散歩に行きました。<br>
64 + 明日も晴れるといいな。</p>
65 + ```
66 +
67 + ## Behavior
68 +
69 + | Input | Result |
70 + | --- | --- |
71 + | A single newline inside a paragraph | Becomes a `<br>` |
72 + | A blank line between paragraphs | Still splits paragraphs |
73 + | A fenced code block | Unchanged |
74 + | Inline code | Unchanged |
75 + | Headings | Keep their Markdown heading structure |
76 + | Line breaks in list items | Handled by the Markdown AST structure |
77 + | Line breaks in blockquotes | Treated like ordinary paragraphs |
78 + | An explicit hard break (two trailing spaces or `\`) | Not converted twice |
79 + | Raw HTML in Markdown | Left as-is |
80 +
81 + ## Limitations
82 +
83 + - The plugin converts soft breaks only. It does not change how blank lines,
84 + lists, or code blocks are parsed.
85 + - The result is decided at build time; rebuild the site after changing the
86 + plugin list.
87 +
88 + ## Obsidian relationship
89 +
90 + Obsidian has a setting called "Strict line breaks". When it is off, a single
91 + newline is shown as a line break. This plugin brings that same behavior to
92 + Riebeckite's rendered pages.
93 +
94 + ## Exports
95 +
96 + - `hardBreaks()` — plugin factory
97 + - `hardBreaksPlugin` — alias of `hardBreaks`
98 +
99 + ## See also
100 +
101 + - [Plugin guide](../reference/plugin-api.md)
102 +