add markdown to topic cards
This commit is contained in:
parent
dc55bae243
commit
fc044294f1
|
@ -220,7 +220,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="scroll">
|
<div class="scroll">
|
||||||
<div class="desc">
|
<div class="desc">
|
||||||
<span class="best_in_place best_in_place_desc" data-url="/topics/{{id}}" data-object="topic" data-nil="{{desc_nil}}" data-attribute="desc" data-type="textarea">{{desc}}</span>
|
<span class="best_in_place best_in_place_desc" data-url="/topics/{{id}}" data-object="topic" data-nil="{{desc_nil}}" data-attribute="desc" data-type="textarea" data-original-content="{{desc_markdown}}">{{{desc_html}}}</span>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -273,10 +273,14 @@ const TopicCard = {
|
||||||
topic.trigger('saved')
|
topic.trigger('saved')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// this is for all subsequent renders after in-place editing the desc field
|
||||||
$(showCard).find('.best_in_place_desc').bind('ajax:success', function () {
|
$(showCard).find('.best_in_place_desc').bind('ajax:success', function () {
|
||||||
this.innerHTML = this.innerHTML.replace(/\r/g, '')
|
var desc = $(this).html() === $(this).data('nil')
|
||||||
var desc = $(this).html() === $(this).data('nil') ? '' : $(this).html()
|
? ''
|
||||||
|
: $(this).text()
|
||||||
topic.set('desc', desc)
|
topic.set('desc', desc)
|
||||||
|
$(this).data('bestInPlaceEditor').original_content = desc
|
||||||
|
this.innerHTML = Util.mdToHTML(desc)
|
||||||
topic.trigger('saved')
|
topic.trigger('saved')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -397,8 +401,6 @@ const TopicCard = {
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
var desc_nil = 'Click to add description...'
|
|
||||||
|
|
||||||
nodeValues.attachmentsHidden = ''
|
nodeValues.attachmentsHidden = ''
|
||||||
if (topic.get('link') && topic.get('link') !== '') {
|
if (topic.get('link') && topic.get('link') !== '') {
|
||||||
nodeValues.embeds = '<a href="' + topic.get('link') + '" id="embedlyLink" target="_blank" data-card-description="0">'
|
nodeValues.embeds = '<a href="' + topic.get('link') + '" id="embedlyLink" target="_blank" data-card-description="0">'
|
||||||
|
@ -454,8 +456,11 @@ const TopicCard = {
|
||||||
nodeValues.date = topic.getDate()
|
nodeValues.date = topic.getDate()
|
||||||
// the code for this is stored in /views/main/_metacodeOptions.html.erb
|
// the code for this is stored in /views/main/_metacodeOptions.html.erb
|
||||||
nodeValues.metacode_select = $('#metacodeOptions').html()
|
nodeValues.metacode_select = $('#metacodeOptions').html()
|
||||||
nodeValues.desc_nil = desc_nil
|
nodeValues.desc_nil = 'Click to add description...'
|
||||||
nodeValues.desc = (topic.get('desc') == '' && authorized) ? desc_nil : topic.get('desc')
|
nodeValues.desc_markdown = (topic.get('desc') === '' && authorized)
|
||||||
|
? desc_nil
|
||||||
|
: topic.get('desc')
|
||||||
|
nodeValues.desc_html = Util.mdToHTML(nodeValues.desc_markdown)
|
||||||
return nodeValues
|
return nodeValues
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { Parser, HtmlRenderer } from 'commonmark'
|
||||||
|
|
||||||
import Visualize from './Visualize'
|
import Visualize from './Visualize'
|
||||||
|
|
||||||
const Util = {
|
const Util = {
|
||||||
|
@ -119,6 +121,9 @@ const Util = {
|
||||||
},
|
},
|
||||||
checkURLisYoutubeVideo: function (url) {
|
checkURLisYoutubeVideo: function (url) {
|
||||||
return (url.match(/^https?:\/\/(?:www\.)?youtube.com\/watch\?(?=[^?]*v=\w+)(?:[^\s?]+)?$/) != null)
|
return (url.match(/^https?:\/\/(?:www\.)?youtube.com\/watch\?(?=[^?]*v=\w+)(?:[^\s?]+)?$/) != null)
|
||||||
|
},
|
||||||
|
mdToHTML: text => {
|
||||||
|
return new HtmlRenderer().render(new Parser().parse(text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,16 @@
|
||||||
"babel-preset-es2015": "6.14.0",
|
"babel-preset-es2015": "6.14.0",
|
||||||
"babel-preset-react": "6.11.1",
|
"babel-preset-react": "6.11.1",
|
||||||
"backbone": "1.0.0",
|
"backbone": "1.0.0",
|
||||||
"underscore": "1.4.4",
|
"commonmark": "0.26.0",
|
||||||
"csv-parse": "1.1.7",
|
"csv-parse": "1.1.7",
|
||||||
|
"json-loader": "0.5.4",
|
||||||
"lodash": "4.16.1",
|
"lodash": "4.16.1",
|
||||||
"node-uuid": "1.4.7",
|
"node-uuid": "1.4.7",
|
||||||
"outdent": "0.2.1",
|
"outdent": "0.2.1",
|
||||||
"react": "15.3.2",
|
"react": "15.3.2",
|
||||||
"react-dom": "15.3.2",
|
"react-dom": "15.3.2",
|
||||||
"socket.io": "0.9.12",
|
"socket.io": "0.9.12",
|
||||||
|
"underscore": "1.4.4",
|
||||||
"webpack": "1.13.2"
|
"webpack": "1.13.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -21,6 +21,9 @@ const config = module.exports = {
|
||||||
plugins,
|
plugins,
|
||||||
devtool,
|
devtool,
|
||||||
module: {
|
module: {
|
||||||
|
preLoaders: [
|
||||||
|
{ test: /\.json$/, loader: 'json' }
|
||||||
|
],
|
||||||
loaders: [
|
loaders: [
|
||||||
{
|
{
|
||||||
test: /\.(js|jsx)?$/,
|
test: /\.(js|jsx)?$/,
|
||||||
|
|
Loading…
Reference in a new issue