From 6524ad2442e7f6702957ac4ee2e4eb7a2efcda35 Mon Sep 17 00:00:00 2001 From: Aria Buckles Date: Thu, 7 Sep 2017 13:01:21 -0700 Subject: [PATCH] Headings: Allow # headings to be ended with a single newline Fixes #2 Also see: https://github.com/Khan/simple-markdown/issues/30 Test plan: I made a react-native project and put this in it, and tried the following markdown: # header 1 ## header 2 # header x paragraph --- MarkdownView.js | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/MarkdownView.js b/MarkdownView.js index bdaac12..238466d 100644 --- a/MarkdownView.js +++ b/MarkdownView.js @@ -45,7 +45,7 @@ function mergeRules(baseRules, rules) { return mergedRules } -const IMAGE_LINK = "(?:\\[[^\\]]*\\]|[^\\]]|\\](?=[^\\[]*\\]))*" +const IMAGE_LINK = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*"; const IMAGE_HREF_AND_TITLE = "\\s*?(?:\\s+['\"]([\\s\\S]*?)['\"])?" const IMAGE_SIZE = "(?:\\s+=([0-9]+)x([0-9]+))?\\)\\s*" @@ -58,6 +58,9 @@ const DefaultRules : Rules = Object.freeze(mergeRules( ...Object.entries(DefaultRenders).map(([nodeKey, render]) => ({[nodeKey]: {render: render}})) ), { + heading: { + match: SimpleMarkdown.blockRegex(/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n *)*\n/), + }, image: { match: inlineRegex(new RegExp("^!\\[(" + IMAGE_LINK + ")\\]\\(" + IMAGE_HREF_AND_TITLE + IMAGE_SIZE)), parse: (capture, parse, state): ImageNode => ({ diff --git a/package.json b/package.json index e0c00bf..f286ce2 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "dependencies": { "prop-types": "^15.5.10", "react-native-tabular-grid": "github:Benjamin-Dobell/react-native-tabular-grid", - "simple-markdown": "^0.2.1" + "simple-markdown": "0.3.x" }, "devDependencies": { "flow-bin": "^0.36.0"