HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h1>Google Spreadsheet to JSON Converter</h1>
<p>It's pretty useful to be able to get data from a Google Spreasheet as JSON, however it takes a bit of messing around with the URL to do so. This little converter should help.</p>
<p>The best part is that this tool handles mutiple sheets, returning the right sheet ID for whichever is specified in the URL</p>
<div ng-app="app">
<div ng-controller="controller">
<h2>Enter Your Google Spreadsheet URL here</h2>
<small><a href="https://support.google.com/docs/answer/37579?hl=en" target="_blank">Make sure it's published to the web <span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>
</a></small>
<form ng-submit="getGoogleJSON(inputURL)">
<input type="text" ng-model="inputURL" />
<input class="btn btn-lg btn-success" type="submit" />
</form>
<span class="error">{{error}}</span>
<div class="result" ng-show="newURL">
<h3>Your new URL is:</h3>
<code>{{newURL}}</code><br>
<small><a ng-href="{{newURL}}" target="_blank">Open URL <span class="glyphicon glyphicon-new-window" aria-hidden="true"></span>
</a></small>
<h3>Usage</h3>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation"><a href="#jquery" class="active" aria-controls="jquery" role="tab" data-toggle="tab">JQuery</a></li>
<li role="presentation"><a href="#angular" aria-controls="angular" role="tab" data-toggle="tab">AngularJS</a></li>
<li role="presentation"><a href="#json" aria-controls="json" role="tab" data-toggle="tab">JSON Response</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="jquery">
<pre><code>
$.get('{{newURL}}', function(data){
var entries = data.feed.entry;
$(entries).each(function(){
// Do something with each entry
});
});
</code></pre>
</div>
<div role="tabpanel" class="tab-pane" id="angular">
<pre><code>
$http.get('{{newURL}}').then(function(response){
// Assign data to scope
$scope.data = response.data;
});
</code></pre>
</div>
<div role="tabpanel" class="tab-pane" id="json">
<pre>{{JSONData | json}}</pre>
</div>
</div>
</div>
</div>
</div>
body {
text-align:center;
}
p {
width:600px;
margin:20px auto;
}
h1, h2, h3 {
color:coral;
}
input {
display:block !important;
margin:10px auto !important;
&[type="text"]{
width:90%;
padding: 10px;
font-size:1.3em;
text-align:center;
}
}
.result {
width:80%;
margin:auto;
pre {
margin-top:10px;
text-align:left;
padding:0 10px;
}
}
.error {
color:red;
}
(function() {
var app = angular.module('app', []);
app.controller('controller', function($scope, $http) {
// Default URL
$scope.inputURL = "https://docs.google.com/spreadsheets/d/1I3tEfgYtWKNYK9vqTmsCGfZfbHckS0-odDIgEilHiOQ/edit#gid=471572974";
// Convert the URL function
$scope.getGoogleJSON = function(url) {
// Clear newURL
$scope.newURL = '';
// Empty array for all the original grid IDs
$scope.oldGrids = [];
// Empty array for all the new grid IDs
$scope.newGrids = [];
// Get the spreadsheet ID from the URL
var id;
var preString = url.substring(url.indexOf('/d/') + 3);
if (preString.indexOf('/') > -1) {
id = preString.substring(0, preString.indexOf('/'));
} else {
id = preString;
}
// Get the grid ID from the URL
var grid = url.substring(url.indexOf('=') + 1);
// Get XML data of the spreadhseet which includes the new IDs. Using cors.io to avoid cross origin errors. This is for when a spreadsheet has multiple sheets
$http.get('https://cors.io/?https://spreadsheets.google.com/feeds/worksheets/' + id + '/public/full').then(function(response) {
// Parse the response as xml
var xml = $($.parseXML(response.data));
// Find each entry and loop through
$(xml).find('entry').each(function() {
// Get each old grid ID from XML data - contained in a '<link>'
var oldGridSrc = $(this).children('link[rel="http://schemas.google.com/visualization/2008#visualizationApi"]').attr('href');
// Chop the ID from the end of the href
var oldGrid = oldGridSrc.substring(oldGridSrc.indexOf('=') + 1, oldGridSrc.indexOf('&'))
// Find the '<id>' element in the xml. This contains the new Grid ID
var newGridSrc = $(this).children('id').text();
// Chop the ID from the end of the string
var newGrid = newGridSrc.substring(newGridSrc.lastIndexOf('/') + 1);
// Push new Grid ID to array
$scope.newGrids.push(newGrid);
// Push old Grid ID to array
$scope.oldGrids.push(oldGrid);
}) // End Each
// Get new Grid ID by cross referencing the original grid ID in the oldGrids array, return the index, and use that index to get the new Grid ID from the newGrids array. If undefined set to '1' which is the default for the first sheet
$scope.newGridID = $scope.newGrids[$scope.oldGrids.indexOf(grid)] || '1';
// Compose new URL
$scope.newURL = 'https://spreadsheets.google.com/feeds/list/' + id + '/' + $scope.newGridID + '/public/values?alt=json';
// Get JSON Response
$http.get($scope.newURL).then(function(response) {
$scope.JSONData = response.data;
});
// Show first tab
$('.nav-tabs a:first').tab('show');
setTimeout(function() {
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
}, 500);
}, function(response){
$scope.error = "Sorry, there has been an error. Please check your Spreadsheet URL";
}) // End $http.get
} // End getGoogleJSON function
}); // End Controller
})();
Also see: Tab Triggers