d2-playground icon indicating copy to clipboard operation
d2-playground copied to clipboard

Question: Generate URL for d2 files for play.d2lang.com preview

Open edwinjhlee opened this issue 1 year ago • 3 comments

Hello D2 community,

I'm trying to understand how to encode D2 code into the URL for the online playground: https://play.d2lang.com/

I've noticed the script URL parameter appears to contain encoded D2 code, for example: https://play.d2lang.com/?script=qlDQtVOo5AIEAAD__w%3D%3D. Is there any official documentation that explains this encoding scheme and other URL parameters for the playground?

Thank you

edwinjhlee avatar Dec 13 '24 08:12 edwinjhlee

I just foud the related issue here:

https://github.com/terrastruct/d2-playground/issues/45

https://gist.github.com/jrcd-HR/92ef3407c9f5061787b7c7a095a031ea

https://github.com/terrastruct/d2/pull/1709

edwinjhlee avatar Dec 13 '24 08:12 edwinjhlee

I notice currently using compress/flate and basd64 as encoding in the playgroud url. It is very hard to do such encoding in the shell scenario with curl and native commands. Is there any other way to pass the file content to the playground ? any attribute other than 'script=' ?

@alixander

BTW, is there any documents about the api ?

https://api.d2lang.com/render/svg?script=qlDQtVOo5AIEAAD__w%3D%3D&

edwinjhlee avatar Dec 13 '24 08:12 edwinjhlee

I am also looking for how to deploy this API service, looking forward to your reply

Sayi avatar Dec 13 '24 14:12 Sayi