Giter VIP home page Giter VIP logo

Comments (7)

stephenturner avatar stephenturner commented on August 28, 2024

+1 to this 👍

from csv-to-html-table.

stephenturner avatar stephenturner commented on August 28, 2024

I'm using this for my own project, and wrote this Makefile in the project repo that scans a CSV for markdown links e.g. [google](http://google.com) and uses a perl regex to convert that to an HTML link. It also fixes what MS Excel destroys wrt line endings. Could probably extend this with a regex to look for bare URLs.

data = data/mydatafile.csv

all: 
    # fix line endings
    perl -pi -e 's/\r/\n/g; $$_.="\n" if eof' $(data)
    # get rid of blank lines
    perl -ni -e 'print unless /^$$/' $(data)
    # parse markdown links
    perl -pi -e 's@\[([^\[]+)\]\(([^\)]+)\)@<a href='\''$$2'\'' target='\''_blank'\''>$$1</a>@g' $(data)

from csv-to-html-table.

derekeder avatar derekeder commented on August 28, 2024

This is cool. I'm a huge fan of Make!

My only concern is ease of use. One of the really nice features of this project is its 100% javascript and HTML, and is intended to be easy for 'plug and play'.

I was thinking of doing a similar regex in Javascript. For the excel stuff, I was thinking of using this: https://github.com/SheetJS/js-xls and https://github.com/SheetJS/js-xlsx

from csv-to-html-table.

b-meson avatar b-meson commented on August 28, 2024

In csv_to_html_table.js made the following edits
csv_data[row_id][10]= linkify(csv_data[row_id][10]); where linkify is a JS function

function linkify(inputText) {
    //URLs starting with http://, https://, or ftp://
    var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    var replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">Text of Link Request</a>');
    return replacedText
}

However this implementation is not very efficient for many columns, in fact you have to define it for each column. It is a way to hack around this. @derekeder actually helped me write this.

from csv-to-html-table.

derekeder avatar derekeder commented on August 28, 2024

Hey all, I ended up adding a generic way to pass in custom formatting functions and apply them to specific columns, like so:

<script>

  //my custom function that creates a hyperlink
  function format_link(link){
    if (link)
      return "<a href='" + link + "' target='_blank'>" + link + "</a>";
    else
      return "";
  }

  //initializing the table
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false},
    custom_formatting: [[4, format_link]] //execute the function on the 4th column of every row
  });
</script>

Hope this helps!

from csv-to-html-table.

b-meson avatar b-meson commented on August 28, 2024

This is a good implementation thanks Derek.

On Sat, Sep 10, 2016 at 12:03 AM Derek Eder [email protected]
wrote:

Hey all, I ended up adding a generic way to pass in custom formatting
functions and apply them to specific columns, like so:

<script> //my custom function that creates a hyperlink function format_link(link){ if (link) return "" + link + ""; else return ""; } //initializing the table CsvToHtmlTable.init({ csv_path: 'data/Health Clinics in Chicago.csv', element: 'table-container', allow_download: true, csv_options: {separator: ',', delimiter: '"'}, datatables_options: {"paging": false}, custom_formatting: [[4, format_link]] //execute the function on the 4th column of every row });</script>

Hope this helps!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC9OPOKkxLVyOv-b8gJ7hWAm6PEFg0Qwks5qojoygaJpZM4FCJjV
.

from csv-to-html-table.

derekeder avatar derekeder commented on August 28, 2024

👍

from csv-to-html-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.