-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
feat: Support config in frontmatter. #4750
Conversation
Related to #4748 |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #4750 +/- ##
============================================
+ Coverage 45.55% 74.83% +29.27%
============================================
Files 53 146 +93
Lines 6621 14561 +7940
Branches 32 586 +554
============================================
+ Hits 3016 10896 +7880
+ Misses 3604 3549 -55
- Partials 1 116 +115
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments:
- I don't think we should be changing
packages/mermaid/src/config.ts
. Can't we just treat config in the YAML frontmatter the same way we treat%%{init: ...}
directives?
That way we can use the already existingaddDirective()
function, and we don't need to worry about potential security vulnerabilities in this PR. (we may also need to calldirectiveSanitizer()
first). - This PR needs documentation on the https://mermaid.js.org/ website (maybe on the https://mermaid.js.org/config/configuration.html page?)
Yes, that was my first approach. But directives are currently not typed properly. So tried this as a POC. Docs will be added before merge. |
Is there any reason why can't just change the diff --git a/packages/mermaid/src/config.ts b/packages/mermaid/src/config.ts
index e0066382..a7e6c49b 100644
--- a/packages/mermaid/src/config.ts
+++ b/packages/mermaid/src/config.ts
@@ -8,10 +8,10 @@ export const defaultConfig: MermaidConfig = Object.freeze(config);
let siteConfig: MermaidConfig = assignWithDepth({}, defaultConfig);
let configFromInitialize: MermaidConfig;
-let directives: any[] = [];
+let directives: MermaidConfig[] = [];
let currentConfig: MermaidConfig = assignWithDepth({}, defaultConfig);
-export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: any[]) => {
+export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: MermaidConfig[]) => {
// start with config being the siteConfig
let cfg: MermaidConfig = assignWithDepth({}, siteCfg);
// let sCfg = assignWithDepth(defaultConfig, siteConfigDelta);
@@ -188,7 +188,7 @@ export const sanitize = (options: any) => {
*
* @param directive - The directive to push in
*/
-export const addDirective = (directive: any) => {
+export const addDirective = (directive: MermaidConfig) => {
if (directive.fontFamily) {
if (!directive.themeVariables) {
directive.themeVariables = { fontFamily: directive.fontFamily }; We may have to add add |
No reason at all. I guess my brain was in POC mode and didn't want to touch any existing stuff. I've cleaned it up now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason at all. I guess my brain was in POC mode and didn't want to touch any existing stuff.
I've cleaned it up now :)
The implementation looks great to me, all it needs is:
- E2E tests
- Can you add a test that has both a config directive in YAML frontmatter, and in a
%%{init: }
block, just to confirm it works?
- Can you add a test that has both a config directive in YAML frontmatter, and in a
- an example in the
demos/
folder (or multiple examples), and - some documentation in the https://mermaid.js.org site!
If you want to be really fancy, you can rewrite the your commits to split up the refactor
commits (which have no visible changes to users), fix:
commits (which fix potential bugs), and the feat:
commits (which add new features), e.g. something like refactor: sanitize in addDirective
, refactor: improve addDirective types
, ... fix: improve YAML frontmatter type handling
, feat: support config directives in YAML
, but this is a pretty small PR, so it doesn't matter too much 😄
FYI, I think this PR will close issue #4630! If you agree, feel free to stick it in your PR's description.
d46307a
to
85d2b8f
Compare
ac31665
to
a6e6c3f
Compare
…d-js/mermaid into feature/frontmatterConfig * 'feature/frontmatterConfig' of https://github.com/mermaid-js/mermaid: Update docs
cff9f49
to
2967b3c
Compare
db873fa
to
2b9dc0e
Compare
…rConfig * origin/develop: chore: Remove duplicate CI action chore: Add circular dependency check in CI refactor: Remove circular dependencies
Merging myself as @knsv has approved and attempted a merge. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [mermaid](https://togithub.com/mermaid-js/mermaid) | [`10.3.1` -> `10.4.0`](https://renovatebot.com/diffs/npm/mermaid/10.3.1/10.4.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/mermaid/10.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/mermaid/10.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/mermaid/10.3.1/10.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/mermaid/10.3.1/10.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>mermaid-js/mermaid (mermaid)</summary> ### [`v10.4.0`](https://togithub.com/mermaid-js/mermaid/releases/tag/v10.4.0) [Compare Source](https://togithub.com/mermaid-js/mermaid/compare/v10.3.1...v10.4.0) #### Features - feat: Support config in frontmatter. by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4750](https://togithub.com/mermaid-js/mermaid/pull/4750) - feat(sankey): Show values by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4748](https://togithub.com/mermaid-js/mermaid/pull/4748) #### Docs - docs: Add development example page. by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4714](https://togithub.com/mermaid-js/mermaid/pull/4714) - Documentation for [#​2509](https://togithub.com/mermaid-js/mermaid/issues/2509) by [@​jason-curtis](https://togithub.com/jason-curtis) in [https://github.com/mermaid-js/mermaid/pull/4740](https://togithub.com/mermaid-js/mermaid/pull/4740) - Fixes to Docs sidebar, main page and badges by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4742](https://togithub.com/mermaid-js/mermaid/pull/4742) - Split development documentation into several pages by [@​nirname](https://togithub.com/nirname) in [https://github.com/mermaid-js/mermaid/pull/4744](https://togithub.com/mermaid-js/mermaid/pull/4744) - Docs: update Latest News section by [@​huynhicode](https://togithub.com/huynhicode) in [https://github.com/mermaid-js/mermaid/pull/4768](https://togithub.com/mermaid-js/mermaid/pull/4768) #### Chores - Update all minor dependencies (minor) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4732](https://togithub.com/mermaid-js/mermaid/pull/4732) - Update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4731](https://togithub.com/mermaid-js/mermaid/pull/4731) - convert `assignWithDepth` to TS by [@​Yokozuna59](https://togithub.com/Yokozuna59) in [https://github.com/mermaid-js/mermaid/pull/4717](https://togithub.com/mermaid-js/mermaid/pull/4717) - convert `diagrams/common/svgDrawCommon.js` to ts by [@​Yokozuna59](https://togithub.com/Yokozuna59) in [https://github.com/mermaid-js/mermaid/pull/4724](https://togithub.com/mermaid-js/mermaid/pull/4724) - ci(release-drafter): add more release notes categories by [@​aloisklink](https://togithub.com/aloisklink) in [https://github.com/mermaid-js/mermaid/pull/4752](https://togithub.com/mermaid-js/mermaid/pull/4752) - chore(deps): update all patch dependencies (patch) by [@​renovate](https://togithub.com/renovate) in [https://github.com/mermaid-js/mermaid/pull/4753](https://togithub.com/mermaid-js/mermaid/pull/4753) - standardized pie definitions by [@​Yokozuna59](https://togithub.com/Yokozuna59) in [https://github.com/mermaid-js/mermaid/pull/4501](https://togithub.com/mermaid-js/mermaid/pull/4501) - Remove Circular Dependencies by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4761](https://togithub.com/mermaid-js/mermaid/pull/4761) - chore: Enforce type imports by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4763](https://togithub.com/mermaid-js/mermaid/pull/4763) - chore: Preview PRs with mermaid-live-editor on Netlify by [@​sidharthv96](https://togithub.com/sidharthv96) in [https://github.com/mermaid-js/mermaid/pull/4769](https://togithub.com/mermaid-js/mermaid/pull/4769) #### New Contributors - [@​jason-curtis](https://togithub.com/jason-curtis) made their first contribution in [https://github.com/mermaid-js/mermaid/pull/4740](https://togithub.com/mermaid-js/mermaid/pull/4740) **Full Changelog**: mermaid-js/mermaid@v10.3.1...v10.4.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/levaintech/contented). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41Ni4wIiwidXBkYXRlZEluVmVyIjoiMzYuNTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
📑 Summary
Allows defining diagram specific config from the frontmatter.
Resolves #4630
📏 Design Decisions
The config will be added using the existing
addDirective
function, which has the necessary security checks.📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.develop
branch