It seemed to be hard to find a good example of using js-yaml from a browser. Probably because they emphasize the use of the parser in node.js.
The parser is at https://github.com/nodeca/js-yaml. Use NPM to install it
npm install js-yaml
and grab the js-yaml.js file from the node_modules/js-yaml/bin directory.
Here is a quick, simple demo that loads a YAML file, uses js-yaml to parse it into objects, and then (for verification) it does a native JSON.stringify to convert the JSON into a string and finally uses jquery $.parseJSON to verify the resulting JSON.
(function () {
"use strict";
$(document).ready(function () {
$.get('/common/resources/LessonContentsLv01Ln01.yml')
.done(function (data) {
console.log('File load complete');
console.log(jsyaml.load(data));
var jsonString = JSON.stringify(data);
console.log(jsonString);
console.log($.parseJSON(jsonString));
});
});
}());
And the HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Read YAML</title>
<script src="//code.jquery.com/jquery-2.1.0.js">
</script><script src='/vendor/js/js-yaml.js'>
</script><script src='/test/readYaml.js'>
</script>
</head>
<body>
</body>
</html>
Github repository https://github.com/nodeca/js-yaml