1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-20 13:11:44 +00:00

Merge pull request #548 from asmsuechan/add-a-module-findTitle

Add a module to find the title
This commit is contained in:
SuenagaRyota
2017-06-07 10:30:46 +09:00
committed by GitHub
4 changed files with 62 additions and 68 deletions

View File

@@ -12,6 +12,7 @@ import ee from 'browser/main/lib/eventEmitter'
import markdown from 'browser/lib/markdown'
import StatusBar from '../StatusBar'
import _ from 'lodash'
import { findNoteTitle } from 'browser/lib/findNoteTitle'
const electron = require('electron')
const { remote } = electron
@@ -63,44 +64,6 @@ class MarkdownNoteDetail extends React.Component {
ee.off('topbar:togglelockbutton', this.toggleLockButton)
}
findTitle (value) {
let splitted = value.split('\n')
let title = null
let isMarkdownInCode = false
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(/^# +/) || 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) {
for (let i = 0; i < splitted.length; i++) {
let trimmedLine = splitted[i].trim()
if (trimmedLine.length > 0) {
title = trimmedLine
break
}
}
if (title == null) {
title = ''
}
}
title = markdown.strip(title)
return title
}
getPercentageOfCompleteTodo (noteContent) {
let splitted = noteContent.split('\n')
let numberOfTodo = 0
@@ -124,7 +87,7 @@ class MarkdownNoteDetail extends React.Component {
note.content = this.refs.content.value
note.tags = this.refs.tags.value
note.title = this.findTitle(note.content)
note.title = markdown.strip(findNoteTitle(note.content))
note.updatedAt = new Date()
this.setState({