-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for rendering diagrams with mermaid
[mermaid][Mermaid] generates diagrams and flowcharts from text in a similar manner as Markdown. This adds support for rendering diagrams from any markdown code blocks with the language tag `mermaid`. For example the code block: ```mermaid sequenceDiagram Alice->>+John: Hello John, how are you? John-->>-Alice: Great! ``` Will now render an inline SVG diagram of the sequence instead of the raw `<code>` block. Keeping diagrams as code in this way makes it significantly easier to keep diagrams up to date with the documentation, and can make reviewing changes to them easier. The implementation takes advantage of the existing dependecy on node.js to install and execute the mermaid cli tool that translates the various diagram code into SVG. A timeout is added to execution to workaround an issue where the cli tool [fails to terminate on error][fail-exit]. The deafult mermaid themes for diagrams don't quite fit the GOV.UK "brand" colors, and creating the CSS to get the colors pretty is out of scope, so this just sets it to use the "neutral" (grayscale) theme, which at least doesn't clash with anything. [mermaid]: https://mermaid-js.github.io/mermaid/#/ [fail-exit]: mermaidjs/mermaid.cli#77
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "rack/file" | ||
require "capybara/rspec" | ||
|
||
Capybara.app = Rack::File.new("example/build") | ||
|
||
RSpec.describe "Diagrams in code blocks" do | ||
include Capybara::DSL | ||
|
||
it "generates static SVG from mermaid code blocks" do | ||
when_the_site_is_created | ||
and_i_visit_the_code_page | ||
then_there_is_an_svg_diagram | ||
end | ||
|
||
def when_the_site_is_created | ||
rebuild_site! | ||
end | ||
|
||
def and_i_visit_the_code_page | ||
visit "/code.html" | ||
end | ||
|
||
def then_there_is_an_svg_diagram | ||
expect(page.body).to match '<svg id="mermaid-' | ||
end | ||
end |