Embed javascript in markdown

后端 未结 11 2553
[愿得一人]
[愿得一人] 2020-12-13 02:23

I\'m using the Maruku markdown processor. I\'d like this

*blah* blah \"blah\" in [markdown](blah)



        
11条回答
  •  盖世英雄少女心
    2020-12-13 02:37

    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

    
    

    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

    
    

    server.js

    app.use('/static', express.static('public'))
    

提交回复
热议问题