Open WhySeeYC opened 2 years ago
I assume there are some characters that are not allowed (reserved). I use MermaidJS for dynamic flowcharts, based on DB data, and have special escaping f-n
def safe(text: str) -> str:
return text.replace('(', '<').replace(')', '>').replace("'", '`').replace('"', '`').replace('[', '<')\
.replace(']', '>').replace('@', '*').replace('|', '/').replace('{', '<').replace('}', '>')
this is a good candidate for str.maketrans
and str.translate
:)
safe_table = str.maketrans({
'(': '<',
')': '>',
"'": '`',
'"': '`',
'[': '<',
']': '>',
'@': '*',
'|': '/',
'{': '<',
'}': '>',
})
# later...
print("... your unsafe string ...".translate(safe_table))
Hi @rdemetrescu and @devova, thank you so much for the response! I really appreciate it. However, I tried with the str.maketrans
function and replace out those characters and re-run my defined mermaid string. It still only shows the preview icon. Further on, I checked whether the original string and translated string are the same, and it showed that they are actually the same (Please see screenshot). So I am not sure whether this implies the problem is at the encoding and decoding step.
I am also having this problem.
When I try to display the tutorial gantt:
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24d
Using the python code, the url is :https://mermaid.ink/img/CmdhbnR0ICAKICAgIHRpdGxlIEEgR2FudHQgRGlhZ3JhbSAgCiAgICBkYXRlRm9ybWF0ICBZWVlZLU1NLUREICAKICAgIHNlY3Rpb24gU2VjdGlvbiAgCiAgICBBIHRhc2sgICAgICAgICAgIDphMSwgMjAxNC0wMS0wMSwgMzBkICAKICAgIEFub3RoZXIgdGFzayAgICAgOmFmdGVyIGExICAsIDIwZCAgCiAgICBzZWN0aW9uIEFub3RoZXIgIAogICAgVGFzayBpbiBzZWMgICAgICA6MjAxNC0wMS0xMiAgLCAxMmQgIAogICAgYW5vdGhlciB0YXNrICAgICAgOiAyNGQgIAo=
but if I use the live editor to generate the same gantt, I get: https://mermaid.live/edit#pako:eNpdUD2LwzAM_StCcwJx2slbIfSmTu1y4EXESmsusUuiDEfpfz_5cFqoMFh-H3pYD-yTZ7R4pSgC4CJoSZCR4QBf_2AX6DrTtJGehI9pnkjl31r16VR33cYu3EtIEc7lLvABhJYfeJclU0HbmH3dGD0V7Br_EsckN57fFkuD6JsMQDb5z7DNUOBL9oWY6RK2BZk2TzDtawJ9RoGFdq80VjixfjJ4Xc4jix2qcmKHVlvPA62jOHTxqVJaJZ1_Y49W5pUrXO95S2VxaAcaF37-AXkQZ9Y
MacOS Big Sur: 12.3 JupyterLab: Version: 3.6.2 Python: 3.9.6
Does anybody knows how to create live link for the graph generated? All examples I found were creating links for mermaid.ink, but I saw the show-me plugin in ChatGPT generating a editable mermaid.live link with the generated graph. Any help would be appreciated. I tried passing the base64 string, it doesn't work.
Thanks
For anyone coming across, the following works for me,
def mermaid_editor_link(code):
mermaid_editor_json = {
"code": code,
"mermaid": {"theme": "default"},
"updateEditor": False
}
mermaid_editor_json_string = json.dumps(mermaid_editor_json)
buffer = base64.b64encode(mermaid_editor_json_string.encode()).decode()
return 'https://mermaid.live/edit#' + buffer
to avoid this problem I suggest using a library in Python that act as an interface for the meamaidjs mermaid-py it work like this :
Hi π community, I have loved the function of mermaid and would like to try to integrate it with Python plotting in Jupyter Notebook in vs code. However, it seems that the integration only work for certain type of diagrams: Here is the code:
Would somebody kindly help me with the integration? I would like to make the Gantt chart work. Here are the specs of my system:
Am programming rookie π so please kindly suggest a step forward. If this likely is an jupyter issue, it will highly be appreciated to be pointed to where to seek for help as well. π