# Line context for GitHub links in onebox

**URL:** <https://meta.discourse.org/t/line-context-for-github-links-in-onebox/156389>\
**Category:** Product Support\
**Created:** [June 30, 2020, 6:55pm UTC](https://meta.discourse.org/t/line-context-for-github-links-in-onebox/156389 "2020-06-30T18:55:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![guildai](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/guildai/32/248544_2.png) [@guildai](https://meta.discourse.org/u/guildai)\
**Post date:** [July 1, 2020, 12:31pm UTC](https://meta.discourse.org/t/line-context-for-github-links-in-onebox/156389/4 "2020-07-01T12:31:09Z")

</div>

In this case I’m stepping the reader through a series of changes to a file. The context is important in each case, whether I’m highlighting one line or many.

The component already highlights one line with context. The case I have here would like that same behavior applied with multiple lines.

I see the sensibility of the current scheme but I think there’s a solid case to support multi-line highlights w/context as well.

If Onebox isn’t already configurable beyond the link itself, it would need to be. Perhaps something like this?

```plaintext
<span
  data-onebox-highlight="true"
  data-onebox-context="5"
  >https://github.com/.../get-started/mnist_mlp.py#L16-L18</span>

```

There’s not much new here other than configuring what the component formats and displays.

Naively, it looks like this would be a backend only change. Consider the differences between these two onebox.json responses:

- [Single line + highlight + context](https://my.guild.ai/onebox.json?url=https%3A%2F%2Fgithub.com%2Fguildai%2Fguildai%2Fblob%2Fmaster%2Fexamples%2Fget-started%2Fmnist_mlp.py%23L18&refresh=true&category_id=14&topic_id=203)
- [Multiple lines only](https://my.guild.ai/onebox.json?url=https%3A%2F%2Fgithub.com%2Fguildai%2Fguildai%2Fblob%2Fmaster%2Fexamples%2Fget-started%2Fmnist_mlp.py%23L16-L18&refresh=false&category_id=3&topic_id=188)

As one might expect, one has context with a `highlight` line and the other does not.

If the [backend](https://github.com/discourse/onebox/blob/master/lib/onebox/mixins/git_blob_onebox.rb) were configurable per request, it’s a matter of applying the existing formatting rules. I see the implementation assumes [one line-to-highlight](https://github.com/discourse/onebox/blob/master/lib/onebox/mixins/git_blob_onebox.rb#L51). The change to support a line range is minimal (e.g. use an array of lines-to-highlight and [check for membership](https://github.com/discourse/onebox/blob/master/lib/onebox/mixins/git_blob_onebox.rb#L146)).

---

_[View the full topic](https://meta.discourse.org/t/line-context-for-github-links-in-onebox/156389)._
