Skip to content
Merged
Changes from 3 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
10 changes: 7 additions & 3 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ class MarkdownNoteDetail extends React.Component {
findTitle (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(/^# .+/)) {
title = trimmedLine.substring(1, trimmedLine.length).trim()
break
if (trimmedLine.match('```')){
isMarkdownInCode = !isMarkdownInCode
} else if (isMarkdownInCode === false && trimmedLine.match(/^# +/)) {
title = trimmedLine.substring(1, trimmedLine.length).trim()
break
}
Copy link
Contributor

@asmsuechan asmsuechan Mar 16, 2017

Choose a reason for hiding this comment

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

Perhaps you can make this if clause better. Like below:

if(markdownInCode === false && trimmendLine.match(/^# +/)){
  title = trimmedLine.substring(1, trimmedLine.length).trim()
  break
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for correcting my code. I think that it is readble than my code. I'll rewrite it.

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for corrections! And I recognized 1 point. You can reduce 1 indent like this below:

if (trimmedLine.match('```')){
  isMarkdownInCode = !isMarkdownInCode
} else if(isMarkdownInCode === false && trimmedLine.match(/^# +/)) {
  title = trimmedLine.substring(1, trimmedLine.length).trim()
  break
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your advice ! I will fix it soon.

}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code doesn't work. Because there is an extra }. And also the indents are not good 😨

if (trimmedLine.match('```')){
  isMarkdownInCode = !isMarkdownInCode
} else if (isMarkdownInCode === false && trimmedLine.match(/^# +/)) {
  title = trimmedLine.substring(1, trimmedLine.length).trim()
  break
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'll fix it soon.


Expand Down