Skip to content
This repository was archived by the owner on May 20, 2018. It is now read-only.

Commit 4742f38

Browse files
author
Lev Lazinskiy
committed
View Single Notes, and Task Lists
Permalink are now created for notes. GFM TaksLists are supported now. :) Thanks to [this](markedjs/marked#587) PR.
1 parent 5984d3f commit 4742f38

File tree

7 files changed

+62
-15
lines changed

7 files changed

+62
-15
lines changed

app/main/views.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from flask import render_template, session, redirect, url_for, flash
2+
from flask import render_template, session, redirect, url_for, flash, abort
33
from flask.ext.login import current_user, login_required
44

55
from . import main
@@ -21,6 +21,14 @@ def index():
2121
else:
2222
return render_template('index.html')
2323

24+
@main.route('/note/<int:id>')
25+
@login_required
26+
def note(id):
27+
note = Note.query.get_or_404(id)
28+
if current_user != note.author:
29+
abort(403)
30+
return render_template('note.html', notes=[note])
31+
2432
@main.route('/edit/<int:id>', methods=['GET', 'POST'])
2533
@login_required
2634
def edit(id):

app/static/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ a.buttons {
8585
text-decoration: none;
8686
}
8787

88+
li.task-list-item {
89+
list-style-type: none;
90+
}
91+
8892
/* Style for Releases Plugin */
8993
#releases {
9094
list-style-type: none;

app/static/js/braindump.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ editor.session.setMode("ace/mode/markdown");
55
editor.getSession().setUseWrapMode(true);
66
editor.setAutoScrollEditorIntoView(true);
77
editor.setOption("minLines", 10);
8-
editor.setOption("maxLines", 100);
8+
editor.setOption("maxLines", 25);
99

1010
var textarea = $('textarea[id="body"]').hide();
1111
var textarea_html_label = $('label[for="body_html"]').hide();
@@ -21,7 +21,7 @@ editor.commands.addCommand({
2121
name: 'insert text',
2222
bindKey: {win: 'Ctrl-1', mac: 'Ctrl-1'},
2323
exec: function(editor) {
24-
editor.insert("*TODO ")
24+
editor.insert("- [ ] TODO")
2525
},
2626
readOnly: true // false if this command should not apply in readOnly mode
2727
});

app/static/js/libs/marked.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var block = {
2727
text: /^[^\n]+/
2828
};
2929

30+
block.checkbox = /^\[([ x])\] +/;
3031
block.bullet = /(?:[*+-]|\d+\.)/;
3132
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
3233
block.item = replace(block.item, 'gm')
@@ -157,7 +158,8 @@ Lexer.prototype.token = function(src, top, bq) {
157158
, item
158159
, space
159160
, i
160-
, l;
161+
, l
162+
, checked;
161163

162164
while (src) {
163165
// newline
@@ -304,6 +306,16 @@ Lexer.prototype.token = function(src, top, bq) {
304306
space = item.length;
305307
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
306308

309+
if (this.options.gfm) {
310+
checked = block.checkbox.exec(item);
311+
312+
if (checked) {
313+
checked = checked[1] === 'x';
314+
item = item.replace(block.checkbox, '');
315+
} else {
316+
checked = undefined;
317+
}
318+
}
307319
// Outdent whatever the
308320
// list item contains. Hacky.
309321
if (~item.indexOf('\n ')) {
@@ -333,6 +345,7 @@ Lexer.prototype.token = function(src, top, bq) {
333345
}
334346

335347
this.tokens.push({
348+
checked: checked,
336349
type: loose
337350
? 'loose_item_start'
338351
: 'list_item_start'
@@ -809,13 +822,23 @@ Renderer.prototype.hr = function() {
809822
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
810823
};
811824

812-
Renderer.prototype.list = function(body, ordered) {
825+
Renderer.prototype.list = function(body, ordered, taskList) {
813826
var type = ordered ? 'ol' : 'ul';
814-
return '<' + type + '>\n' + body + '</' + type + '>\n';
827+
var classes = taskList ? ' class="task-list"' : '';
828+
return '<' + type + classes + '>\n' + body + '</' + type + '>\n';
815829
};
816830

817-
Renderer.prototype.listitem = function(text) {
818-
return '<li>' + text + '</li>\n';
831+
Renderer.prototype.listitem = function(text, checked) {
832+
if (checked === undefined) {
833+
return '<li>' + text + '</li>\n';
834+
}
835+
836+
return '<li class="task-list-item">'
837+
+ '<input type="checkbox" class="task-list-item-checkbox"'
838+
+ (checked ? ' checked' : '')
839+
+ '> '
840+
+ text
841+
+ '</li>\n';
819842
};
820843

821844
Renderer.prototype.paragraph = function(text) {
@@ -1037,24 +1060,29 @@ Parser.prototype.tok = function() {
10371060
}
10381061
case 'list_start': {
10391062
var body = ''
1063+
, taskList = false
10401064
, ordered = this.token.ordered;
10411065

10421066
while (this.next().type !== 'list_end') {
1067+
if (this.token.checked !== undefined) {
1068+
taskList = true;
1069+
}
10431070
body += this.tok();
10441071
}
10451072

1046-
return this.renderer.list(body, ordered);
1073+
return this.renderer.list(body, ordered, taskList);
10471074
}
10481075
case 'list_item_start': {
1049-
var body = '';
1076+
var body = ''
1077+
, checked = this.token.checked;
10501078

10511079
while (this.next().type !== 'list_item_end') {
10521080
body += this.token.type === 'text'
10531081
? this.parseText()
10541082
: this.tok();
10551083
}
10561084

1057-
return this.renderer.listitem(body);
1085+
return this.renderer.listitem(body, checked);
10581086
}
10591087
case 'loose_item_start': {
10601088
var body = '';
@@ -1063,7 +1091,7 @@ Parser.prototype.tok = function() {
10631091
body += this.tok();
10641092
}
10651093

1066-
return this.renderer.listitem(body);
1094+
return this.renderer.listitem(body, checked);
10671095
}
10681096
case 'html': {
10691097
var html = !this.token.pre && !this.options.pedantic

app/static/js/libs/releases.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/templates/_notes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% for note in notes %}
33
<li class="note">
44
<div class="note-content">
5-
<div class="note-title"><h3>{{ note.title }}</h3></div>
5+
<div class="note-title"><a href="{{ url_for('.note', id=note.id)}}"><h3>{{ note.title }}</h3></a></div>
66
<div class="note-date">{{ moment(note.timestamp).fromNow() }}
77
by <a href="{{ url_for('.index', username=note.author.username) }}">{{ note.author.username }}</a> </div>
88
<div class="note-body">

app/templates/note.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends 'base.html' %}
2+
3+
{% block title %} Braindump | Note {% endblock %}
4+
5+
{% block page_content %}
6+
{% include '_notes.html' %}
7+
{% endblock %}

0 commit comments

Comments
 (0)