Libraryless. Click here for Pure Java version (2499L/16K).
1 | /* input e.g. [[ |
2 | prelude |
3 | |
4 | title |
5 | ----- |
6 | |
7 | text |
8 | |
9 | title 2 |
10 | ------- |
11 | |
12 | text |
13 | ]] */ |
14 | |
15 | static SS underlinedHeadingSections(S text) { |
16 | LS lines = lines(text); |
17 | L<Int> l = indicesOfStartingWithTrim(lines, "--"); |
18 | new LinkedHashMap<S> out; |
19 | if (nempty(l)) |
20 | mapPutIfNemptyValue(out, "", rtrim(lines(takeFirst(lines, first(l)-1)))); |
21 | for i over l: { |
22 | int i1 = get(l, i); |
23 | int i2 = or(get(l, i+1), l(lines)+1); |
24 | S heading = trim(get(lines, i1-1)); |
25 | out.put(heading, lines(subList(lines, i1+1, i2-1))); |
26 | } |
27 | ret out; |
28 | } |
Began life as a copy of #1021250
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027381 |
Snippet name: | underlinedHeadingSections |
Eternal ID of this version: | #1027381/5 |
Text MD5: | eea379a29a0b94fb0c8c7499c9b5fb9e |
Transpilation MD5: | 28319a6854509edcf60c1f0c9fceb438 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-16 14:21:03 |
Source code size: | 546 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 219 / 323 |
Version history: | 4 change(s) |
Referenced in: | [show references] |