From ef7b35ab7ddc8ba174e27f063208dbe38ed02e27 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 29 Apr 2011 01:35:29 -0400 Subject: Made lazy ordered lists a settable option. The previous behavior (on) is the default. --- markdown/__init__.py | 13 +++---------- markdown/blockprocessors.py | 2 +- markdown/commandline.py | 6 +++++- tests/misc/some-test.html | 4 ++-- tests/options/lazy_ol_off.html | 18 ++++++++++++++++++ tests/options/lazy_ol_off.txt | 17 +++++++++++++++++ tests/options/test.cfg | 2 ++ 7 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tests/options/lazy_ol_off.html create mode 100644 tests/options/lazy_ol_off.txt create mode 100644 tests/options/test.cfg diff --git a/markdown/__init__.py b/markdown/__init__.py index 2bc7061..9b964b7 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -63,6 +63,7 @@ class Markdown: 'tab_length' : 4, 'enable_attributes' : True, 'smart_emphasis' : True, + 'lazy_ol' : True, } output_formats = { @@ -96,6 +97,7 @@ class Markdown: * tab_length: Length of tabs in the source. Default: 4 * enable_attributes: Enable the conversion of attributes. Default: True * smart_emphsasis: Treat `_connected_words_` intelegently Default: True + * lazy_ol: Ignore number of first item of ordered lists. Default: True """ @@ -353,16 +355,7 @@ def markdown(text, *args, **kwargs): Keyword arguments: * text: Markdown formatted text as Unicode or ASCII string. - * extensions: A list of extensions or extension names (may contain config args). - * safe_mode: Disallow raw html. One of "remove", "replace" or "escape". - * output_format: Format of output. Supported formats are: - * "xhtml1": Outputs XHTML 1.x. Default. - * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1). - * "html4": Outputs HTML 4 - * "html": Outputs latest supported version of HTML (currently HTML 4). - Note that it is suggested that the more specific formats ("xhtml1" - and "html4") be used as "xhtml" or "html" may change in the future - if it makes sense at that time. + * Any arguments accepted by the Markdown class. Returns: An HTML document as a string. diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 5949c00..cc1d2a8 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -346,7 +346,7 @@ class OListProcessor(BlockProcessor): # This is a new list so create parent with appropriate tag. lst = util.etree.SubElement(parent, self.TAG) # Check if a custom start integer is set - if self.STARTSWITH !='1': + if not self.parser.markdown.lazy_ol and self.STARTSWITH !='1': lst.attrib['start'] = self.STARTSWITH self.parser.state.set('list') diff --git a/markdown/commandline.py b/markdown/commandline.py index 3f2e009..caf9288 100644 --- a/markdown/commandline.py +++ b/markdown/commandline.py @@ -49,6 +49,9 @@ def parse_options(): help="print debug messages") parser.add_option("-x", "--extension", action="append", dest="extensions", help = "load extension EXTENSION", metavar="EXTENSION") + parser.add_option("-n", "--no_lazy_ol", dest="lazy_ol", + action='store_false', default=True, + help="Observe number of first item of ordered lists.") (options, args) = parser.parse_args() @@ -65,7 +68,8 @@ def parse_options(): 'safe_mode': options.safe, 'extensions': options.extensions, 'encoding': options.encoding, - 'output_format': options.output_format}, options.verbose + 'output_format': options.output_format, + 'lazy_ol': options.lazy_ol}, options.verbose def run(): """Run Markdown from the command line.""" diff --git a/tests/misc/some-test.html b/tests/misc/some-test.html index 92e7262..b78683f 100644 --- a/tests/misc/some-test.html +++ b/tests/misc/some-test.html @@ -51,7 +51,7 @@ ok with a bunch of items
  • Mostly fruits

    -
      +
      1. Apple
      2. Pare
      @@ -65,4 +65,4 @@ Another code example * Lists and similar stuff > Should be ignored - + \ No newline at end of file diff --git a/tests/options/lazy_ol_off.html b/tests/options/lazy_ol_off.html new file mode 100644 index 0000000..bff1970 --- /dev/null +++ b/tests/options/lazy_ol_off.html @@ -0,0 +1,18 @@ +

      A numbered list from daringfireball:

      +
        +
      1. Bird
      2. +
      3. McHale
      4. +
      5. Parish
      6. +
      +

      Again:

      +
        +
      1. Bird
      2. +
      3. McHale
      4. +
      5. Parish
      6. +
      +

      Now starting with 1:

      +
        +
      1. Bird
      2. +
      3. McHale
      4. +
      5. Parish
      6. +
      \ No newline at end of file diff --git a/tests/options/lazy_ol_off.txt b/tests/options/lazy_ol_off.txt new file mode 100644 index 0000000..611f3a6 --- /dev/null +++ b/tests/options/lazy_ol_off.txt @@ -0,0 +1,17 @@ +A numbered list from daringfireball: + +3. Bird +1. McHale +8. Parish + +Again: + +3. Bird +1. McHale +8. Parish + +Now starting with 1: + +1. Bird +1. McHale +8. Parish diff --git a/tests/options/test.cfg b/tests/options/test.cfg new file mode 100644 index 0000000..d0d3368 --- /dev/null +++ b/tests/options/test.cfg @@ -0,0 +1,2 @@ +[lazy_ol_off] +lazy_ol = False -- cgit v1.2.3