/* input e.g. [[ prelude title ----- text title 2 ------- text ]] */ static SS underlinedHeadingSections(S text) { LS lines = lines(text); L l = indicesOfStartingWithTrim(lines, "--"); new LinkedHashMap out; if (nempty(l)) mapPutIfNemptyValue(out, "", rtrim(lines(takeFirst(lines, first(l)-1)))); for i over l: { int i1 = get(l, i); int i2 = or(get(l, i+1), l(lines)+1); S heading = trim(get(lines, i1-1)); out.put(heading, lines(subList(lines, i1+1, i2-1))); } ret out; }