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

anchorlinenos and lineanchors attributes do not work when using with code fences #9385

Closed
kaushalmodi opened this issue Jan 14, 2022 · 9 comments · Fixed by #9562
Closed

Comments

@kaushalmodi
Copy link
Contributor

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.92.0-B3549403 linux/amd64 BuildDate=2022-01-12T08:23:18Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Hugo Discourse discussion

https://discourse.gohugo.io/t/bug-anchorlinenos-true-attribute-doesnt-work-when-using-code-fences/36564

Reproducible example

Steps to reproduce the problem

git clone https://gitlab.com/hugo-mwe/hugo-mwe
cd hugo-mwe
git checkout anchorlinenos
./srv.sh

Analysis

It looks like the anchorlinenos and lineanchors attributes get passed on as-is to the rendered HTML without being treated as special attributes for creating line number hyperlinks.

I see this when I look at the source of the above test HTML page:

image

Possibly related code:

// Attributes with special meaning that does not make sense to render in HTML.
attributeExcludes = map[string]bool{
"linenos": true,
"hl_lines": true,
"linenostart": true,
}

The link anchoring feature was added in fb0f2cc but the new attributes probably still need to be added in render_hooks.go. /cc @fjorgemota

@jmooring
Copy link
Member

jmooring commented Jan 14, 2022

When using code fences, the available options are limited by the yuin/goldmark-highlighting module (upstream).

The hl_style option should be added to the attributeExcludes map (separate issue #9390).

More info:
https://discourse.gohugo.io/t/36564/3

@kaushalmodi
Copy link
Contributor Author

I really wanted to move away from using the highlight shortcode completely because of #4717. But now I will use it only when I need to use anchorlinenos.

I'll close this issue given that this is recognized as an expected behavior.

@jmooring
Copy link
Member

But now I will use it only when I need to use anchorlinenos

Or set the default in site configuration:

[markup.highlight]
anchorLineNos = true

@kaushalmodi
Copy link
Contributor Author

@jmooring

Or set the default in site configuration

Yeah, I realized that that worked. But my sites have hundreds of code blocks and I don't want to enable the anchors for every line.

That makes me think.. why does enabling that variable in site config work even for code fences?

@kaushalmodi
Copy link
Contributor Author

I think that if Hugo makes the anchorLineNos=true value propagate from the code fence attribute to wherever it needs to set, then this issue will be resolved. Because setting that var in the global site config definitely works.

@kaushalmodi kaushalmodi reopened this Jan 14, 2022
@kaushalmodi
Copy link
Contributor Author

@bep Can you please take a look at this?

Is it possible to make this work by any change from the Hugo side?

```emacs-lisp { linenos=table, anchorlinenos=true, lineanchors=org-coderef--xyz }
(save-excursion
   (goto-char (point-min))
```

Right now, the line anchors don't get enabled if we use code fences; they work only with the highlight shortcode.

  1. I am seeing that you are refactoring a lot of code around goldmark code block rendering and I am hoping that this is a good time to fix this while you are working on that code base.
  2. I haven't seen any response on [feature request] Support for linkable line numbers as supported by Chroma yuin/goldmark-highlighting#25.

@bep
Copy link
Member

bep commented Feb 24, 2022

There are now 1 handling of this config so I assume that your case will now just work, but I would soonish merge my work into master branch, and would appreciate if "someone else" could verify this then.

@kaushalmodi
Copy link
Contributor Author

@bep Thanks! Yes, the latest master has fixed this bug. To avoid regression, I added a small test in #9562. The test passed locally, but is failing in the CI for a reason I don't understand.

kaushalmodi added a commit to kaushalmodi/hugo that referenced this issue Feb 24, 2022
@bep bep closed this as completed in #9562 Feb 24, 2022
bep pushed a commit that referenced this issue Feb 24, 2022
kaushalmodi added a commit to kaushalmodi/ox-hugo that referenced this issue Mar 1, 2022
Now that Hugo issue gohugoio/hugo#9385 is
fixed in Hugo
v0.93.0 (https://github.com/gohugoio/hugo/releases/tag/v0.93.0), this
workaround (of using the `highlight` shortcode only when coderefs were
used) is no longer needed.

This is "minor" breaking because the coderefs feature was introduced
very recently and so I doubt if anyone is still using this :D

If users want to use coderefs, they need to upgrade Hugo to v0.93.0

Documentation for coderef support: https://ox-hugo.scripter.co/doc/source-blocks/#code-references
@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 18, 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.

3 participants