# Display external source code with highlight

**URL:** <https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723>\
**Category:** support\
**Created:** [January 31, 2023, 11:33am UTC](https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723 "2023-01-31T11:33:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ITler](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/itler/32/17799_2.png) [@ITler](https://discourse.gohugo.io/u/ITler)\
**Post date:** [January 31, 2023, 11:33am UTC](https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723/1 "2023-01-31T11:33:29Z")

</div>

Dear Hugo pros,

I would like to embed code with proper highlighting from an external source, means:

- read external file determined by an URL, i.e. `readFile $url`
- use the capabilities of `highlight` function
- even be able to only render a part of the external file by specifying a `lineStart` and `lineEnd`
- directly embed it via shortcode to my regular hugo markdown content

basically something like:

```auto
{{< highlight go "url=https://foo.bar/baz.go,lineStart=3,lineEnd=20,hl_lines=8 15-17" >}}
{{< /highlight >}}

```

I am not yet familiar with the power of Hugo, so I didn’t find out how I could realize this.  
Is this possible these days and if yes, how? 🙂

Thank you and kind regards

ITler

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 31, 2023, 8:55pm UTC](https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723/2 "2023-01-31T20:55:58Z")

</div>

General approach:

1. Use `resources.GetRemote` to capture the file
2. Split the file into an array of lines
3. Iterate through the lines, beginning at the “start” line and ending at the “stop” line
4. Pass the result through the `highlight` function

---

<div class="post-metadata">

**Author:** ![ITler](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/itler/32/17799_2.png) [@ITler](https://discourse.gohugo.io/u/ITler)\
**Post date:** [February 1, 2023, 7:55am UTC](https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723/3 "2023-02-01T07:55:53Z")

</div>

Ah yes… I missed the `resources.GetRemote`… I will go this road.

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [February 3, 2023, 7:56am UTC](https://discourse.gohugo.io/t/display-external-source-code-with-highlight/42723/4 "2023-02-03T07:56:16Z")

</div>

Closed on February 3, 2023, 7:56am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
