From cdf79440651f172a64f1aa65ba93c9e70880d56c Mon Sep 17 00:00:00 2001
From: Adam Coldrick
Date: Fri, 11 Sep 2015 16:59:55 +0000
Subject: [PATCH] Render descriptions and comments as Markdown
When displaying comments and descriptions for projects or stories,
render the content as Markdown before displaying it. This is a
simple way to support rich text descriptions and comments, and
there is no special editor as yet.
Any code in the supplied Markdown (indented by 4 spaces) will have
its syntax highlighted. The `highlightjs` module is used for syntax
highlighting and the `marked` module is used for parsing the
Markdown.
Also, stop eslint from raising an error when it thinks something is
undefined, and raise a warning instead. This is because the use of
`hljs` and `marked` was confusing the linter into thinking they
weren't defined.
Change-Id: I7896fd686a39e27f8068ee6db6747b2b5ab0ccfc
---
.eslintrc | 3 +-
Gruntfile.js | 3 +-
bower.json | 4 ++-
src/app/projects/template/detail.html | 6 ++--
src/app/services/directive/markdown.js | 35 +++++++++++++++++++
.../template/comments/user_comment.html | 6 ++--
src/app/stories/template/detail.html | 14 +++-----
src/app/stories/template/story_list_item.html | 5 +--
src/app/storyboard/module.js | 9 ++++-
src/index.html | 2 ++
src/theme/base/discussion.less | 2 +-
src/theme/main.less | 1 +
12 files changed, 67 insertions(+), 23 deletions(-)
create mode 100644 src/app/services/directive/markdown.js
diff --git a/.eslintrc b/.eslintrc
index 64dcb316..dff941d1 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -49,10 +49,11 @@
"no-trailing-spaces": 2,
"camelcase": 0,
"no-extra-boolean-cast": 0,
+ "no-undef": 1,
// Stylistic
"indent": [2, 4],
"max-len": [2, 80],
"no-undefined": 2
}
-}
\ No newline at end of file
+}
diff --git a/Gruntfile.js b/Gruntfile.js
index a2b403e3..fc2f84e5 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -149,7 +149,8 @@ module.exports = function (grunt) {
dir.theme + '/custom/',
dir.theme + '/storyboard/',
dir.bower + '/bootstrap/less/',
- dir.bower + '/font-awesome/less/'
+ dir.bower + '/font-awesome/less/',
+ dir.bower + '/highlightjs/styles/'
];
},
cleancss: true,
diff --git a/bower.json b/bower.json
index 92e307d5..e5c4c7bd 100644
--- a/bower.json
+++ b/bower.json
@@ -13,7 +13,9 @@
"angular-elastic": "2.4.2",
"angular-moment": "0.9.0",
"angular-cache": "3.2.5",
- "angularjs-viewhead": "0.0.1"
+ "angularjs-viewhead": "0.0.1",
+ "marked": "0.3.4",
+ "highlightjs": "8.4"
},
"devDependencies": {
"angular-mocks": "1.3.13",
diff --git a/src/app/projects/template/detail.html b/src/app/projects/template/detail.html
index 2980b633..4b00bf9a 100644
--- a/src/app/projects/template/detail.html
+++ b/src/app/projects/template/detail.html
@@ -46,9 +46,9 @@
- {{project.description}}
-
+
+
No description provided
diff --git a/src/app/services/directive/markdown.js b/src/app/services/directive/markdown.js
new file mode 100644
index 00000000..f39e190f
--- /dev/null
+++ b/src/app/services/directive/markdown.js
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 Codethink Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Service for rendering text as markdown.
+ */
+angular.module('sb.services')
+ .directive('insertMarkdown', function($sanitize) {
+ 'use strict';
+
+ return {
+ restrict: 'E',
+ scope: {
+ content: '='
+ },
+ link: function(scope, elem) {
+ scope.$watch('content', function(newVal) {
+ elem.html('