Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert numbered lists text to nested HTML lists
    text
    copied!<p><strong>UPDATE AT THE BOTTOM</strong></p> <p>Maybe somebody could help with this... been struggling with it for days and i'm blocked :/</p> <p>For a content-cleaner solution i'm working in, i'm trying to convert some pure-text numbered lists, like:</p> <pre><code>1 Foo 1.1 Foo 1 1.2 Foo 2 2 Bar 2.1 Bar 1 2.2 Bar 2 2.2.1 Bar 2.1 2.2.2 Bar 2.2 2.3 Bar 3 3 Z Another root item </code></pre> <hr> <p>... into correct nested html lists ...</p> <pre class="lang-html prettyprint-override"><code>&lt;ul&gt; &lt;li&gt;Foo &lt;ul&gt; &lt;li&gt;Foo 1&lt;/li&gt; &lt;li&gt;Foo 2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Bar &lt;ul&gt; &lt;li&gt;Bar 1&lt;/li&gt; &lt;li&gt;Bar 2 &lt;ul&gt; &lt;li&gt;Bar 2.1&lt;/li&gt; &lt;li&gt;Bar 2.2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Bar 3&lt;/li&gt; &lt;/ul&gt; &lt;li&gt;Another root item&lt;/li&gt; &lt;/ul&gt; </code></pre> <hr> <p>Some things that may help:</p> <ul> <li>No need for the result to be correctly indented, just surrounded by the correct html tags</li> <li>No need to locate the list inside another text, can sume i already have only the list</li> <li>No need for great performance, regexp, itaration... whatever works is fine</li> <li>No need for especific language solution, PHP, Python, Javascript, Pseudocode... is fine</li> <li>Can asume " " (space) as the only separator after the "1.2.3 " list text</li> <li>Can asume lines are already in the correct order, no need to order them at all</li> </ul> <hr> <p><strong>UPDATE TLTR (Not homework, but real world usage)</strong></p> <p>Sorry for looking so "homework not done", my fault. English is not my language and i tried to be maybe to concise. What i'm trying to do is to make it easier for my workmates to format text to correct html from unknow sources.</p> <p>Up to day i managed to (you can see the full screenshot here <a href="http://twitpic.com/907aw5/" rel="nofollow">http://twitpic.com/907aw5/</a> as i can't attach images being my first question and no reputation):</p> <ul> <li>I get the original text and do a strip_tags on it to delete any incorrect HTML it can have</li> <li>I insert it into a textarea</li> <li>I integrated a Javascript editor ( Codemirror <a href="http://codemirror.net" rel="nofollow">http://codemirror.net</a> ) with the specifications for HTML </li> <li>I injected an edition bar with the most common tags we use, as my workmates doesn't know a word about HTML </li> <li>As part of the cleaning options, i set two hotkeys that makes an ul / ol of the selected text (breaking in the \n chars)</li> <li>When the user saves, i run HTMLTidy on it for it to became as cleaner as posible (indent, delete propietary tags, etc...)</li> </ul> <p>Just to finish, as you can see in the above screenshot, i have a lot of texts with the 1.2.3 "organization", and it will be of much help to be able to get a nested list solution out of this kind of text.</p> <hr> <p><strong>UPDATE (The especific needs)</strong></p> <p>Now the explanation of "why" i used so many bullets for asumptions:</p> <ul> <li>No need for the result to be correctly indented, just surrounded by the correct html tags (Because after this, when the user hit Save button, i run htmltidy on it, so it get indented)</li> <li>No need to locate the list inside another text, can sume i already have only the list (Because i run the code over the user-selected text in the editor, so i can sume he selected the correct list)</li> <li>No need for great performance, regexp, itaration... whatever works is fine (As it an human-use, point-click, point-click, i don't mind if it takes 0.0001 seconds per use, or 0.1)</li> <li>No need for especific language solution, PHP, Python, Javascript, Pseudocode... is fine (I intend to use it in javascript/jQuery, but what i need is just the logic, as i'm blocked... i can tarnslate it if the solution is in another language)</li> <li>Can asume " " (space) as the only separator after the "1.2.3 " list text (As it is the 99% of my text-cases)</li> <li>Can asume lines are already in the correct order, no need to order them at all (As you can see in the screenshot, that text is human-entered, and i asume they inserted it in the correct order)</li> </ul> <p>Sorry again for not being clear enought, just my first question in Stackoverflow, and i didn't realize it will look like homework, my fault.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload