Skip to content
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

Add top level 1 heading as bookmark title suggestion #293

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

amohamed11
Copy link
Contributor

Added basic top level 1 # heading extraction to suggest it as title for bookmark. I'm a regex newbie, but this was the best regex I could come up with that handled most cases that I tested for. Any regex wizardry advice is welcome.

Closes #267

@makew0rld
Copy link
Owner

Thanks for your PR, this looks simple and nice! It may be replaced once #182 is implemented, but that's not happening any time soon.

However, I think your regex is faulty. I played around and came up with (?m)^#[^#][\t ]*[^\s].*$ which I think is better. Anything can be in a header, but your regex disallows Unicode symbols. It also matches across newlines due to use of \s.

If you didn't know already, you can test and play with your regex at https://regex101.com/. It's a great site and very handy for understanding regex and creating your own.

If you don't spot any issues with my regex, you can add it to this PR and I'll merge it after testing.

@amohamed11
Copy link
Contributor Author

@makeworld-the-better-one ah good catch on the unicode, completely forgot to test for that. I tested your regex on a few examples, and it seemes to work well. I've updated the regex and amended the commit to keep things small. Let me know if there is anything else.

@makew0rld
Copy link
Owner

Thanks for this, works great! Will merge now. In the future, I prefer contributors avoid force-pushes / amending, so what was changed is clear. I will squash the commits after anyway.

@makew0rld makew0rld merged commit 50044dd into makew0rld:master Jan 28, 2022
makew0rld added a commit that referenced this pull request Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When bookmarking a page, suggest a title based on the first level 1 heading
2 participants