-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Made script to convert directives to yml #4827
base: develop
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #4827 +/- ##
===========================================
+ Coverage 79.52% 79.55% +0.03%
===========================================
Files 147 147
Lines 13069 13069
Branches 613 613
===========================================
+ Hits 10393 10397 +4
+ Misses 2546 2542 -4
Partials 130 130
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.
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.
ok sure
const filePath : string ="./test/test.md"; | ||
|
||
fs.readFile(filePath,'utf-8',(err,data)=>{ | ||
if(err){ | ||
console.log("Error reading file"+err); | ||
return; | ||
} |
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.
Please wrap file reading in a function that should be executed when needed and filePath
as a parameter.
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.
ok i will do this change thanks
return; | ||
} | ||
|
||
const diresctiveRegix=/%%{init:(.*?)\}%%/g; |
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.
The regex should match everything between %%{
and }%%
, if it's empty then just remove it.
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.
ok but we have every directive with init in it so that is why i used this regex pattern
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.
Not necessarily, there are some other samples. It also can have empty spaces between after %%{
, so do not rely on its content.
This one is escaped \}
, but this one is not {
(probably, should be).
const jsonContent = directiveContent.replace(/'/g, '"'); | ||
|
||
// Construct YAML content manually | ||
const newYamlContent=`{"config":${jsonContent}}`; |
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.
It would be better if used this instead:
config:
pie: ...
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.
And some data aren't inside `config. Please refer to docs for that.
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.
can you elaborate this one as i am not able to understand the data part please
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.
As the example I provided in the issue:
title: This is another complicated flow
config:
theme: base
sankey:
nodeAlignment: justify
flowchart:
curve: cardinal
htmlLabels: false
Not everything is under the config
key
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.
hi @nirname can you help me with a regex patter that i can use to solve this above example and like can you give a directive example where above mentioned example is converted from
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.
hi @Yokozuna59 can you provide me the link where data is not inside config and also the pie that you mentioned will come automatically can you help me out with it
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.
@aloisklink we need your help. There is a schema which represents config, but it seems that the config is only a subset of yaml directives. Where to look, to have a full example?
@Aryangp
There is a schema which represents config. According to the docs we have config
and title
keys (at least)
Directives is what is being deprecated.
Addressing your question about syntax. These were recently removed from grammar, but you can get the idea
of what directives syntax was and what the current function to detect them is
There is an example of detect function call
This is how diagrams are preprocessed
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.
@aloisklink we need your help. There is a schema which represents config, but it seems that the config is only a subset of yaml directives. Where to look, to have a full example?
So far, I don't think there isn't anything, see #4757. There's only the https://mermaid.js.org/config/configuration.html#frontmatter-config documentation, which isn't very substantial.
Contributions to improving the documentation are welcome (even I don't know what can and can't be put into frontmatter, e.g. does wrap: true
do anything??)
Long-term, I'd love to make a JSON Schema that represents and documents the front matter, but I haven't had much time recently to work on mermaid unfortunately (and I first want to help improve the existing MermaidConfig
JSON schema).
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.
@Aryangp please keep title
and config
keys. I'm not sure what else should be here
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.
Please, fix linting.
If this request only adds script, but does not update directives, then it should not resolve the issue
return; | ||
} | ||
|
||
const diresctiveRegix=/%%{init:(.*?)\}%%/g; |
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.
Not necessarily, there are some other samples. It also can have empty spaces between after %%{
, so do not rely on its content.
This one is escaped \}
, but this one is not {
(probably, should be).
const jsonContent = directiveContent.replace(/'/g, '"'); | ||
|
||
// Construct YAML content manually | ||
const newYamlContent=`{"config":${jsonContent}}`; |
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.
As the example I provided in the issue:
title: This is another complicated flow
config:
theme: base
sankey:
nodeAlignment: justify
flowchart:
curve: cardinal
htmlLabels: false
Not everything is under the config
key
Please add the modified contents to this PR. |
@Aryangp Is there any updates in this PR? I'm currently working on the language server and I want to make it convert directives to front matter: example.webm |
@Yokozuna59 No sorry actually i had my university exams can you give me two days i will update the changes in the PR |
@Aryangp ping |
📑 Summary
I have created a script that will convert the existing directive code to yml code as it scan throught the given file and change it to yml code
Resolves #4756
📏 Design Decisions
I have used simple fs library to scan througth the file and using regex pattern to find the directives in it when i find those pattern i make a function that take the json code and convert it into yml and that write that changed code in the existing file
📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.develop
branch