Skip to content

Feature predefined variable extension#153

Merged
telesoho merged 6 commits into
telesoho:masterfrom
seaspeak:feature-predefined-variable-extension
May 2, 2026
Merged

Feature predefined variable extension#153
telesoho merged 6 commits into
telesoho:masterfrom
seaspeak:feature-predefined-variable-extension

Conversation

@seaspeak

Copy link
Copy Markdown
Contributor

Summary
Enhancement: Add ${basePath}, slicing support, and constructor injection for Predefine.

Description
I’ve implemented several improvements to the variable expansion system:

  • Added ${basePath} variable for rendering Markdown root‑relative paths (e.g. /images/...).
  • Implemented Python‑style slicing (start:end) for variable expansion (e.g. ${filePath|:-1}).
    • Step slicing not supported (e.g. [::2], [::-1]).
    • Supported variables for slicing: ${filePath}, ${fileWorkspaceFolder}, ${relativeFileDirname}.
  • Added new test case: "predefined variables slicing test" to verify slicing behavior.
  • Extended Predefine constructor to support Dependency Injection, improving testability.

Syntax examples:

${relativeFileDirname} → "src/assets/images"
${relativeFileDirname|-1} → "images"
${relativeFileDirname|0:2} → "src/assets"
${relativeFileDirname|:-1} → "src/assets"

Motivation
This enhancement provides more flexibility in handling file paths and workspace‑relative paths. Developers can now manipulate paths more easily when working with Markdown paste operations.
Constructor injection also improves testability by allowing mock values to be injected during unit tests.

Testing

  • All existing tests pass.
  • New slicing test case added and verified.

…ystem with Python-style slicing support.

- Added `${basePath}` variable to render root-relative path (e.g. `/images/...`).
- Implemented Python-style slicing (`start:end`) for variable expansion, e.g. `${filePath|:-1}`.
- Step slicing (e.g. `[::2]`, `[::-1]`) is not supported.
- Supported variables for slicing: `${filePath}`, `${fileWorkspaceFolder}`, `${relativeFileDirname}`.
- Added new test case: "predefined variables slicing test" to verify Python-style slicing behavior
  (|-1, 0:2, :-1 supported; ::2 step not supported).
- Extended Predefine constructor to allow injection for testing purposes.
- Remove test console.log
@telesoho

Copy link
Copy Markdown
Owner

@seaspeak

In Ubuntu and macOS environments, the "predefined variables slicing test" unit test failed to pass. Could you please check it?

seaspeak added 3 commits May 2, 2026 03:07
- Replaced hardcoded Windows-style path "C:\" with OS-specific strings
- Ensured tests run correctly on both Windows and Ubuntu
- Ensures correct handling of root (e.g. "C:\\" vs "C:"; "/")
- Use Node.js path API to avoid direct path string manipulation
- Keep path representation platform-dependent
- Improves cross-platform consistency between Windows and Linux
- Use path.resolve for customBasePath to ensure consistent root reference
- Prevent prepending slashes to paths that are already absolute (e.g., cross-drive paths on Windows)
@telesoho telesoho merged commit a646bd8 into telesoho:master May 2, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants