question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to import code from external file into a codeblock?

See original GitHub issue

Is there a built in or recommended way to inline code from an external file in a codeblock for a markdown content page? I want to store a code snippet in a source file, but inline it in my markdown. Currently I’m able to load the code with the following:

<template>
  <div class="nuxt-content-highlight">
    <pre class="line-numbers"><code>{{code}}</code></pre>
  </div>
</template>

<script>
import raw from "@/assets/code/my_code_file";
export default {
  data {
    return { code: raw }
  }
}
</script>

which “works” and I could create a component, but it feels like I’m reinventing the wheel. I hardly found anything about external file loading in nuxt, much less for nuxt-content within markdown. Ideally I’d have a markdown file like the following:

# My markdown file

```
{ include assets/code/my_code_file }
```

And nuxt-content would do the heavy lifting for me.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Atinuxcommented, Jan 14, 2021

Could be nice to add such component to the docs theme!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Existing Source to CodeBlocks Project - YouTube
Typing and running your first program in CodeBlocks · C++ Libraries For Beginners · Solve Any Pattern Question with This Trick! · HTML...
Read more >
How to start a CodeBlocks project from external code and ...
Create the project, then: right click on the project name on the "Projects" pane; add files recursively.
Read more >
Include External Object File in to Project - Code::Blocks Forums
Well, if it worked with Dev-C++, it can probably be done by going to Build options -> <your target or project> -> Linker...
Read more >
Include code into code blocks from external source files ...
Is there a way to do this with a Lua or Python filter instead? Does anyone have a ready-made boxed-up filter for this...
Read more >
Clear Coding with Modules and Packages in Python
To use a module in an external Python code block, we need to import that specific module into our code structure. To do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found