I made this couple months ago. It is not perfect but may give you some idea. I haven't try bimodal/multimodal one.
hDI[α_, a_, b_] :=
Module[{}, f[x_] := PDF[NormalDistribution[], x];
sol = {c1, c2} /.
Assuming[
c1 ∈ Reals && c2 ∈ Reals && c1 <= 0 &&
c2 >= 0 ,
FindRoot[{Integrate[f[x], {x, c1, c2}] == α,
f[c2] == f[c1]}, {{c1, a}, {c2, b}}, MaxIterations -> 1000]];
Show[Plot[f[x], {x, First@sol, Last@sol}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All,
Filling -> Axis, FillingStyle -> LightBlue],
Plot[f[x], {x, -3, 3}],
Graphics[{Arrowheads[{-0.04, 0.04}],
Arrow[{{First@sol, f[First@sol]}, {Last@sol, f[Last@sol]}}],
Text[Round[First@sol, 0.01], {First@sol - 0.3, f[First@sol]}],
Text[Round[Last@sol, 0.01], {Last@sol + 0.3, f[Last@sol]}],
Text[Round[α 100] "% HDI", {Mean[{First@sol, Last@sol}],
f@Mean[{First@sol, Last@sol}]/2}]}]]]
hDI[0.95, -1, 1]

hDI[α_, a_, b_] :=
Module[{}, data = RandomVariate[NormalDistribution[], 10000];
f[x_] := PDF[SmoothKernelDistribution[data], x];
sol = {c1, c2} /.
Assuming[
c1 ∈ Reals && c2 ∈ Reals && c1 <= 0 &&
c2 >= 0 ,
FindRoot[{Integrate[f[x], {x, c1, c2}] == α,
f[c2] == f[c1]}, {{c1, a}, {c2, b}}, MaxIterations -> 1000]];
Show[Plot[f[x], {x, First@sol, Last@sol}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All,
Filling -> Axis, FillingStyle -> LightBlue,
Plot[f[x], {x, -3, 3}],
Graphics[{Arrowheads[{-0.04, 0.04}],
Arrow[{{First@sol, f[First@sol]}, {Last@sol, f[Last@sol]}}],
Text[Round[First@sol, 0.01], {First@sol - 0.3, f[First@sol]}],
Text[Round[Last@sol, 0.01], {Last@sol + 0.3, f[Last@sol]}],
Text[Round[α 100] "% HDI", {Mean[{First@sol, Last@sol}],
f@Mean[{First@sol, Last@sol}]/2}]}]]]
hDI[0.95, -1, 1]

hDI[α_, a_, b_] :=
Module[{}, f[x_] := PDF[GammaDistribution[2, 2], x];
sol = {c1, c2} /.
Assuming[
c1 ∈ Reals && c2 ∈ Reals && c1 >= 0 &&
c2 >= 0 ,
FindRoot[{Integrate[f[x], {x, c1, c2}] == α,
f[c2] == f[c1]}, {{c1, a}, {c2, b}}, MaxIterations -> 1000]];
Show[Plot[f[x], {x, First@sol, Last@sol}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All,
Filling -> Axis, FillingStyle -> LightBlue,
Plot[f[x], {x, -1, 13}],
Graphics[{Arrowheads[{-0.04, 0.04}],
Arrow[{{First@sol, f[First@sol]}, {Last@sol, f[Last@sol]}}],
Text[Round[First@sol, 0.01], {First@sol - 0.3, f[First@sol]}],
Text[Round[Last@sol, 0.01], {Last@sol + 0.3, f[Last@sol]}],
Text[Round[α 100] "% HDI", {Mean[{First@sol, Last@sol}],
f@Mean[{First@sol, Last@sol}]/2}]}]]]
hDI[0.95, 2, 6]

hDI[α_, a_] :=
Module[{}, f[x_] := PDF[ExponentialDistribution[2], x];
sol = c1 /.
Assuming[c1 ∈ Reals && c1 >= 0 ,
FindRoot[{Integrate[f[x], {x, 0, c1}] == α}, {c1, a},
MaxIterations -> 1000]];
Show[Plot[f[x], {x, 0, sol}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All,
Filling -> Axis, FillingStyle -> LightBlue,
Plot[f[x], {x, 0, 2}],
Graphics[{Arrowheads[{-0.04, 0.04}],
Arrow[{{0, f[sol]}, {sol, f[sol]}}],
Text[Round[0, 0.01], {0, f[sol]}],
Text[Round[sol, 0.01], {sol + 0.1, f[sol]}],
Text[Round[α 100] "% HDI", {Mean[{0, sol}],
f@Mean[{0, sol}]/2}]}]]]
hDI[0.8, 1]

d =
SmoothKernelDistribution[
N[Log[Table[GenomeData[i, "SequenceLength"], {i, 41}]]]];
f[x_] := PDF[d], x];
hDI[α_, a_, b_, c_, d_] := Module[{},
sol = {c1, c2, c3, c4} /.
Assuming[
c1 ∈ Reals && c2 ∈ Reals &&
c3 ∈ Reals && c4 ∈ Reals && c1 >= 0 &&
c2 >= 0 && c3 >= 0 && c24 >= 0,
FindRoot[{(Integrate[f[x], {x, c1, c2}] +
Integrate[f[x], {x, c3, c4}]) == α,
f[c1] == f[c2] == f[c3] == f[c4]}, {{c1, a}, {c2, b}, {c3,
c}, {c4, d}}, MaxIterations -> 1000]];
Show[Plot[f[x], {x, sol[[1]], sol[[2]]}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All, Filling -> Axis,
FillingStyle -> LightBlue],
Plot[f[x], {x, sol[[3]], sol[[4]]}, Axes -> {True, False},
AxesOrigin -> {0, 0}, PlotRange -> All, Filling -> Axis,
FillingStyle -> LightBlue], Plot[f[x], {x, 0, 30}],
Graphics[{Arrowheads[{-0.02, 0.02}],
Arrow[{{sol[[1]], f[sol[[1]]]}, {sol[[2]], f[sol[[2]]]}}],
Arrow[{{sol[[3]], f[sol[[3]]]}, {sol[[4]], f[sol[[4]]]}}],
Text[Round[sol[[1]], 0.01], {sol[[1]] - 0.5, f[sol[[1]]]}],
Text[Round[sol[[2]], 0.01], {sol[[2]] + 0.6, f[sol[[2]]]}],
Text[Round[sol[[3]], 0.01], {sol[[3]] - 0.6, f[sol[[3]]]}],
Text[Round[sol[[4]], 0.01], {Last@sol + 0.6, f[sol[[4]]]}],
Text[Round[α 100] "% HDI", {Mean[{sol[[3]], sol[[4]]}],
f@Mean[{sol[[3]], sol[[4]]}]/2}]}]]]
hDI[0.8, 5, 11, 17, 21]
