ITADN

feat: render field descriptions as markdown

#465Pull Requestdanielo515 创建于 2026-04-23
D
danielo515commented
## Summary Field descriptions now render as markdown. Authors can drop links, wikilinks, bold/italic, and inline code into a description to point users at docs, format syntax references, or explain tricky inputs — the capability requested in #376. Before, the description text was rendered as a plain string. Now it flows through Obsidian's `MarkdownRenderer`, so e.g. this description… ``` See the [Luxon format](https://moment.github.io/luxon/#/formatting) for supported tokens. Keep it **short** — e.g. `yyyy-MM-dd`. ``` …renders as a proper clickable link, bolded text, and code span inline with the field. ## Changes - **New** `src/views/components/Form/MarkdownDescription.svelte` — small component that renders a markdown string into a `setting-item-description` div using `MarkdownRenderer.render`. It owns an Obsidian `Component` and unloads it in `onDestroy`, so event handlers on rendered content (e.g. internal link clicks) are cleaned up with the form modal. - `ObsidianInputWrapper.svelte` accepts an optional `app` prop. When present **and** the description is non-empty, it renders markdown via `MarkdownDescription`; otherwise it falls back to the existing plain-text rendering. - `useObsidianSetting.ts` (used by `toggle` and `folder`) accepts an optional `app` and renders markdown into the `Setting.descEl` when present, returning a `destroy` hook so the backing `Component` is unloaded with the element. - `RenderField.svelte` plumbs `app` through all `ObsidianInputWrapper` usages, plus into `ObsidianToggle` and `InputTextArea`. - `InputNote`, `InputDataview`, `ObsidianSelect`, `InputTextArea`, `InputFolder`, `ObsidianToggle` now pass `app` along to the wrapper / setting helper. - `styles.css` zeroes the margin on rendered `<p>` elements inside `.setting-item-description` so the description lays out identically to a plain string (Obsidian's markdown output wraps short text in a `<p>`). When `app` is `undefined` (defensive fallback), rendering falls back to the previous plain-text behaviour, so nothing breaks if a wrapper is instantiated in isolation. ## Test plan - [x] `npm run check` (lint + svelte-check) — passes, only pre-existing warnings - [x] `npm run test` — all 159 tests pass, 2 pre-existing skipped - [x] `npm run build` (lint + svelte-check + esbuild production bundle) — passes, only pre-existing warnings - [ ] Preview URL: open a form with a field whose description contains a link like `[docs](https://example.com)`, **bold**, or `` `code` ``, and confirm the rendered form shows clickable/styled markup beneath the field label - [ ] Confirm a `toggle` or `folder` field with a markdown description also renders the markup (not only wrapper-based fields) Closes #376 --- _Generated by [Claude Code](https://claude.ai/code/session_01P5UW1b6yKZtQ5BNZQYeXmj)_
合并状态:未合并 1 条评论