Have worked in dozens of languages but new to Python.
My first (maybe second) question here, so be gentle...
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.
For a 2-level unordered list like this...
- First level
- Second level
Tomboy/GNote uses something like...
<list><list-item>First level<list><list-item>Second level</list-item></list></list-item></list>
However, the Zim personal wiki wants that to be...
* First level
* Second level
... with leading tabs.
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...
count * "text"
Thus, it looks like there should be a way to do something like...
newnote = re.sub("<list>", LEVEL * "\t", oldnote)
Where LEVEL is the ordinal (occurrance) of <list>
in the note. It would thus be 0
for the first <list>
incountered, 1
for the second, etc.
LEVEL would then be decremented each time </list>
was encountered.
<list-item>
tags are converted to the asterisk for the bullet (preceded by newline as appropriate) and </list-item>
tags dropped.
Finally... the question...
- How do I get the value of LEVEL and use it as a tabs multiplier?