I\'m using the Maruku markdown processor. I\'d like this
*blah* blah \"blah\" in [markdown](blah)
I built an express server with a library called Showdown that converts markdown to HTML, and also will let you use HTML in your markdown file, and this is how I am able to use javascript and also link to my css file.
TOC.md
<script src="/js/toc"></script>
server.js
app.get('/js/toc', (req, res) => {
fs.readFile(path.join(__dirname, 'public', 'js', 'toc.js'), 'utf-8', (err, data) => {
if(err) throw err;
res.set({
'Content-Type': 'text/javascript'
})
res.send(data)
})
})
Or you could do it using express static middleware. You would just need to put your javascript file inside a folder called public.
TOC.md
<script src="/static/js/toc.js"></script>
server.js
app.use('/static', express.static('public'))
A good idea is to have local and cloud js sources separated:
In the post file:
cloudjs:
- //cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js
- //cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js
localjs:
- datamaps.world.min.js
- custom.js
In the default file after footer inclusion:
{% for js in page.cloudjs %}
<script type="text/javascript" src="{{ js }}"></script>
{% endfor %}
{% for js in page.localjs %}
<script type="text/javascript" src="{{ "/assets/scripts/" | prepend: site.baseurl | append: js }}"></script>
{% endfor %}
Just indent the first line contains < script > tag.
I had this same problem, but I managed to get JavaScript to appear in my code by putting a newline after the opening tag.
To my experience, markdown will outpus javascript text as plain text as long as you remove the code formatting that may confuse markdown.
Basically what I do is to review the generated html and find out what extra tags are inserted in between my javascript code by markdown. And remove the formatting that generates the extra tag.
I found that escaping the closing '>' symbol in both, the opening and closing 'script' tags, will display it correctly, for example:
If you type the follwing:
<script\>... javascript code...</script\>
It will be rendered like this:
<script>... javascript code...</script>
That's just my two cents.