codehike icon indicating copy to clipboard operation
codehike copied to clipboard

Dynamic code mention

Open genert opened this issue 7 months ago • 1 comments

In previous CodeHike, it was possible to do the following:

<CH.Section>
Some text [hover here](focus://code.py#3)

```python code.py
def method():
    print("hello")
    print("world")
``

</CH.Section>

The current version has the following capability - https://codehike.org/docs/code/code-mentions

BUT it requires hard-coding the hover values in CSS styles. Is there a generic way for this as previous versions supported?

genert avatar May 19 '25 14:05 genert

It's possible. The key is in the last paragraph of that page:

If you need a more complex behavior, you could add a React Context Provider to the HoverContainer component and use it to store the current hover state. Then, you can use the useContext hook in the Line component to check if the current line is the one being hovered over.

pomber avatar May 19 '25 15:05 pomber