Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting HTML list (<li>) to tabs (i.e. indentation)
    primarykey
    data
    text
    <p>Have worked in dozens of languages but new to Python.</p> <p>My first (maybe second) question here, so be gentle...</p> <p>Trying to efficiently convert HTML-like markdown text to wiki format (specifically, Linux Tomboy/GNote notes to Zim) and have gotten stuck on converting lists. </p> <p>For a 2-level unordered list like this...</p> <ul> <li>First level <ul> <li>Second level</li> </ul></li> </ul> <p>Tomboy/GNote uses something like...</p> <p><code>&lt;list&gt;&lt;list-item&gt;First level&lt;list&gt;&lt;list-item&gt;Second level&lt;/list-item&gt;&lt;/list&gt;&lt;/list-item&gt;&lt;/list&gt;</code></p> <p>However, the Zim personal wiki wants that to be...</p> <pre><code>* First level * Second level </code></pre> <p>... with leading tabs.</p> <p>I've explored the regex module functions re.sub(), re.match(), re.search(), etc. and found the cool Python ability to code repeating text as...</p> <pre><code> count * "text" </code></pre> <p>Thus, it looks like there should be a way to do something like...</p> <pre><code> newnote = re.sub("&lt;list&gt;", LEVEL * "\t", oldnote) </code></pre> <p>Where LEVEL is the ordinal (occurrance) of <code>&lt;list&gt;</code> in the note. It would thus be <code>0</code> for the first <code>&lt;list&gt;</code> incountered, <code>1</code> for the second, etc.</p> <p>LEVEL would then be decremented each time <code>&lt;/list&gt;</code> was encountered.</p> <p><code>&lt;list-item&gt;</code> tags are converted to the asterisk for the bullet (preceded by newline as appropriate) and <code>&lt;/list-item&gt;</code> tags dropped.</p> <p>Finally... the question...</p> <ul> <li>How do I get the value of LEVEL and use it as a tabs multiplier?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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