mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-12 17:26:17 +00:00
Add findTitle as a module
This commit is contained in:
32
browser/lib/findNoteTitle.js
Normal file
32
browser/lib/findNoteTitle.js
Normal file
@@ -0,0 +1,32 @@
|
||||
export function find (value) {
|
||||
let splitted = value.split('\n')
|
||||
let title = null
|
||||
let isMarkdownInCode = false
|
||||
|
||||
for (let i = 0; i < splitted.length; i++) {
|
||||
let trimmedLine = splitted[i].trim()
|
||||
if (trimmedLine.match('```')) {
|
||||
isMarkdownInCode = !isMarkdownInCode
|
||||
} else if (isMarkdownInCode === false && trimmedLine.match(/^# +/)) {
|
||||
title = trimmedLine.substring(1, trimmedLine.length).trim()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (title == null) {
|
||||
title = ''
|
||||
for (let i = 0; i < splitted.length; i++) {
|
||||
let trimmedLine = splitted[i].trim()
|
||||
if (trimmedLine.length > 0) {
|
||||
title = trimmedLine
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
export default {
|
||||
find
|
||||
}
|
||||
Reference in New Issue
Block a user