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

not working with Unicode characters in API #437

Open
Mrithul-E opened this issue Nov 23, 2024 · 5 comments
Open

not working with Unicode characters in API #437

Mrithul-E opened this issue Nov 23, 2024 · 5 comments

Comments

@Mrithul-E
Copy link

utf-8 not working with base64 , cant use ascii in Unicode

@jihchi
Copy link
Owner

jihchi commented Nov 23, 2024

Could you please provide an example of the mermaid code?

@Mrithul-E
Copy link
Author

Mrithul-E commented Dec 7, 2024


import base64
import json
import zlib

def generate_pako_url(graph_definition):
    payload = {
        "code": graph_definition,
        "mermaid": {"theme": "default"}
    }
    json_string = json.dumps(payload)
    compressed_data = zlib.compress(json_string.encode('utf-8'), level=9)
    base64_encoded = base64.b64encode(compressed_data).decode('utf-8')
    return f"http://mermaid.ink/svg/pako:{base64_encoded}"


graph = """
graph LR
   A[പാപ്പിനിശ്ശേരി] --> B(കണ്ണൂർ ജില്ലയിലെ ഒരു ഗ്രാമ പഞ്ചായത്ത്)
   B --> C(2017-18 വർഷത്തെ മികച്ച ഗ്രാമപഞ്ചായത്ത്)
"""

print(generate_pako_url(graph))

content = requests.get(generate_pako_url(graph)).content

with open("id.svg", "wb") as svg:
    svg.write(content)

not working :http://mermaid.ink/svg/pako:eNqlkk0LwjAMhv9K6EnBQT+2dXgQnFdPXp2HsnZOcFPGdhr777p00ICIBy/haZq8zVsysvJhHdsCK9prZ541HE9FCwD7czFwK80clQscW5KvkLPAKg01C2tk7msuEEU7yFfzSSTYrYiqZzlHXQIWlURcEnFkWX3cpr5Nhldj4VOadHNiy0FwJFwoEtS7dxqTWRde42/l6OuwklzoSGSoqBLvA1l/6ffjShd8+G8Rhg7yw8Cf87MNsMZ1jbnZ9yKMrK9dgythXWWGe8+m6QXU2qo4

but mermaid.live auto correct the pako that work, please help me write the code to convert the text to a working pako url.

@Mrithul-E
Copy link
Author

@jihchi how to convert a text to that working pako

@jihchi
Copy link
Owner

jihchi commented Dec 7, 2024

I used Mermaid Live Editor and it works for me:

https://mermaid.ink/img/pako:eNqFkTFLAzEUx79KeFOFO7Auyg2CrW666KZxCE3aO-hdjpgMUjrooJOLUAQRFx3EoZaS00X0q-Sj-PK0Ki4uf977v_fPLyQj6GmpIIOBEXXOtnd5xRjbOAj-Mfi3qM0F1e_BP5A-k4N6HvwMnUOWpuus0wp-EvwdDVFPQ_PKgr-hyJzcefBPi_YMZ5cx35xgdUXzGQGnjHC3ZF2Thal7aqMu0QU7BO22Vpbbq2l7DTMNAoN_-bUaGVMCTuJJdN5f2D8sSKBUphSFxBcaRTIHm6tScciwlKov3NBy4NUYV4Wzeu-46kFmjVMJuFoKqzYLgW9bQtYXw6Nvd0sWVpvFpqJu5_Mn6EMSqEW1r_VPzmg3yL-68QcSFekk?type=png

For Python code, please refer to #396 to see if that helps.

@Mrithul-E
Copy link
Author

oh thank you @jihchi ❤️

its now working

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

No branches or pull requests

2 participants