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.

Loading another script from markdown - issues

See original GitHub issue

I have a simple markdown file which includes an external JS file like so:

loadJSFile.md

---
title: "Simple JS test"
---

<script type="text/javascript" src="./test.js"></script>

<button onClick="runTest()">run Test</button>

and the JS file sits in the same directory

test.js

function runTest () {
  console.log('run a test')
}

When I run gatsby develop and load the page, the test.js file is not loaded by the browser, meaning no request is even made, although I do see the script tag in the DOM. Therefore clicking the button results in an error.

Now if I run gatsby build and gatsby serve-build I see a 404 for the test.js file

Any ideas on how to approach this problem would be appreciated. Thank you!

gatsby --version 0.12.45

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
Piyush3dBcommented, Jun 7, 2017

For reference, in issue #312 @stereoboost has posted https://react-styleguidist.js.org/ that is trying to address this. Example markdown file.

mdxc is another example how to approach this.

0reactions
jboldacommented, Jun 5, 2017

@Piyush3dB were you able to figure it out? You can actually use js/jsx directly, and import a markdown file for your text. It becomes a bit of a pain if you want to lace react components within your text though. FYI, any file in /pages with dealt with. Js/x files will be used directly, and markdown will be transformed. Also anything prepended with an underscore will be used, but not put into the pages array. That means you can do _mycontent.md and require/import it into your jsx. It will be transformed to html markup so just dangerously set inner html to put it in your component.

The 1.0 branch is actively discussing how to write jsx in markdown though if you are interested.

I am going to close this as it’s old and the questions are answered, but feel free to ask more questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

16.1 Source external R scripts | R Markdown Cookbook
If your R Markdown document has a large amount of code, you may consider putting some code in external R scripts, and run...
Read more >
Add script tag to markdown file [closed] - Stack Overflow
I am developing document in MKdocs and need to load some script files to my markdown file. How can I add js functions...
Read more >
15 Common Problems with rmarkdown (and some solutions)
15.1 Avoiding problems · 15.2 The errors · 15.3 “Duplication”: Duplicated chunk names · 15.4 “Not what I ordered”: Objects not created in...
Read more >
SDS - Troubleshooting in R Markdown - GitHub Pages
Not including all the packages you need for your code. This error will occur if you try to use a function in a...
Read more >
R Markdown
Turn your analyses into high quality documents, reports, presentations and dashboards with R Markdown. Use a productive notebook interface to weave together ...
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