diff --git a/.gitignore b/.gitignore index 28e99cb..2076729 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _* ebin log erl_crash.dump +rebar3.crashdump .rebar _rel _deps diff --git a/README.md b/README.md index 52a8d27..50d845e 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,35 @@ In case you get a warning for something that is working or would like further co ### Additional options +#### Support for Mermaid + +Out-of-the-box support for [Mermaid](https://mermaid.js.org/) is provided via `rebar.config` option +`with_mermaid`, as follows: + +```erlang +{ex_doc, [ + {with_mermaid, true} +]}. +``` + +or + +```erlang +{ex_doc, [ + {with_mermaid, "10.2.4"} +]}. +``` + +Check out what this looks like in `doc/index.html`. + +```mermaid +graph TD; + A-->B; + A-->C; + B-->D; + C-->D; +``` + #### v prefix for source ref versions By default rebar3_ex_doc adopts the convention of prefixing versions with `v`. diff --git a/rebar.config b/rebar.config index f4f5a4f..0be1c18 100644 --- a/rebar.config +++ b/rebar.config @@ -27,7 +27,8 @@ {homepage_url, <<"https://github.com/starbelly/rebar3_ex_doc">>}, {source_url, <<"https://github.com/starbelly/rebar3_ex_doc">>}, {assets, <<"assets">>}, - {api_reference, false} + {api_reference, false}, + {with_mermaid, true} ]}. {profiles, [ diff --git a/src/rebar3_ex_doc.erl b/src/rebar3_ex_doc.erl index 3934537..ecae5a5 100644 --- a/src/rebar3_ex_doc.erl +++ b/src/rebar3_ex_doc.erl @@ -17,6 +17,7 @@ -define(DEFAULT_DOC_DIR, "doc"). -define(DEFAULT_DOC_LANG, "en"). +-define(DEFAULT_MERMAID_VSN, "10.2.4"). %% =================================================================== %% Public API @@ -77,6 +78,9 @@ format_error({write_config, Err}) -> format_error({unsupported_otp, Ver}) -> Str = "You are using erlang/OTP '~ts', but this plugin requires at least erlang/OTP 24.", io_lib:format(Str, [integer_to_list(Ver)]); +format_error({mermaid_vsn_not_string, Vsn}) -> + Str = "ex_doc option 'with_mermaid' should be 'true', 'false', or string(). Got: ~p", + io_lib:format(Str, [Vsn]); format_error({ex_doc, _}) -> ""; format_error(Err) -> @@ -307,6 +311,8 @@ to_ex_doc_format(ExDocOpts) -> [{K, to_binary(OutputDir)} | Opts]; ({prefix_ref_vsn_with_v, _}, Opts) -> Opts; + ({with_mermaid, Vsn}, Opts) -> + Opts ++ mermaid_add(Vsn); (OtherOpt, Opts) -> rebar_api:warn("unknown ex_doc option ~p", [OtherOpt]), [OtherOpt | Opts] @@ -490,3 +496,15 @@ help(language) -> help(logo) -> "Path to the image logo of the project (only PNG or JPEG accepted)." "The image size will be 64x64 and copied to the assets directory.". + +% Mermaid support +mermaid_add(false) -> + ""; +mermaid_add(true) -> + mermaid_add(?DEFAULT_MERMAID_VSN); +mermaid_add(Vsn) when is_list(Vsn) -> + [{before_closing_head_tag, #{ + html => "