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

Refactor the dirty code

This commit is contained in:
Sosuke Suzuki
2017-03-18 01:58:15 +09:00
parent 034f46792b
commit b577ca2bc2

View File

@@ -65,22 +65,16 @@ class MarkdownNoteDetail extends React.Component {
findTitle (value) {
let splitted = value.split('\n')
let title = null
let markdownInCode = false
let isMarkdownInCode = false
for (let i = 0; i < splitted.length; i++) {
let trimmedLine = splitted[i].trim()
if (trimmedLine.match('```')){
if (markdownInCode) {
markdownInCode = false
} else {
markdownInCode = true
}
isMarkdownInCode = !isMarkdownInCode
} else {
if(!markdownInCode) {
if (trimmedLine.match(/^# +/)){
title = trimmedLine.substring(1, trimmedLine.length).trim()
break
}
if(isMarkdownInCode === false && trimmedLine.match(/^# +/)) {
title = trimmedLine.substring(1, trimmedLine.length).trim()
break
}
}
}