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

Way of switching between YAML and JSON in README and docs #81

Open
simonw opened this issue Feb 15, 2022 · 4 comments
Open

Way of switching between YAML and JSON in README and docs #81

simonw opened this issue Feb 15, 2022 · 4 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Feb 15, 2022

For example on https://datasette.io/plugins/datasette-init I would like a JSON/YAML toggle on this example:

image

I'd like this in the docs too, like on https://docs.datasette.io/en/stable/metadata.html

@simonw simonw transferred this issue from another repository Feb 15, 2022
@simonw simonw transferred this issue from simonw/temp Feb 15, 2022
@simonw
Copy link
Owner Author

simonw commented Feb 15, 2022

I think the best way to do this is to have all of the examples in YAML (since that can be formatted in different ways) and then provide JavaScript that can read that YAML and convert it to pretty-printed JSON.

@simonw
Copy link
Owner Author

simonw commented Feb 15, 2022

This works, using https://www.npmjs.com/package/yaml

<script type="module">
import yaml from 'https://cdn.skypack.dev/yaml';
console.log(yaml.parse("foo: bar"));
</script>

It's a little bit heavy though - 63.9KB transferred:

image

@simonw
Copy link
Owner Author

simonw commented Feb 15, 2022

Using https://cdn.skypack.dev/yaml?min is a bit lighter: 47.12KB transferred total:

image

@simonw
Copy link
Owner Author

simonw commented Feb 15, 2022

In Firefox DevTools I had to use:

const yaml = await import('https://cdn.skypack.dev/yaml');
yaml.default.parse('foo: bar');

@simonw simonw added documentation Improvements or additions to documentation enhancement New feature or request labels May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant