-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: header extraction improvement (close: #238) #271
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const parseEmojis = str => { | ||
const emojiData = require('markdown-it-emoji/lib/data/full.json') | ||
return str.replace(/:(.+?):/g, (placeholder, key) => emojiData[key] || placeholder) | ||
} | ||
|
||
const unescapeHtml = html => html | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '\'') | ||
.replace(/:/g, ':') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
|
||
const removeMarkdownToken = str => str | ||
.replace(/`(.*)`/, '$1') // `` | ||
.replace(/\[(.*)\]\(.*\)/, '$1') // []() | ||
.replace(/\*\*(.*)\*\*/, '$1') // ** | ||
.replace(/\*(.*)\*/, '$1') // * | ||
.replace(/_(.*)_/, '$1') // _ | ||
|
||
// put here to avoid circular references | ||
const compose = (...processors) => { | ||
if (processors.length === 0) return input => input | ||
if (processors.length === 1) return processors[0] | ||
return processors.reduce((prev, next) => { | ||
return (...args) => next(prev(...args)) | ||
}) | ||
} | ||
|
||
module.exports = compose(unescapeHtml, parseEmojis, removeMarkdownToken) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checking of the
processors.length
seems unnecessary. Perhaps something like this?Or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm? Are you telling me how to write code?
Code should be as easy as possible to understand, don't always think about drag racing.
If you expect me to make a change, first give redux a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ulivz I also prefer easier to read code, but this is open source and @ycmjason is just offering what he thinks might be better code. He is not telling you how to write code and you don't have to be combative about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 Yes, I should say convincing reasons instead of arguing for it.
@ycmjason I'm terribly sorry about my recklessness, and I liked the style what you said above, but, after a long time, I found I always need to think back to what parameters of reduce's callback needs to accept. Until one day I read the source code of Redux, I found it's easier to undestand. so I'd like this style.