From e63fe52e5b43a195eed9bdb45aadfacf71cfd890 Mon Sep 17 00:00:00 2001 From: Aria Buckles Date: Wed, 13 Mar 2019 13:46:28 -0700 Subject: [PATCH] Flow: Fix flow errors on flow 0.94.0 --- package.json | 2 +- simple-markdown.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 23c80b4..0ab372d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-markdown", - "version": "0.4.2", + "version": "0.4.3", "description": "Javascript markdown parsing, made simple", "main": "simple-markdown.js", "scripts": { diff --git a/simple-markdown.js b/simple-markdown.js index d8bb509..00c0d27 100644 --- a/simple-markdown.js +++ b/simple-markdown.js @@ -20,7 +20,7 @@ * the wonderful [marked.js](https://github.com/chjj/marked) * * LICENSE (MIT): - * New code copyright (c) 2014 Khan Academy. + * New code copyright (c) 2014-2019 Khan Academy & Aria Buckles. * * Portions adapted from marked.js copyright (c) 2011-2014 * Christopher Jeffrey (https://github.com/chjj/). @@ -47,11 +47,9 @@ /*:: // Flow Type Definitions: -type Capture = { - '0': string, - index?: number, - [number]: string, -}; +type Capture = + Array & {index: number} | + Array & {index?: number}; type Attr = string | number | boolean; @@ -1023,7 +1021,8 @@ var defaultRules /* : DefaultRules */ = { var lastItemWasAParagraph = false; var itemContent = items.map(function(item, i) { // We need to see how far indented this item is: - var space = LIST_ITEM_PREFIX_R.exec(item)[0].length; + var prefixCapture = LIST_ITEM_PREFIX_R.exec(item); + var space = prefixCapture ? prefixCapture[0].length : 0; // And then we construct a regex to "unindent" the subsequent // lines of the items by that amount: var spaceRegex = new RegExp("^ {1," + space + "}", "gm");