diff --git a/dist/showdown.js b/dist/showdown.js index 9998a74..b715bc6 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index fc89a37..69b6676 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 72c5778..605d088 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 81b657d..a4022f1 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/subParsers/lists.js b/src/subParsers/lists.js index 1b2c07d..96d08f9 100644 --- a/src/subParsers/lists.js +++ b/src/subParsers/lists.js @@ -3,7 +3,6 @@ */ showdown.subParser('lists', function (text, options, globals) { 'use strict'; - text = globals.converter._dispatch('lists.before', text, options, globals); /** * Process the contents of a single ordered or unordered list, splitting it @@ -123,6 +122,17 @@ showdown.subParser('lists', function (text, options, globals) { return listStr; } + function styleStartNumber (list, listType) { + // check if ol and starts by a number different than 1 + if (listType === 'ol') { + var res = list.match(/^ *(\d+)\./); + if (res && res[1] !== '1') { + return ' start="' + res[1] + '"'; + } + } + return ''; + } + /** * Check and parse consecutive lists (better fix for issue #142) * @param {string} list @@ -140,10 +150,11 @@ showdown.subParser('lists', function (text, options, globals) { if (list.search(counterRxg) !== -1) { (function parseCL (txt) { - var pos = txt.search(counterRxg); + var pos = txt.search(counterRxg), + style = styleStartNumber(list, listType); if (pos !== -1) { // slice - result += '\n<' + listType + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '\n'; + result += '\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '\n'; // invert counterType and listType listType = (listType === 'ul') ? 'ol' : 'ul'; @@ -152,16 +163,19 @@ showdown.subParser('lists', function (text, options, globals) { //recurse parseCL(txt.slice(pos)); } else { - result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '\n'; + result += '\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '\n'; } })(list); } else { - result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '\n'; + var style = styleStartNumber(list, listType); + result = '\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '\n'; } return result; } + /** Start of list parsing **/ + text = globals.converter._dispatch('lists.before', text, options, globals); // add sentinel to hack around khtml/safari bug: // http://bugs.webkit.org/show_bug.cgi?id=11231 text += 'ยจ0'; diff --git a/test/cases/ordered-list-starting-number.html b/test/cases/ordered-list-starting-number.html new file mode 100644 index 0000000..45666bb --- /dev/null +++ b/test/cases/ordered-list-starting-number.html @@ -0,0 +1,12 @@ +
    +
  1. foo
  2. +
  3. bar
  4. +
  5. baz
  6. +
+
+
    +
  1. a
  2. +
  3. b
  4. +
  5. c
  6. +
  7. d
  8. +
diff --git a/test/cases/ordered-list-starting-number.md b/test/cases/ordered-list-starting-number.md new file mode 100644 index 0000000..b5e9fde --- /dev/null +++ b/test/cases/ordered-list-starting-number.md @@ -0,0 +1,10 @@ +5. foo +6. bar +7. baz + +--- + +3. a +2. b +7. c +23. d diff --git a/test/cases/ordered-list-wrong-numbers.md b/test/cases/ordered-list-wrong-numbers.md index 643b57d..2fd21c6 100644 --- a/test/cases/ordered-list-wrong-numbers.md +++ b/test/cases/ordered-list-wrong-numbers.md @@ -1,4 +1,4 @@ - 8. Red + 1. Red 1. Green - 3. Blue + 1. Blue