Skip to content

#38 Add config support#97

Merged
udlose merged 21 commits intomainfrom
rajeshgithub001-add-config-support
Sep 2, 2025
Merged

#38 Add config support#97
udlose merged 21 commits intomainfrom
rajeshgithub001-add-config-support

Conversation

@udlose
Copy link
Copy Markdown
Owner

@udlose udlose commented Sep 2, 2025

PR Classification

Code cleanup and new feature implementation #38

PR Summary

This pull request refactors the asset management system and enhances the Mermaid diagram rendering capabilities by integrating YAML parsing. Key changes include:

  • ServiceConfiguration.cs: Refactored to use AssetHelper for asset extraction and validation.
  • MermaidRenderer.cs: Updated to utilize AssetHelper for retrieving assets, simplifying initialization.
  • index.html: Added support for YAML configuration blocks and included the new js-yaml.min.js script.
  • AssetHelper.cs: Introduced to manage asset extraction and retrieval, consolidating previous logic.
  • .editorconfig: Updated with new code style preferences and Resharper settings.

rajeshgithub001 and others added 16 commits September 1, 2025 13:14
…le keeping the macOS .app bundle download step intact.
…me to reference it from the embedded manifest resource stream

This commit adds `js-yaml.min.js` as an embedded resource in the project file with the logical name `MermaidPad.Assets.js-yaml.min.js`. It also removes the previous entries for `js-yaml.min.js` that were listed as a `None` type and as an `EmbeddedResource`, indicating that the file is no longer treated as a resource in the project. #38
Removed the `ExtractAssetsOnce` method from `ServiceConfiguration.cs` and replaced it with a call to `EmbeddedResourceHelper.ExtractAssets` for centralized asset extraction. Updated logging messages and removed constants for asset filenames.

Introduced a new `ExtractAssets` method in `EmbeddedResourceHelper.cs` to handle embedded asset extraction with improved logging and validation. Consolidated individual asset extraction into a loop for better maintainability.

Updated asset validation logic to utilize a list of required assets, enhancing clarity and extensibility of the code.
Updated the MermaidRenderer class to include support for the js-yaml.min.js file. Defined constants for the file name and request path, added existence checks during content preparation, and implemented asynchronous reading of the file. Modified HTTP request handling to serve the js-yaml file when requested.
Updated `ValidateAssets` method for clarity and functionality. Changed parameter name to `assetsDirectory` and modified logic to collect missing files in a list. Enhanced error handling with detailed messages for missing assets.
Updated the method of finding the first newline character in the exception's StackTrace. The change replaces the hardcoded `'\n'` with `Environment.NewLine` to ensure platform independence and correct newline handling across different environments.
This commit introduces a new asynchronous method, `GetEmbeddedResourceAsync`, in `EmbeddedResourceHelper.cs` that retrieves the content of an embedded resource as a byte array. The method is documented with XML comments detailing its functionality, parameters, return values, and potential exceptions. Additionally, a `using` directive for `System.Text` has been added to facilitate string encoding operations.
- Updated `ServiceConfiguration` to use `AssetHelper` for asset extraction.
- Renamed `EmbeddedResourceHelper` to `AssetHelper` and improved documentation.
- Introduced constants for asset file names to enhance maintainability.
- Added `GetAssetFromDiskAsync` method for asynchronous asset retrieval with error handling.
- Changed encoding handling to use a static readonly field for consistency.
- Updated stream reading to utilize the new encoding field.
- Removed asset directory parameters and introduced AssetHelper for better asset management.
- Transitioned from string-based content to byte arrays for enhanced performance and safety.
- Updated method names and improved logging for better insights during asset preparation.
Updated `<script>` tags for `mermaid.min.js` and `js-yaml.min.js` to include the `defer` attribute. This change allows the scripts to execute after the document has been parsed, improving page load performance by preventing blocking of page rendering.
Refactor code to ensure `mermaid` and `jsyaml` are accessed
as global objects via the `window` object. This change
improves compatibility across different contexts.
Specifically, the `retries` variable is now defined using
`window._mermaidRetries`, and both libraries are initialized
and rendered with the `window.` prefix.
Added and modified several code style settings for C# development in the `.editorconfig` file, including:
- Inferred names for tuples and anonymous types
- Compound assignment operator suggestions
- Simplified string interpolation
- Collection initializers for loosely matched types
- Namespace structure matching folder structure
- Resharper setting to disable highlighting for evident type object creation
Copilot AI review requested due to automatic review settings September 2, 2025 01:18
@udlose udlose self-assigned this Sep 2, 2025

This comment was marked as outdated.

@udlose udlose added bug Something isn't working enhancement New feature or request dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code labels Sep 2, 2025
@udlose udlose added this to the 1.0.5 milestone Sep 2, 2025
@udlose udlose linked an issue Sep 2, 2025 that may be closed by this pull request
Updated the `retries` variable from `const` to `let` to allow reassignment. This change is necessary for the retry logic to function correctly when rendering Mermaid diagrams, while the overall logic remains unchanged.
Refactor the handling of exception stack traces in the
`SimpleLogger` class by introducing a `ReadOnlySpan<char>`
to store the stack trace. This change reduces redundant
access to `ex.StackTrace`, improving efficiency and
readability when extracting the first line of the stack trace.
Added a new "Downloads" section in `build-and-release.yml` for macOS, detailing installation steps for a Universal DMG. Updated previous macOS installation notes and included new download options for Windows and Linux, featuring zip files for x64 and ARM64 architectures. These changes improve clarity and usability for users across different platforms.
@udlose udlose requested a review from Copilot September 2, 2025 02:03

This comment was marked as outdated.

…es" instead of "characters." Added a new log message to report the length of the prepared YAML content in bytes.
@udlose udlose requested a review from Copilot September 2, 2025 02:22

This comment was marked as outdated.

Removed unused Encoding references and optimized stream reading.
The new implementation directly reads bytes from the stream, enhancing performance by eliminating unnecessary string conversions.
@udlose udlose requested a review from Copilot September 2, 2025 02:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the asset management system and adds YAML configuration support for Mermaid diagrams. The changes consolidate asset handling logic into a new AssetHelper class and integrate js-yaml.min.js for parsing YAML configuration blocks.

  • Refactored asset management from ServiceConfiguration and EmbeddedResourceHelper into centralized AssetHelper
  • Added support for YAML configuration blocks in Mermaid diagrams with js-yaml integration
  • Updated initialization methods to use the new asset helper and removed parameter dependencies

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Views/MainWindow.axaml.cs Updated WebView initialization to use parameterless method and simplified asset handling
ViewModels/MainViewModel.cs Removed default values from observable properties
Services/SimpleLogger.cs Improved stack trace parsing using Environment.NewLine
Services/Platforms/EmbeddedResourceHelper.cs Deleted - functionality moved to AssetHelper
Services/Platforms/AssetHelper.cs New centralized asset management class with extraction, validation, and retrieval
Services/MermaidRenderer.cs Updated to use AssetHelper for asset retrieval and added js-yaml support
MermaidSamples.txt Added example showing YAML configuration usage
MermaidPad.csproj Added js-yaml.min.js as embedded resource
Infrastructure/ServiceConfiguration.cs Simplified by delegating asset extraction to AssetHelper
Assets/index.html Added js-yaml script and YAML configuration parsing logic
.github/workflows/build-and-release.yml Updated release documentation and download instructions
.editorconfig Added Resharper code style configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@udlose udlose merged commit bcb0747 into main Sep 2, 2025
@udlose udlose deleted the rajeshgithub001-add-config-support branch September 2, 2025 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file enhancement New feature or request github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Config Support

3 participants