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 splitRE template func #2061

Closed
digitalcraftsman opened this issue Apr 8, 2016 · 8 comments
Closed

Add splitRE template func #2061

digitalcraftsman opened this issue Apr 8, 2016 · 8 comments
Labels

Comments

@digitalcraftsman
Copy link
Member

splitRE would work analogous to #2048. Users pass the regular expression, content that should be splitted and an optional third parameter to limit the matches. A slice of strings would be returned.

{{ splitRE "<h2.*?>(.|\n)*?</h2>" .Content }}

It's implementation would upon regexp's split function.

@bep
Copy link
Member

bep commented Apr 8, 2016

Hmm... I think we should think hard before we add more regexp stuff. This is needed to patch shortcomings of Hugo, and it opens up to fairly ineffective pipelines of

{{ index (.Content | splitRe "h1") 0 }}
{{ index (.Content | splitRe "h1") 1 }}

We should solve this properly, I believe there are other issues floating around about getting the different content sections.

@digitalcraftsman
Copy link
Member Author

The reason why I planned to implement both template funcs was to improve the results of the search index. I know that regexp are a bad (and perhaps slow) approach to solve the problem. But the template limit my possibilities.

Maybe you new an alternative way to achieve this.

@bep
Copy link
Member

bep commented Apr 8, 2016

This is the alternative: russross/blackfriday#166

Hugo's speed is one of its main selling points, and is the reason why I spent three hours implementing a emoji parser instead of using an existing slow, memory-consuming and buggy one. It adds up. This function would maybe be fine when used "within reason", but then it ends up in your themes and it becomes the new Hugo benchmark.

@bep
Copy link
Member

bep commented Apr 8, 2016

Regexp is a great thing. But in this case it is the wrong choice.

@digitalcraftsman
Copy link
Member Author

digitalcraftsman commented Apr 8, 2016

As I stated I know that regexp are not my first tool of choice in this case. That why I asked for better alternatives and I share your thoughts.

The linked Blackfriday issue would solve a lot of problems. But the project doesn't seems to be very active (I do not want to blame anyone - it's just an observation).

@DanySK
Copy link

DanySK commented Jun 16, 2021

I would need this now... I need to split a string that may end with Unix or Windows newlines, and by far this would be the easiest way to do it I can think of.

@DanySK
Copy link

DanySK commented Jun 16, 2021

(I will use replaceRE + split as a substitution, I guess that is the intended way to do it...)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants