Comments (7)
+1 to this 👍
from csv-to-html-table.
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.
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.
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.
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.
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
<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>
functions and apply them to specific columns, like so: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.
👍
from csv-to-html-table.
Related Issues (20)
- [suggestion] Edditable and savable HOT 1
- Tables without column headers in the first row HOT 1
- Select2 or selectize integration HOT 1
- How we can use csv file from web via url? HOT 3
- Add capability to pass in comma separate string instead of file HOT 2
- HTTPS issue HOT 1
- Make multilne text in cells
- Adding bootstrap tabs to the view. How would one go about doing this? HOT 1
- datatables_options "processing": true did not work HOT 1
- Add Dropdown filter
- function format_link(link)
- Cannot work in PHP HOT 1
- Can we use multiple CSV once? HOT 2
- White page
- auto refresh/reload the csv file when it changed HOT 1
- Table not showing HOT 7
- How to embed CSV file in HTML Javascript
- Can we change the cell color based on value with format link option?
- Fix the columns title when the table is scrolled down
- Allow reading CSV directly and not from file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csv-to-html-table.