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

Expose .Name and .Position within codeblock render hook #9574

Closed
jmooring opened this issue Feb 26, 2022 · 5 comments
Closed

Expose .Name and .Position within codeblock render hook #9574

jmooring opened this issue Feb 26, 2022 · 5 comments

Comments

@jmooring
Copy link
Member

Primarily for using with errorf, erroridf, and warnf. Of the two values, .Position is the most important. Usage:

{{ errorf "The language you have specified for the %q template is invalid. See %s" .Name .Position }}

The language you have specified for the "render-codeblock" template is invalid. See "/home/user/project/content/_index.md:20:1"

@bep
Copy link
Member

bep commented Feb 26, 2022

Expose .Name and .Position

So, the issue title makes this look easy, and I initial thought that, too, but this needs to be calculated. I have the byte offset from Goldmark, but there is a potential big diff in the source Goldmark sees and the original (considering front matter and shortcodes), so those offsets are not useful. Since this is (hopefully) only used for error situations, we could probably do a string search in the original source on demand. I agree that this would be useful.

bep added a commit to bep/hugo that referenced this issue Feb 26, 2022
But note that this is not particulary fast and the recommendad usage is error logging only.

Updates gohugoio#9574
@bep
Copy link
Member

bep commented Feb 26, 2022

I appended Position to #9575 -- please take it for a spin ...

As to .Name; I understand the need, but I find it a little bit foreign and confusing to add that to the interface.

@jmooring
Copy link
Member Author

I understand the need, but I find it a little bit foreign and confusing to add that to the interface.

The .Position value will be enough to help the user resolve the error in most cases. The template name would be nice to have, but I understand that might be more difficult. Thank you for this. I'll test #9575 in a few minutes.

bep added a commit to bep/hugo that referenced this issue Feb 26, 2022
But note that this is not particulary fast and the recommendad usage is error logging only.

Updates gohugoio#9574
bep added a commit to bep/hugo that referenced this issue Feb 26, 2022
But note that this is not particulary fast and the recommendad usage is error logging only.

Updates gohugoio#9574
bep added a commit to bep/hugo that referenced this issue Feb 26, 2022
But note that this is not particulary fast and the recommendad usage is error logging only.

Updates gohugoio#9574
bep added a commit that referenced this issue Feb 26, 2022
But note that this is not particulary fast and the recommendad usage is error logging only.

Updates #9574
@bep
Copy link
Member

bep commented Feb 28, 2022

Closing this for now.

@bep bep closed this as completed Feb 28, 2022
@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 Mar 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants