Commit 1805ed8a by Rocky Duan

search highlighting

parent 30f5bdb4
...@@ -105,7 +105,6 @@ $ -> ...@@ -105,7 +105,6 @@ $ ->
replaceMath: (text) -> replaceMath: (text) ->
text = text.replace /@@(\d+)@@/g, ($0, $1) => @math[$1] text = text.replace /@@(\d+)@@/g, ($0, $1) => @math[$1]
@math = null @math = null
console.log text
text text
@replaceMathWrapper: (_this) -> @replaceMathWrapper: (_this) ->
...@@ -163,7 +162,6 @@ $ -> ...@@ -163,7 +162,6 @@ $ ->
$('#file-upload').unbind('change').change(startUploadHandler) $('#file-upload').unbind('change').change(startUploadHandler)
imageUploadHandler = (elem, input) -> imageUploadHandler = (elem, input) ->
console.log "here"
ajaxFileUpload(imageUploadUrl, input, imageUploadHandler) ajaxFileUpload(imageUploadUrl, input, imageUploadHandler)
editor = new Markdown.Editor( editor = new Markdown.Editor(
......
...@@ -278,15 +278,36 @@ initializeFollowThread = (thread) -> ...@@ -278,15 +278,36 @@ initializeFollowThread = (thread) ->
handleEditComment(this) handleEditComment(this)
initializeContent: (content) -> initializeContent: (content) ->
unescapeHighlightTag = (text) ->
text.replace(/\&lt\;highlight\&gt\;/g, "<span class='search-highlight'>")
.replace(/\&lt\;\/highlight\&gt\;/g, "</span>")
stripLatexHighlight = (text) ->
text
markdownWithHighlight = (text) ->
converter = Markdown.getMathCompatibleConverter()
unescapeHighlightTag stripLatexHighlight converter.makeHtml text
$content = $(content) $content = $(content)
initializeVote $content initializeVote $content
if $content.hasClass("thread") if $content.hasClass("thread")
initializeFollowThread $content initializeFollowThread $content
$local = Discussion.generateLocal($content.children(".discussion-content")) $local = Discussion.generateLocal($content.children(".discussion-content"))
$contentTitle = $local(".thread-title")
if $contentTitle.length
$contentTitle.html unescapeHighlightTag stripLatexHighlight $contentTitle.html()
$contentBody = $local(".content-body") $contentBody = $local(".content-body")
raw_text = $contentBody.html()
converter = Markdown.getMathCompatibleConverter() console.log "raw html:"
$contentBody.html(converter.makeHtml(raw_text)) console.log $contentBody.html()
$contentBody.html markdownWithHighlight $contentBody.html()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, $contentBody.attr("id")] MathJax.Hub.Queue ["Typeset", MathJax.Hub, $contentBody.attr("id")]
id = $content.attr("_id") id = $content.attr("_id")
if not Discussion.getContentInfo id, 'editable' if not Discussion.getContentInfo id, 'editable'
......
...@@ -42,7 +42,11 @@ ...@@ -42,7 +42,11 @@
<div class="discussion-right-wrapper clearfix"> <div class="discussion-right-wrapper clearfix">
${render_title(content, type, **kwargs)} ${render_title(content, type, **kwargs)}
<div class="discussion-content-view"> <div class="discussion-content-view">
% if content.get('highlighted_body', None):
<div class="content-body ${type}-body" id="content-body-${content['id']}">${content['highlighted_body'] | h}</div>
% else:
<div class="content-body ${type}-body" id="content-body-${content['id']}">${content['body'] | h}</div> <div class="content-body ${type}-body" id="content-body-${content['id']}">${content['body'] | h}</div>
% endif
<div class="content-raw-body ${type}-raw-body" style="display: none">${content['body'] | h}</div> <div class="content-raw-body ${type}-raw-body" style="display: none">${content['body'] | h}</div>
${render_tags(content, type, **kwargs)} ${render_tags(content, type, **kwargs)}
${render_bottom_bar(content, type, **kwargs)} ${render_bottom_bar(content, type, **kwargs)}
...@@ -54,8 +58,12 @@ ...@@ -54,8 +58,12 @@
<%def name="render_title(content, type, **kwargs)"> <%def name="render_title(content, type, **kwargs)">
% if type == "thread": % if type == "thread":
% if content.get('highlighted_title', None):
<a class="thread-title" name="${content['id']}" href="javascript:void(0)">${content['highlighted_title'] | h}</a>
% else:
<a class="thread-title" name="${content['id']}" href="javascript:void(0)">${content['title'] | h}</a> <a class="thread-title" name="${content['id']}" href="javascript:void(0)">${content['title'] | h}</a>
% endif % endif
% endif
</%def> </%def>
<%def name="render_tags(content, type, **kwargs)"> <%def name="render_tags(content, type, **kwargs)">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment