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 limit option for replaceRE and replace #7586

Closed
dmgawel opened this issue Aug 21, 2020 · 4 comments · Fixed by #7604
Closed

Add limit option for replaceRE and replace #7586

dmgawel opened this issue Aug 21, 2020 · 4 comments · Fixed by #7604

Comments

@dmgawel
Copy link
Contributor

dmgawel commented Aug 21, 2020

I'd like to propose adding an optional limit param for replaceRE and replace functions that works exactly the same as limit in findRE.

Example use case: Process article content and automatically add links to glossary terms for first occurrences of every word from glossary.

cc: @fplanque

@bep bep added Enhancement and removed Proposal labels Aug 21, 2020
@bep bep added this to the v0.75 milestone Aug 21, 2020
@bep
Copy link
Member

bep commented Aug 21, 2020

That sounds good.

@fplanque
Copy link

+1 Use case: Automatically wrap a link on a word (glossary) in the content without creating multiple/redundant occurrences of that link.

@moorereason moorereason changed the title Limit functionality for replaceRE and replace Add limit option for replaceRE and replace Aug 27, 2020
moorereason added a commit to moorereason/hugo that referenced this issue Aug 28, 2020
@moorereason
Copy link
Contributor

I've submitted a PR for consideration that updates replace.

The stdlib regexp package doesn't provide a limited replace function. A proposal issue exists, but there's no movement yet.

bep pushed a commit that referenced this issue Aug 28, 2020
moorereason added a commit to moorereason/hugo that referenced this issue Aug 28, 2020
Go stdlib doesn't contain a limited replace in the regexp package, but
we can accomplish the same thing with ReplaceAllStringFunc.

Fixes gohugoio#7586
@bep bep closed this as completed in #7604 Aug 28, 2020
bep pushed a commit that referenced this issue Aug 28, 2020
Go stdlib doesn't contain a limited replace in the regexp package, but
we can accomplish the same thing with ReplaceAllStringFunc.

Fixes #7586
@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 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants