Code blocks
Code blocks provide monospace source editing with language-aware syntax highlighting, JetBrains Mono typography by default, copy support, and configurable presentation themes.
- Included in:
notesConfiguration,documentConfiguration - Pure-Dart import:
package:vyuh_document_elements/code.dartorpackage:vyuh_document_elements/vyuh_document_elements.dart - Flutter extension:
CodeDocumentExtension(bundled inDocumentEditorElements.defaults) - Action namespace:
CodeActions
Quick example
dart
import 'package:vyuh_document/vyuh_document.dart';
import 'package:vyuh_document_elements/vyuh_document_elements.dart';
final doc = Document.of(notesConfiguration, [
Code(
"void main() => print('Hello Vyuh Document');",
language: 'dart',
),
]);What you can configure
| Property | Type / Values | Purpose |
|---|---|---|
language | String? (e.g. 'dart', 'json', 'yaml', 'typescript', 'sql', 'bash', ...) | Selects the syntax highlighter grammar and fence label |
presentation.themeMode | CodeBlockThemeMode | Light, dark, or host-adaptive code block surface |
presentation.backgroundColor, textColor | String? (hex) | Override container fill and base code ink |
presentation.fontSize | double? (points) | Override monospace font size |
presentation.borderColor, borderWidth, borderRadius | String?, double? | Frame border styling and corner rounding |
presentation.paddingTop, paddingEnd, paddingBottom, paddingStart | double? (points) | Inner code block padding |
paragraphFormat | ParagraphFormat | Spacing before/after, line height, and pagination flow |
Actions & commands
| Action ID | Effect |
|---|---|
CodeActions.insert | Convert selection to a code block or insert one |
CodeActions.insertBlock | Insert a new standalone code block |
- Typed command:
SetLanguage(language)updates the syntax highlighting language canonically. - Markdown input rule: Typing
```dart(or```) + Enter creates a fenced code block with the given language. - Inline triggers disabled inside code: Typing
/,@, or:inside a code block stays literal source code — triggers never hijack code editing.
Restricting usage
- Remove code blocks:
notesConfiguration.withoutElements([Code.element]) - Keep inline code only: Exclude
Code.elementwhile keeping theInlineCodemark onParagraph.
Format parity
| DOCX | HTML | Markdown | |
|---|---|---|---|
| Shaded monospace paragraph block preserving line breaks | Monospace syntax-styled frame matching screen layout | <pre><code class="language-..."> | Fenced code blocks (```dart) |