1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-12 17:26:17 +00:00

Edit the method

This commit is contained in:
asmsuechan
2017-05-23 15:27:22 +09:00
parent d4865adf6a
commit 908cd7a890

View File

@@ -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