Export Multiline chart data to csv with JavaScript

I am trying to adjust my Bokeh app so that clients are able to export the chart data in Multiline graphs to csv.

I had a look at the example here https://github.com/bokeh/bokeh/tree/master/examples/app/export_csv
which uses Javascript to save the data from a DataTable to csv upon clicking a button.

However, this fails with Multiline glyphs and produces some strange output.

I don’t have any experience with Javascript. Would somebody be able to help with adjusting the code in “download.js” to work with Multiline charts?

In a ColumnDataSource for the MultiLine glyph, the columns for xs and ys must contain arrays. How would you represent such arrays in CSV?