| # Copyright lowRISC contributors. |
| # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| # SPDX-License-Identifier: Apache-2.0 |
| """mdbook preprocessor for wavejson code-blocks. |
| It surrounds wavejson code-blocks with script tags of type WaveDrom. |
| from mdbook import utils as md_utils |
| WAVEJSON_PATTERN = re.compile("```wavejson\n(.+?)\n```", re.DOTALL) |
| WAVEJSON_REPLACE = r'<script type="WaveDrom">\1</script>' |
| if (sys.argv[1], sys.argv[2]) == ("supports", "html"): |
| # load both the context and the book from stdin |
| context, book = json.load(sys.stdin) |
| for chapter in md_utils.chapters(book["sections"]): |
| WAVEJSON_PATTERN.sub(WAVEJSON_REPLACE, chapter["content"]) |
| # dump the book into stdout |
| if __name__ == "__main__": |