# Including program code in pages?

**URL:** <https://discourse.gohugo.io/t/including-program-code-in-pages/7304>\
**Category:** support\
**Created:** [July 4, 2017, 3:19pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304 "2017-07-04T15:19:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wysardry](https://avatars.discourse-cdn.com/v4/letter/w/278dde/32.png) [@Wysardry](https://discourse.gohugo.io/u/Wysardry)\
**Post date:** [July 4, 2017, 3:19pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/1 "2017-07-04T15:19:00Z")

</div>

After a long break from website creation, I am planning one that will have program source code snippets and listings on many of its pages. Would Hugo be suitable for this?

I have created HTML pages by hand in the past, but have no experience of Markdown or Go.

Whilst reading through the online docs I am a little concerned that Hugo might modify some of the code as it processes the pages. For example, it seems that Blackfriday still converts 1/2, 1/4 and 3/4 even with fractions set to false in the configuration.

I want code such as “PRINT 1/2” to remain intact.

Is there a way to ensure that certain text remains as written?

Can Hugo “include” other text files in a page without modifying the content?

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [July 4, 2017, 4:01pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/2 "2017-07-04T16:01:33Z")

</div>

If you want code to remain intact, use code blocks…either with the triple back tick or with the built in highlight shortcode…

---

<div class="post-metadata">

**Author:** ![Wysardry](https://avatars.discourse-cdn.com/v4/letter/w/278dde/32.png) [@Wysardry](https://discourse.gohugo.io/u/Wysardry)\
**Post date:** [July 5, 2017, 12:36pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/3 "2017-07-05T12:36:46Z")

</div>

I don’t need the code to be highlighted, and there isn’t likely to be a suitable language definition if I did (the code will be various BASIC dialects).  
I just need the code to remain unmodified.  
Is there a way to include other text files with Hugo? If not, I may be better off using another generator.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [July 5, 2017, 3:22pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/4 "2017-07-05T15:22:18Z")

</div>

Yes Hugo can include text without modifying it. Check out the `readFile` function. Triple back ticks won’t give you syntax highlighting unless you run it through pygments on the server or through a client side highlighter like highlight.js. Triple back ticks in content are just standard markdown for `<code>` and `<pre>`. As far as output, Hugo Dan write to any text-based format…

---

<div class="post-metadata">

**Author:** ![Wysardry](https://avatars.discourse-cdn.com/v4/letter/w/278dde/32.png) [@Wysardry](https://discourse.gohugo.io/u/Wysardry)\
**Post date:** [July 5, 2017, 5:24pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/5 "2017-07-05T17:24:46Z")

</div>

Maybe I’m not understanding how Hugo works, but don’t functions like readFile only work inside template files? I was hoping to pull in content from a text file in the middle of a markdown file, as that would make life easier whenever the code changed.

---

<div class="post-metadata">

**Author:** ![MunifTanjim](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/muniftanjim/32/17521_2.png) [@MunifTanjim](https://discourse.gohugo.io/u/MunifTanjim)\
**Post date:** [July 5, 2017, 5:49pm UTC](https://discourse.gohugo.io/t/including-program-code-in-pages/7304/6 "2017-07-05T17:49:13Z")

</div>

I think [`shortcodes`](https://gohugo.io/extras/shortcodes/) can use `readFile`. And then, that shortcode is usable in markdown.

I haven’t tried, but a shortcode like this should be possible to create:

`{{< includeText "/path/to/textFile" />}}`

**`_layouts/shortcodes/includeText`** :

```auto
<pre>
  <code>
    {{ readFile ( .Get 0 ) }}
  </code>
</pre>

```
