mirror of https://github.com/realaravinth/gitpad
feat: render markdown comments
parent
31f2c6960a
commit
d948730110
|
@ -17,7 +17,7 @@
|
|||
|
||||
- [x] Upload code snippets
|
||||
- [x] Syntax Highlighting
|
||||
- [ ] Comments
|
||||
- [x] Comments
|
||||
- [x] Versioning through Git
|
||||
- [ ] Fork gists
|
||||
- [x] Gist privacy: public, unlisted, private
|
||||
|
|
|
@ -40,18 +40,22 @@ pub struct SourcegraphQuery<'a> {
|
|||
pub code: &'a str,
|
||||
}
|
||||
|
||||
pub fn render_markdown(content: &str) -> String {
|
||||
// Set up options and parser. Strikethroughs are not part of the CommonMark standard
|
||||
// and we therefore must enable it explicitly.
|
||||
let options = Options::all();
|
||||
// options.insert(Options::ENABLE_STRIKETHROUGH);
|
||||
let parser = Parser::new_ext(content, options);
|
||||
|
||||
// Write to String buffer.
|
||||
let mut html_output = String::with_capacity(content.len());
|
||||
html::push_html(&mut html_output, parser);
|
||||
html_output
|
||||
}
|
||||
|
||||
impl<'a> SourcegraphQuery<'a> {
|
||||
pub fn render_markdown(&self) -> String {
|
||||
// Set up options and parser. Strikethroughs are not part of the CommonMark standard
|
||||
// and we therefore must enable it explicitly.
|
||||
let options = Options::all();
|
||||
// options.insert(Options::ENABLE_STRIKETHROUGH);
|
||||
let parser = Parser::new_ext(self.code, options);
|
||||
|
||||
// Write to String buffer.
|
||||
let mut html_output = String::new();
|
||||
html::push_html(&mut html_output, parser);
|
||||
html_output
|
||||
render_markdown(self.code)
|
||||
}
|
||||
|
||||
pub fn syntax_highlight(&self) -> String {
|
||||
|
|
|
@ -24,11 +24,11 @@ use tera::Context;
|
|||
use db_core::prelude::*;
|
||||
|
||||
use crate::api::v1::{gists::PostCommentRequest, routes::GetFilePath};
|
||||
use crate::data::api::v1::render_html::GenerateHTML;
|
||||
use crate::data::api::v1::{
|
||||
gists::{FileInfo, GistID, GistInfo},
|
||||
render_html::GenerateHTML,
|
||||
render_html::render_markdown,
|
||||
};
|
||||
//use crate::data::api::v1::render_html::GenerateHTML;
|
||||
use crate::errors::*;
|
||||
use crate::pages::routes::GistProfilePathComponent;
|
||||
use crate::pages::routes::PostCommentPath;
|
||||
|
@ -239,10 +239,15 @@ async fn view_util(
|
|||
//gist.files.iter_mut().for_each(|file| file.generate());
|
||||
let gist: HTMLGistInfo = gist.into();
|
||||
|
||||
let comments = db.get_comments_on_gist(&path.gist).await.map_err(|e| {
|
||||
let mut comments = db.get_comments_on_gist(&path.gist).await.map_err(|e| {
|
||||
let e: ServiceError = e.into();
|
||||
map_err(e, None)
|
||||
})?;
|
||||
|
||||
comments
|
||||
.iter_mut()
|
||||
.for_each(|mut comment| comment.comment = render_markdown(&comment.comment));
|
||||
|
||||
let ctx = PreviewPayload {
|
||||
gist: Some(&gist),
|
||||
comments: Some(&comments),
|
||||
|
|
Loading…
Reference in New Issue