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

render wavedrom in code block #467

Closed
9y2070m opened this issue Aug 16, 2022 · 3 comments · Fixed by #477
Closed

render wavedrom in code block #467

9y2070m opened this issue Aug 16, 2022 · 3 comments · Fixed by #477
Labels
Feature Feature request

Comments

@9y2070m
Copy link

9y2070m commented Aug 16, 2022

For documentation purposes its really nice to create diagrams easily using code.

It would be nice if you can support wavedrom.
https://wavedrom.com/

{signal: [
  {name: 'clk', wave: 'p.....|...'},
  {name: 'dat', wave: 'x.345x|=.x', data: ['head', 'body', 'tail', 'data']},
  {name: 'req', wave: '0.1..0|1.0'},
  {},
  {name: 'ack', wave: '1.....|01.'}
]}
@nicholasserra nicholasserra added the Feature Feature request label Aug 16, 2022
Crozzers added a commit to Crozzers/python-markdown2 that referenced this issue Aug 18, 2022
Works by using the wavedrom python package to render an SVG and embeds that inside the HTML.
@Crozzers
Copy link
Contributor

Hi there! I'm working an implementation of this feature using the wavedrom python package. So far, in order to use it you put your waves inside a fenced code block, setting "wavedrom" as the language like so:

Some text and information
```wavedrom
{ "signal": [{ "name": "Alfa", "wave": "01.zx=ud.23.456789" }] }
```

The wavedrom extra will then render and directly embed the resulting SVG into the output like so:

<p>Some text and information</p>

<div>
<svg ...>[Massive block of SVG stuff]</svg>
</div>

Was this the kind of implementation you had in mind?
If all goes well I'm hoping to submit a PR after #466 is merged, as this feature requires an optional dependency

@Crozzers
Copy link
Contributor

Just added a commit that will allow the SVG embedding to be disabled. If this is the case, or if the wavedrom python package is not installed, then the extra will wrap the code in <script type="WaveDrom">...</script> tags, as the Wavedrom README suggests.
This means that you can then link to the Wavedrom JS file instead of having a massive blob of SVG in the middle of your HTML file.

To control the SVG embedding, one would pass the wavedrom extra as a dict like so:

import markdown2
markdown2.markdown("[some stuff]", extras={"wavedrom": {"prefer_embed_svg": False}})

@9y2070m
Copy link
Author

9y2070m commented Aug 22, 2022

Yeah that's exactly what i had in my mind 😍

I am already using the javascript directly as workaround.
mitmproxy/pdoc#406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants