Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add icon packs #5

Merged
merged 2 commits into from
Jan 31, 2025
Merged

Conversation

owynrichen
Copy link

@owynrichen owynrichen commented Jan 13, 2025

feat(markdown_mermaidjs.py,-test_markdown_mermaid.py,-some-tasks): adds the ability to register icon packs with mermaid via extension configuration

Some newer diagrams (like architecture-beta) leverage icons that can be customized via mermaid.registerIconPacks() https://mermaid.js.org/config/icons.html, this exposes that capability via extension configuration and adds some tests.

Types of changes

  • New feature
  • Refactoring
  • Documentation Update

Description

In addition to the registerIconPacks() work (with tests/etc), I also did some refactoring.

It also adds the ability to decide to bypass pty for tasks that require it so they can run on Windows. The big exception is the git.commit task doesn't work properly as prompt_toolkit can't seem to detect when running in cmd.exe (even when it is). It functions as expected in Ubuntu, though.

Checklist:

  • Add test cases to all the changes you introduce
  • Run inv style locally to ensure all linter checks pass
  • Run inv test locally to ensure all test cases pass
  • Run inv secure locally to ensure no major vulnerability is introduced
  • it did note that jinja2 could use a patch version bump, but that seemed like a dependency issue
  • Update the documentation if necessary
  • added examples for how to use it in both python and Pelican

Steps to Test This Pull Request

The unit tests and documentation additions should cover the primary cases. Basically pass in an extension config
with icon_packs declared that match the { name : url } pattern i.e.:

{
  icon_packs : {
    'logos' : 'https://unpkg.com/@iconify-json/logos@1/icons.json'
  }
}

and it should add corresponding mermaid.registerIconPacks() calls in the script module declaration i.e.:

<script type="module">
    import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
    mermaid.registerIconPacks([
      { name: 'logos', loader: () => fetch('https://unpkg.com/@iconify-json/logos@1/icons.json').then((res) => res.json()) }
    ]);
    mermaid.initialize({ startOnLoad: true });
</script>

Expected behavior

The unit tests assert this behavior, specifically:

test_add_mermaid_script_and_tag_with_icons()

Related Issue

Additional context

@Lee-W Lee-W self-requested a review January 17, 2025 01:34
@Lee-W
Copy link
Owner

Lee-W commented Jan 18, 2025

Hi @owynrichen , could you please fix the EOL before reviewing? It changes too many things now make it harder to review

@owynrichen
Copy link
Author

Can do, let me take a look and update it.

@owynrichen
Copy link
Author

Got it done! Sorry for the delay. It should be ready for review now.

@Lee-W
Copy link
Owner

Lee-W commented Jan 22, 2025

Got it done! Sorry for the delay. It should be ready for review now.

It still contains lots of files I think might not need to be changed 🤔 Could you please use git diff main and check whether these are the expected changes? Thanks!

@owynrichen
Copy link
Author

Hey, I appreciate the POV. The changes in /tasks were to enable the passing of choice for pty from the command-line vs. forcing it to True always, to aide in execution on Windows (and corresponding documentation referencing the option). It still defaults to True so it's a no-op for folks generally.

The other changes are related to the additions themselves and adjustments to unit tests to match. The updates to the pre-commit-hook happened automatically when running the contributing documentation. I'm happy to revert those if you'd prefer.

Copy link
Owner

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

The idea looks good. left some suggestions. Thanks for helping out!

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
docs/contributing.md Outdated Show resolved Hide resolved
markdown_mermaidjs/markdown_mermaidjs.py Outdated Show resolved Hide resolved
markdown_mermaidjs/markdown_mermaidjs.py Outdated Show resolved Hide resolved
markdown_mermaidjs/markdown_mermaidjs.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@Lee-W
Copy link
Owner

Lee-W commented Jan 25, 2025

Hey, I appreciate the POV. The changes in /tasks were to enable the passing of choice for pty from the command-line vs. forcing it to True always, to aide in execution on Windows (and corresponding documentation referencing the option). It still defaults to True so it's a no-op for folks generally.

The other changes are related to the additions themselves and adjustments to unit tests to match. The updates to the pre-commit-hook happened automatically when running the contributing documentation. I'm happy to revert those if you'd prefer.

I just checked again. Somehow the last time it did not reflect the changes 🤔 Thanks for updating!

@owynrichen
Copy link
Author

Awesome, thanks for the feedback! I've updated things based on your recommendations.

Copy link
Owner

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Most of the remaining things are just nitpicks. We're really close to merge. Thanks for helping out!

markdown_mermaidjs/markdown_mermaidjs.py Outdated Show resolved Hide resolved
markdown_mermaidjs/markdown_mermaidjs.py Show resolved Hide resolved
tests/test_markdown_mermaid.py Outdated Show resolved Hide resolved
Copy link
Owner

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

one last nitpick and then we can merge it!

) # for the None case
self.icon_packs.update(config_packs)

"""Add mermaid diagram markdown codeblocks."""
Copy link
Owner

Choose a reason for hiding this comment

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

Let's move it to class docstring

@Lee-W
Copy link
Owner

Lee-W commented Jan 28, 2025

we might need to take care of the blacken-docs version as well

@Lee-W Lee-W force-pushed the feature/add_icon_packs branch 2 times, most recently from d00bb97 to 755777f Compare January 31, 2025 06:43
owynrichen and others added 2 commits January 31, 2025 14:45
…h mermaid via extension configuration

Some newer diagrams (like architecture-beta) leverage icons that can be customized via mermaid.registerIconPacks() https://mermaid.js.org/config/icons.html, this exposes that capability via extension configuration and adds some tests
@Lee-W Lee-W force-pushed the feature/add_icon_packs branch from 755777f to 6bd4a64 Compare January 31, 2025 06:46
@Lee-W Lee-W merged commit e564c87 into Lee-W:main Jan 31, 2025
1 check 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