Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ class MarkdownNoteDetail extends React.Component {
let title = null
let isMarkdownInCode = false

for (let i = 0; i < splitted.length; i++) {
let trimmedLine = splitted[i].trim()
splitted.forEach((line, index) => {
let trimmedLine = line.trim()
let trimmedNextLine = typeof splitted[index + 1] === 'undefined' ? '' : splitted[index + 1].trim()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use just splitted[index + 1] === undefined.

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
}
}
})

if (title == null) {
for (let i = 0; i < splitted.length; i++) {
Expand Down