From 908cd7a890cfbc8badfc081f5f206dea14df9e3c Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Tue, 23 May 2017 15:27:22 +0900 Subject: [PATCH] Edit the method --- browser/lib/findNoteTitle.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/browser/lib/findNoteTitle.js b/browser/lib/findNoteTitle.js index 23c48342..e7e54868 100644 --- a/browser/lib/findNoteTitle.js +++ b/browser/lib/findNoteTitle.js @@ -3,18 +3,22 @@ export function findNoteTitle (value) { let title = null let isMarkdownInCode = false - for (let i = 0; i < splitted.length; i++) { - let trimmedLine = splitted[i].trim() + splitted.some((line, index) => { + let trimmedLine = line.trim() + let trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim() if (trimmedLine.match('```')) { isMarkdownInCode = !isMarkdownInCode - } else if (isMarkdownInCode === false && trimmedLine.match(/^# +/)) { - title = trimmedLine.substring(1, trimmedLine.length).trim() - break + } else if (isMarkdownInCode === false && (trimmedLine.match(/^# +/) || trimmedNextLine.match('='))) { + if (trimmedNextLine.match('=')) { + title = trimmedLine.substring(0, trimmedLine.length).trim() + } else { + title = trimmedLine.substring(1, trimmedLine.length).trim() + } + return true } - } + }) - if (title === null) { - title = '' + if (title == null) { for (let i = 0; i < splitted.length; i++) { let trimmedLine = splitted[i].trim() if (trimmedLine.length > 0) { @@ -22,6 +26,9 @@ export function findNoteTitle (value) { break } } + if (title == null) { + title = '' + } } return title