Skip to content

Commit 02c9bbc

Browse files
committed
some documentation
1 parent 31cb60e commit 02c9bbc

File tree

3 files changed

+63
-12
lines changed

3 files changed

+63
-12
lines changed

notebook/static/base/js/markdown.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,30 @@ define([
5757
}
5858

5959
function render(markdown, options, callback) {
60+
/**
61+
* Find a readme in the current directory. Look for files with
62+
* a name like 'readme.md' (case insensitive) or similar and
63+
* mimetype 'text/markdown'.
64+
*
65+
* @param markdown: the markdown text to parse
66+
* @param options
67+
* Object with parameters:
68+
* with_math: the markdown can contain mathematics
69+
* clean_tables: prevent default inline styles for table cells
70+
* sanitize: remove dangerous html (like <script>)
71+
* @param callback
72+
* A function with two arguments (err, html)
73+
* err: null or the error if there was one
74+
* html: the rendered html string, or if {sanitize: true} was used
75+
* a sanitized jQuery object
76+
*/
6077
options = $.extend({
6178
// Apply mathjax transformation
6279
with_math: false,
6380
// Prevent marked from returning inline styles for table cells
64-
clean_tables: false
81+
clean_tables: false,
82+
// Apply sanitation, this will return a jQuery object.
83+
sanitize: false,
6584
}, options);
6685
var renderer = new marked.Renderer();
6786
if(options.clean_tables) {

notebook/static/tree/js/directoryreadme.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,35 @@ define([
66
'base/js/utils',
77
'base/js/events',
88
'base/js/markdown',
9-
'base/js/mathjaxutils',
10-
], function ($, utils, events, markdown, mathjaxutils) {
9+
], function ($, utils, events, markdown) {
1110
"use strict";
1211

13-
var DirectoryReadme = function (selector, notebook_list, options) {
12+
var DirectoryReadme = function (selector, notebook_list) {
13+
/**
14+
* Constructor
15+
*
16+
* Parameters:
17+
* selector: string
18+
* notebook_list: NotebookList
19+
* Used to obtain a file listing of the active directory.
20+
*/
1421
this.selector = selector;
1522
this.element = $(selector);
1623
this.notebook_list = notebook_list;
17-
this.base_url = options.base_url || utils.get_body_data("baseUrl");
18-
this.contents = options.contents;
1924
this.drawn_readme = null;
2025

2126
this.init_readme();
2227
this.bind_events();
2328
};
2429

2530
DirectoryReadme.prototype.find_readme = function() {
31+
/**
32+
* Find a readme in the current directory. Look for files with
33+
* a name like 'readme.md' (case insensitive) or similar and
34+
* mimetype 'text/markdown'.
35+
*
36+
* @return null or { name, path, last_modified... }
37+
*/
2638
var files_in_directory = this.notebook_list.model_list.content;
2739
for (var i = 0; i < files_in_directory.length; i++) {
2840
var file = files_in_directory[i];
@@ -36,6 +48,12 @@ define([
3648
}
3749

3850
DirectoryReadme.prototype.needs_update = function(readme) {
51+
/**
52+
* Checks if readme is newer or different from the current drawn readme.
53+
*
54+
* @private
55+
* @return if a redraw should happen
56+
*/
3957
if(this.drawn_readme === readme) return false;
4058
if(this.drawn_readme === null || readme === null) return true;
4159
if(this.drawn_readme.path !== readme.path) return true;
@@ -45,14 +63,17 @@ define([
4563

4664

4765
DirectoryReadme.prototype.fetch_readme = function() {
66+
/**
67+
* Find and fetch a readme file, and if necessary trigger a redraw.
68+
*/
4869
var readme = this.find_readme();
4970

5071
if(this.needs_update(readme)) {
5172
if(readme === null) {
5273
this.clear_readme();
5374
} else {
5475
var that = this;
55-
this.contents.get(readme.path, {type: 'file'}).then(
76+
this.notebook_list.contents.get(readme.path, {type: 'file'}).then(
5677
function(file) {
5778
that.draw_readme(file);
5879
},
@@ -65,10 +86,16 @@ define([
6586
}
6687

6788
DirectoryReadme.prototype.bind_events = function () {
89+
/**
90+
* When the notebook_list fires a draw_notebook event, fetch the readme.
91+
*/
6892
events.on("draw_notebook_list.NotebookList", $.proxy(this.fetch_readme, this));
6993
}
7094

7195
DirectoryReadme.prototype.init_readme = function() {
96+
/**
97+
* Build the DOM.
98+
*/
7299
var element = this.element;
73100
element.hide().addClass("list_container");
74101

@@ -88,17 +115,25 @@ define([
88115
}
89116

90117
DirectoryReadme.prototype.clear_readme = function () {
118+
/**
119+
* If no readme is found, hide.
120+
*/
91121
this.drawn_readme = null;
92122
this.element.hide();
93123
}
94124

95125
DirectoryReadme.prototype.draw_readme = function (file) {
126+
/**
127+
* Draw the given readme file. This function is used by fetch_readme.
128+
*
129+
* @param file: {name, path, content}
130+
*/
96131
this.drawn_readme = file;
97132
this.element.show();
98133
this.title
99134
.attr("href",
100135
utils.url_path_join(
101-
this.base_url,
136+
this.notebook_list.base_url,
102137
"edit",
103138
utils.encode_uri_components(file.path)
104139
))

notebook/static/tree/js/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ requirejs([
102102
var kernel_list = new kernellist.KernelList('#running_list', $.extend({
103103
session_list: session_list},
104104
common_options));
105-
var directory_readme = new directoryreadme.DirectoryReadme('#directory_readme', notebook_list, $.extend({
106-
contents: contents,
107-
base_url: common_options.base_url,},
108-
common_options));
105+
var directory_readme = new directoryreadme.DirectoryReadme('#directory_readme', notebook_list);
109106

110107
var terminal_list;
111108
if (utils.get_body_data("terminalsAvailable") === "True") {

0 commit comments

Comments
 (0)