Embedded javascript?

First of all I’d just like to say I’m really impressed by this application, it feels very polished and has a tonne of features that I wouldn’t expect from an open-source project of this scale so I’d like to say thanks for the effort you’ve been putting in.

I’m a little bit new to javascript and markdown, but I was wondering if it is possible to embed javascript within the desktop application.

For example if I wanted to have the following code snippet:

<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js">

</script>

<div id="viz">

</div>
<script type="text/javascript">

var sampleSVG = d3.select("#viz")
    .append("svg")
    .attr("width", 100)
    .attr("height", 100);    

sampleSVG.append("circle")
    .style("stroke", "gray")
    .style("fill", "white")
    .attr("r", 40)
    .attr("cx", 50)
    .attr("cy", 50)
    .on("mouseover", function(){d3.select(this).style("fill", "aliceblue");})
    .on("mouseout", function(){d3.select(this).style("fill", "white");});
    
</script>

Is there anyway I can have this run locally on the desktop app? My understanding is that since it is based on Electron this should be possible? Embedding more standard HTML works as expected.

It would make a killer app for developers journals if it is possible, I may just be completely missing something why this isn’t possible (or have an error in how I am attempting to use it)?

Thanks again

1 Like

I thought it would work but it seems the script is not loaded when embedded like this in the note. You can probably hack it, for example by executing the script in the “onerror” handler of an image, but otherwise I don’t think this kind of usage will be supported.

It’s a bit weird that the contents in the script tag are rendered as text. Have you looked into getting this to work? Being able to use something like https://github.com/omnibrain/svguitar in notes to annotate would be very cool.

Speaking of which, have you looked at opening up the plugins for people to add their own custom plugins ?

I believe that since this was originally posted scripts have been explicitly disabled do to security issues (for example you wouldn’t want notes pulled with the webclipper to embed JavaScript).

And yes, there are currently experiments into adding plugins and if you search the forum you’ll find some small discussions.

1 Like

The reason I’m asking is because the exporting to PDF feature is very nice, I also want to make documents that leverage javascript to use drawing SVG for various reasons. For example, check this JS library https://github.com/omnibrain/svguitar

It would be useful for taking notes about guitar playing, for example (many options out there).

So it would be super useful if JS had the ability to be enabled