admin管理员组

文章数量:1303281

I'd like to serve javascript scripts and have them run such that people can go to my *.github.io page and see the visualizations there.

Is this possible? If so, how might I embed the javascript into the markdown?

I'd like to serve javascript scripts and have them run such that people can go to my *.github.io page and see the visualizations there.

Is this possible? If so, how might I embed the javascript into the markdown?

Share Improve this question edited Oct 3, 2014 at 6:06 Florin Pop 5,1354 gold badges28 silver badges60 bronze badges asked Oct 3, 2014 at 5:32 lollercoasterlollercoaster 16.5k35 gold badges122 silver badges181 bronze badges 3
  • You can use HTML and Javascript directly in those pages. – Lars Kotthoff Commented Oct 3, 2014 at 9:31
  • how? I didn't think markdown specification had javascript. – lollercoaster Commented Oct 3, 2014 at 13:51
  • What I'm saying is that you don't have to use markdown. You can write plain HTML with Javascript. – Lars Kotthoff Commented Oct 3, 2014 at 19:53
Add a ment  | 

2 Answers 2

Reset to default 8

From the Markdown Syntax Overview:

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.

I'm sure there's a better way to include scripts in your project, but if you really want to embed them in your markdown, there shouldn't be anything stopping you from doing the following:

# This is a title

> this is a blockquote

<script>
  // this is a script that renders a chart
  var chart = d3.select('body').append('svg')
     // ...etc...
</script>

Sounds like you want to set up a bl.ocks:

This is a simple viewer for code examples hosted on GitHub Gist. Code up an example using Gist, and then point people here to view the example and the source code, live!

The main source code for your example should be named index.html. You can also include a README.md using Markdown, and a thumbnail.png for preview. The index.html can use relative links to other files in your Gist; you can also use absolute links to shared files, such as D3, jQuery and Leaflet.

Otherwise, you can embed stuff using <iframe>.

本文标签: github pages serve javascriptd3 visualizationsStack Overflow