Building a Structured Outline [closed]

In a fictional document management system, input documents are structured with weighted headings. Lowest weighted headings are the most important.

This is a sample document:

H2 Kinds of Birds

H3 The Finch

H3 The Swan

H2 Habitats

H3 Wetlands

From this document we would like to produce an outline using nested ordered lists in HTML, which would look like this when rendered:

1. Kinds of Birds
1. The Finch
2. The Swan
2. Habitats
1. Wetlands

Your code only needs to take the input list and transform it into the expected data structure, which will be printed.

closed as unclear what you're asking by Xcali, Stephen, wastl, Jo King, ArnauldMay 11 at 23:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• When you say "using nested ordered lists in HTML" do you mean we need to produce HTML? If so could you define its form for us? (Or may we just indent using a space (or a tab?)?) – Jonathan Allan May 11 at 20:37
• Can the titles be assumed to only contain letters and spaces? – ArBo May 11 at 21:06
• Hi and welcome to codegolf! To avoid having to answer questions like those you received, please note that we have a sandbox for proposed challenges which allows you to receive feedback before posting. As is you are missing a few important details, like those already asked about, and things like what the highest header level there will be (or if it is indefinite). – FryAmTheEggman May 11 at 21:26
• May the level be greater than $9$? – Arnauld May 11 at 23:06
• Are we guaranteed to always have level $L+1$ between levels $L$ and $L+2$? Are we supposed to return valid HTML? (with all trailing </ol> tags) – Arnauld May 11 at 23:35

Jelly, 53 50 bytes

Ḋœṡ¥€⁶ZµḢVØ0jI>0ẋ"AƲị“<ol>“</ol>”żṪ“<li>“</li>”jⱮƊ


Try it online!

A monadic link taking a list of strings as input and outputting an HTML fragment with nested ordered lists. Should handle arbitrarily deep nesting of lists and return a syntactically valid HTML fragment.

Example:

H1 All About Birds
H2 Kinds of Birds
H3 The Finch
H3 The Swan
H2 Habitats
H3 Wetlands
H4 Types of wetlands
H5 Very wet wetland
H3 Coast
H2 Sharks


yields:

<ol><li>All About Birds</li><ol><li>Kinds of Birds</li><ol><li>The Finch</li><li>The Swan</li></ol><li>Habitats</li><ol><li>Wetlands</li><ol><li>Types of wetlands</li><ol><li>Very wet wetland</li></ol></ol><li>Coast</li></ol></ol><li>All about fish</li><ol><li>Sharks</li></ol></ol>