Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/tynanpurdy/musical-text. Encourage writing with rhythm by highlighting sentences according to wordcount.
color colorful highlighter obsidian obsidian-md sentence-boundary-detection wordcount writing writing-tool
Something went wrong. Try again.
musical-text src
5 files
README.md
Musical Text Plugin - Module Structure #
This directory contains the modular components of the Musical Text plugin, organized by functionality for better maintainability and code organization.
Module Overview #
types.ts #
Type Definitions and Interfaces
SentenceMarkingStyleenum - Defines the three visual marking stylesMusicalTextSettingsinterface - Plugin settings structureColorPaletteinterface - Color palette definitionMarkdownListMarkerResultinterface - Result type for markdown parsing
color-utils.ts #
Color Processing and Contrast Generation
hexToHsl()- Converts hex colors to HSL formathslToHex()- Converts HSL back to hex formatgetContrastingTextColor()- Generates contrasting text colors of the same hue
Key Features:
- Maintains color harmony by preserving hue
- Ensures optimal contrast ratios for accessibility
- Automatically adjusts lightness for readability
sentence-detection.ts #
Text Analysis and Markdown Processing
computeDecorations()- Main function that analyzes text and creates decorationsdetectMarkdownListMarker()- Identifies and parses markdown list syntaxcountWords()- Counts words while excluding markdown syntaxgetClassForSentence()- Maps word counts to CSS classes
Handles:
- Traditional sentence punctuation (. ! ?)
- Line breaks and paragraph breaks
- Markdown lists (ordered, unordered, checkboxes)
- Precise positioning without marker interference
settings.ts #
Configuration and UI
COLOR_PALETTES- Predefined color schemes from popular editorsDEFAULT_SETTINGS- Default plugin configurationSentenceHighlighterSettingTab- Settings UI implementation
Features:
- 11 built-in color palettes (Gruvbox, Solarized, Tokyo Night, etc.)
- Threshold configuration for sentence lengths
- Color customization with palette reset functionality
- Marking style selection (highlighting, text color, underlining)
Architecture Benefits #
Separation of Concerns #
Each module has a single, well-defined responsibility:
- Types: Central type definitions
- Color Utils: Color manipulation logic
- Sentence Detection: Text parsing and analysis
- Settings: Configuration and UI
- Main: Plugin orchestration and CodeMirror integration
Maintainability #
- Easier to locate and modify specific functionality
- Reduced file size for easier navigation
- Clear module boundaries prevent coupling
- Individual modules can be tested independently
Extensibility #
- New marking styles can be added by updating types and main.ts
- Additional color palettes easily added to settings.ts
- Sentence detection can be enhanced without touching other modules
- Color algorithms can be improved independently
Import Structure #
// Main plugin imports modular components
import { MusicalTextSettings, SentenceMarkingStyle } from "./src/types";
import { getContrastingTextColor } from "./src/color-utils";
import { computeDecorations } from "./src/sentence-detection";
import { DEFAULT_SETTINGS, SentenceHighlighterSettingTab } from "./src/settings";
Development Guidelines #
Adding New Features #
- New marking styles: Update
SentenceMarkingStyleenum in types.ts, add case in main.ts - New color palettes: Add to
COLOR_PALETTESin settings.ts - Enhanced detection: Modify functions in sentence-detection.ts
- Color improvements: Update algorithms in color-utils.ts
Testing #
Each module can be tested independently:
- Color utils can be tested with various hex inputs
- Sentence detection can be tested with sample markdown
- Settings can be tested for UI behavior
- Types provide compile-time safety
This modular structure ensures the Musical Text plugin remains maintainable and extensible as it grows in functionality.