Details

Applies to
1.5.4
Purpose
Disables automatic indentation of paragraphs based on initial whitespace.
Description

When MoinMoin encounters "pure" indentation--an indented paragraph without * or 1. markup--it "indents" the paragraph by treating it as a list item, opening a new list if required. MoinMoin already has an unbulleted list marked up with a dot (.), which performs the exact same function. This patch removes support for pure indentation, requiring a number, bullet or dot be used to create a list item.

Removing pure indentation gains you two things:

  1. You may add multiple paragraphs to a list item. Currently, a second paragraph is joined with the previous paragraph, or it is indented, depending on initial whitespace. Note that it is already possible to add certain block items inside a list item, such as a pre block, which appear at the same level as the main list item. This patch extends that to allow a second paragraph to be created at the same level as well.

    /!\ Try using an empty line (as usual for a new paragraph) and indent next paragraph by the same amount of space as you have before your "1.". Like you see HERE. :) As you can see, this suggestion does not work. It happens to work in the previous case because the parser starts a new paragraph when you have an icon at the beginning or the end, for whatever reason. In the general case, the lines will be joined, as HERE. Try adding a smiley to the beginning or end of this sentence and watch a p tag get output.

    In fact, I just noticed that any markup, including backticks or italics, will cause a p tag to be output around the entire paragraph (!), correctly rendering the output, like HERE. This appears to me to be a genuine bug. If it were fixed, it would eliminate this reason #1.

  2. List text which is vertically aligned for aesthetic purposes, as you might write it in a plain text file, is not indented. This makes importing plain text simpler.

With this change, the following markup:

 1. This is a
    single paragraph

    This is another paragraph
 1. This is the final
    list item

will render approximately like so:

 1. This is a single paragraph

    This is another paragraph

 2. This is the final list item

Without this patch, it is possible to make it appear that a second paragraph is embedded inside another list item. You would do this as follows:

 1. This is a
    single paragraph

 .  This is another paragraph
 1. This is the final list item

While it happens to render correctly on the page, semantically, it is invalid. The additional paragraph becomes a separate, unbulleted list item, instead of a paragraph embedded within the first item. It is unlikely to convert correctly to another format, such as DocBook.

There is another patch floating around which converts a "pure" indented paragraph within a list item into a separate unbulleted list item. This has the same semantic problem.

Problems

There are two issues with this patch.

First, the ability to "blockquote" with pure indentation is gone. Since creating a blockquote is (again) done with an unbulleted list, blockquoting was already semantically incorrect, and I can live with the loss. Also, you can still manually create an unbulleted list using dot (.). In my opinion, blockquoting should have its own markup syntax which outputs an HTML blockquote tag.

Second, normal list item text will be surrounded with paragraph (p) tags when output. The output is still valid HTML, but it's probably not ideal. This is mainly due to my inexperience with the Moin codebase and can probably be corrected.

Patch

   1 --- moin-1.5.4/MoinMoin/parser/wiki.py.orig	2006-05-11 11:24:00.000000000 -0500
   2 +++ moin-1.5.4/MoinMoin/parser/wiki.py	2006-07-31 14:37:28.000000000 -0500
   3 @@ -461,15 +461,7 @@
   4      
   5      def _indent_repl(self, match):
   6          """Handle pure indentation (no - * 1. markup)."""
   7 -        result = []
   8 -        if not (self.in_li or self.in_dd):
   9 -            self._close_item(result)
  10 -            self.in_li = 1
  11 -            css_class = None
  12 -            if self.line_was_empty and not self.first_list_item:
  13 -                css_class = 'gap'
  14 -            result.append(self.formatter.listitem(1, css_class=css_class, style="list-style-type:none"))
  15 -        return ''.join(result)
  16 +        return ""
  17  
  18      def _li_none_repl(self, match):
  19          """Handle type=none (" .") lists."""
  20 @@ -545,7 +537,7 @@
  21                      self.in_li = 1
  22                  
  23          # Open new list, if necessary
  24 -        if self._indent_level() < new_level:
  25 +        if list_type and self._indent_level() < new_level:
  26              self.list_indents.append(new_level)
  27              self.list_types.append(list_type)
  28  
  29 @@ -879,7 +871,7 @@
  30          ###result.append('<span class="info">[no match, add rest: <tt>"%s"<tt>]</span>' % line[lastpos:])
  31          
  32          # Add paragraph with the remainder of the line
  33 -        if not (self.in_pre or self.in_li or self.in_dd or self.inhibit_p or
  34 +        if not (self.in_pre or self.inhibit_p or
  35                  self.formatter.in_p) and lastpos < len(line):
  36              result.append(self.formatter.paragraph(1, css_class="line874"))
  37          result.append(self.formatter.text(line[lastpos:]))
  38 @@ -937,6 +929,7 @@
  39          self.request.clock.start('compile_huge_and_ugly')        
  40          scan_re = re.compile(rules, re.UNICODE)
  41          number_re = re.compile(self.ol_rule, re.UNICODE)
  42 +        bullet_re = re.compile("^\s+[*.]\s", re.UNICODE)
  43          term_re = re.compile(self.dl_rule, re.UNICODE)
  44          indent_re = re.compile("^\s*", re.UNICODE)
  45          eol_re = re.compile(r'\r?\n', re.UNICODE)
  46 @@ -1043,7 +1036,7 @@
  47                  # Check indent level
  48                  indent = indent_re.match(line)
  49                  indlen = len(indent.group(0))
  50 -                indtype = "ul"
  51 +                indtype = None
  52                  numtype = None
  53                  numstart = None
  54                  if indlen:
  55 @@ -1058,6 +1051,8 @@
  56                              numstart = None
  57  
  58                          indtype = "ol"
  59 +                    elif bullet_re.match(line):
  60 +                        indtype = "ul"
  61                      else:
  62                          match = term_re.match(line)
  63                          if match:

moin-1.5.4-parindent-2.patch

Discussion

Updated patch to make sure that dot (.) opens a new list when required. -- JimUrsetto 2006-07-31 19:43:43

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/DisablePureIndentation (last edited 2007-10-29 19:17:16 by localhost)