Unordered lists are great and all, but sometimes I need ordered lists to express a sequence of actions.
And ordered lists are also covered in the Creole spec. –Manuel
If you look at Wiki Creole page, you will note that I listed a number of differences that I decided to introduce. This is because I need a working wiki that I can use – practicality beats purity.
I have a number of problems with numbered lists:
<ol> element is not for numbered lists, but for lists in which order matters,Having said that, if anybody comes up with a sane implementation of numbered lists, I might copy it. I haven't seen any so far.
Sorry for being so stubborn with all your feature requests. I hope you will still find Hatta useful without them. – Radomir Dopieralski
You have good points, but I have something to say on some of them:
BTW, how about making lists support multi-line items? It's not difficult I think, it's just a sequence of paragraphs inside a <li> item (I can be utterly wrong here, I don't know hatta's internals and design).
I don't want to start a flame war here, these are just my opinions and I believe hatta is a quite good piece of software. I like it, and with just a little enhancement it could become one of the indispensable tools in my toolbox
– Manuel
This patch has the same level of support for unordered list as for ordered list. Hope it can be integrated
# HG changeset patch
# User Ben
# Date 1259068058 -3600
# Node ID 83b2eb3b83b5510a3401922a546bf2263a3f9f77
# Parent 7bb567d0126752d364b5392596bdfe69240c910f
Add support for ordered list
diff -r 7bb567d01267 -r 83b2eb3b83b5 hatta.py
--- a/hatta.py Wed Nov 25 20:16:47 2009 +0100
+++ b/hatta.py Tue Nov 24 14:07:38 2009 +0100
@@ -743,10 +743,12 @@
"""
bullets_pat = ur"^\s*[*]+\s+"
+ list_pat = ur"^\s*[#]+\s+"
heading_pat = ur"^\s*=+"
quote_pat = ur"^[>]+\s+"
block = {
- "bullets": bullets_pat,
+ "abullets": bullets_pat,
+ "alist": list_pat,
"code": ur"^[{][{][{]+\s*$",
"conflict": ur"^<<<<<<< local\s*$",
"empty": ur"^\s*$",
@@ -824,6 +826,7 @@
self.quote_re = re.compile(self.quote_pat, re.U)
self.heading_re = re.compile(self.heading_pat, re.U)
self.bullets_re = re.compile(self.bullets_pat, re.U)
+ self.list_re = re.compile(self.list_pat, re.U)
self.block_re = re.compile(ur"|".join("(?P<%s>%s)" % kv
for kv in sorted(self.block.iteritems())))
self.code_close_re = re.compile(ur"^\}\}\}\s*$", re.U)
@@ -1109,7 +1112,7 @@
yield u'<h%d id="line_%d">%s</h%d>' % (level, self.line_no,
werkzeug.escape(line.strip("= \t\n\r\v")), level)
- def _block_bullets(self, block):
+ def _block_abullets(self, block):
level = 0
in_ul = False
for self.line_no, line in block:
@@ -1132,6 +1135,29 @@
in_ul = False
yield '</li></ul>'*level
+ def _block_alist(self, block):
+ level = 0
+ in_ol = False
+ for self.line_no, line in block:
+ nest = len(self.list_re.match(line).group(0).strip())
+ while nest > level:
+ if in_ol:
+ yield '<ol>'
+ yield '<ol id="line_%d">' % self.line_no
+ in_ol = True
+ level += 1
+ while nest < level:
+ yield '</li></ol>'
+ in_ol = False
+ level -= 1
+ if nest == level and not in_ol:
+ yield '</li>'
+ content = line.lstrip().lstrip('#').strip()
+ yield '<li>%s%s' % (u"".join(self.parse_line(content)),
+ self.pop_to(""))
+ in_ol = False
+ yield '</li></ol>'*level
+
def _block_quote(self, block):
level = 0
in_p = False
– Ben
The patch above from Ben, appears to have some problems. The patch doesn't support white space before the '#'. Mixing unordered and ordered will confuse the display of list items and indentation of subsequent text may be shifted.
Given this...
PARTIALLY BROKEN:
Ordered list:
# First item
# Second item
## Sub-item
### Sub-sub-item
# Third item
## Sub-item (leading white space **should be** ignored)
### Sub-sub-item (space improves readability)
Yields this...
Ordered list:
1. First item
2. Second item
1. Sub-item
1. Sub-sub-item
3. Third itemThis is worse...
BROKEN:
Mixed list 1:
* First item
* Second item
## Sub-item
*** Sub-sub-item
* Third item
** Sub-item (leading white space is ignored)
*** Sub-sub-item (space improves readability)
Mixed list 2:
# First item
# Second item
** Sub-item
### Sub-sub-item
# Third item
## Sub-item (leading white space is ignored)
### Sub-sub-item (space improves readability)
Thanks for working on this Ben. I too would like ordered lists. Hopefully you can take this to the next level for all of us. - Randy
Ok, for your first request, I can do something. It was pretty nasty from you though … (Alphabetical order in priority list)
About your second one, … Interestingly enough, It's my turn to ask for a use-case, or better, an expected output …
I updated the inlined patch with my current dev version, so that you can see the diff to the current patch in the Hatta diff, smart isn't it ? (I'm even beginning to use Hatta as a review-board @ $paying_job). – Ben
Thanks for the fix. White space before '# item' seems to work. I appreciate whatever functionality I can get… 8^)
I myself don't have any particular use-case for mixing ordered and unordered list items, although there no doubt are some. Mixed lists are supported by some other Wikis so I added a test case to see what would happen…
The list is scrambled, which is what I'd expect if mixing is not supported (but it should be documented as such). What is surprising (a worse problem) is that all subsequent content is right shifted (heading, text, etc.), even though its far removed from the markup that caused the problem. Yes, I can catch and correct the problem, but naive authors could easily be mystified (assuming they catch it at all).
Would it be possible to add some error recovery to reset the indent, once a non-list item is encountered?
Ordered list support (especially mixed with unordered) is a tough problem in general, which is probably why initial support was deferred.
My apologies if my initial comments were poorly phrased. They were a cut-n-paste from a new help page and therefore were targeting a different audience.
Cheers… - Randy
Thanks for the hard work. By the way, I can create a mercurial repository with a branch of hatta for you, so that we can merge it later when it's ready and tested. This goes about the file tree patch too. What do you think? – Radomir Dopieralski
I like the idea of a branch in the repository. It would allow us to share, evaluate and refine wacky ideas, with less chance of clobbering the robust core code.
Thanks - Randy
Sorry for the delay, the repositories are created at http://hg.hatta-wiki.org now. – Radomir Dopieralski
Thanks, I'm only wondering what's the goal of those repository: For you to pull from them when we're done, or you'll anyway generate a clean patch before importing ?
Reason I'm asking is just to know what to put in it (Do I have push-right actually ?):
BTW, feel free to move this thread to another page as it is a bit off-topic
– Ben
Ideally I'd want to merge the repositories when we are happy with the result. You should have all the necessary rights. I think that it's best to just work normally in this repository: commit your changes locally and push when you have something you want us to test. It seems that commiting one huge patch defeats the idea of a repository. I will try to keep the repositories sychronized with the development version as far as possible. – Radomir Dopieralski
Don't worry about synchronizing, I can pull from -dev and push there … You might already have noticed three little patches (not ordered-list related) there. If you could take a look at them, I would be grateful …
– Ben
Yes, I saw that you renamed some of the markup groups, but this is somewhat ugly. I know that my hack using alphabetical order was ugly too and you just wanted to avoid accidental breakage, but still. I commited something that might be a better solution: http://hg.hatta-wiki.org/hatta-dev/rev/6d47f7177445 – Radomir Dopieralski
Related patch is pushed here.
– Ben