Skip to content

Instantly share code, notes, and snippets.

@jameswquinn
Created October 15, 2017 08:07
Show Gist options
  • Save jameswquinn/591410f11b3e9a7291bb6e51d10ec7ee to your computer and use it in GitHub Desktop.
Save jameswquinn/591410f11b3e9a7291bb6e51d10ec7ee to your computer and use it in GitHub Desktop.
JS-YAML
div.container ng-app="codepen"
div.row
div.col-md-12
h1.page-header Unofficial JS-YAML demo. YAML JavaScript parser.
div.row ng-controller="MainCtrl"
div.col-md-6
div.panel.panel-default
div.panel-heading Source
div.panel-body
form role="form"
textarea.form-control ng-model="source"
div.col-md-6
div.panel.panel-default
div.panel-heading Result
div.panel-body
pre.pre-scrollable
| {{ safeLoad(source) | json }}
app = angular.module('codepen', [])
app.controller 'MainCtrl', ($scope, $http) ->
$scope.safeLoad = (string) ->
try
jsyaml.safeLoad string
catch error
error.stack || String(error)
yaml = 'https://codepen.io/wulab/pen/aAnHc.html'
$http.get(yaml).success (data) ->
$scope.source = data
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/js-yaml/3.4.2/js-yaml.min.js"></script>
.page-header {
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}
textarea {
font-family: monospace;
.panel-body & {
height: 500px;
}
}
pre {
overflow: auto;
word-wrap: normal;
white-space: pre;
.panel-body & {
margin-bottom: 0;
height: 500px;
}
&.pre-scrollable {
/* reset max-height to set height */
max-height: none;
}
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment