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