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

Show how to create an anchor link #1833

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Guide/recipes.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,14 @@ case post of

## Highlight the targeted element

Let's say you have a page with comments, and you link to them with `<a href="#comment-<comment ID>">`.
Let's say you have a page with comments, and you link to them with `<a href="#comment-<comment ID>">`. You can build it like this (assuming you have a `comment.id`):

```haskell
[hsx|
<a { ...[ ("href", "#comment-" ++ show comment.id)
, ("id", "comment-" ++ show comment.id)
]}
|]
mpscholten marked this conversation as resolved.
Show resolved Hide resolved

The browser will scroll to the relevant comment when you follow the link, but let's say you also want to highlight the linked comment — like GitHub does. You could use the `:target` selector, but it doesn't play well with Turbolinks.

Expand Down
Loading