render markdown docs

This commit is contained in:
Michael Zhang 2020-04-22 02:52:11 -05:00
parent 2333a02b4f
commit 229f0478e1
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 20 additions and 17 deletions

View file

@ -9,9 +9,7 @@ pub struct Ref {
impl Ref {
pub fn parse(string: impl AsRef<str>) -> Result<Self> {
let string = string.as_ref();
if string.starts_with("ref") {
}
if string.starts_with("ref") {}
unimplemented!()
}

View file

@ -250,20 +250,21 @@ impl Fedhub {
let mut ctx = self.context();
ctx.insert("repo_name", &path);
ctx.insert("tree_name", &tree_name);
let contents = if blob.is_binary() {
json!(null)
} else {
let str_contents = String::from_utf8(blob.content().to_vec())?;
json!(str_contents.lines().collect::<Vec<_>>())
};
ctx.insert(
"blob",
&json!({
let mut blob_val = json!({
"name": filepath,
"binary": blob.is_binary(),
"lines": contents,
}),
);
});
if !blob.is_binary() {
let str_contents = String::from_utf8(blob.content().to_vec())?;
if let Some(ext) = filepath.extension() {
if ext.to_str().unwrap() == "md" {
blob_val["rendered"] =
json!(markdown_to_html(&str_contents, &ComrakOptions::default()));
}
}
blob_val["lines"] = json!(str_contents.lines().collect::<Vec<_>>());
};
ctx.insert("blob", &blob_val);
render_response("repo_blob.html", &ctx)
}

View file

@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::convert::Infallible;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use anyhow::Result;
use fedhub::{Config, Fedhub};

View file

@ -5,7 +5,11 @@
{% block content %}
<h1>{{ repo_name }}: {{ tree_name }}: {{ blob.name }}</h1>
{% if blob.lines %}
{% if blob.rendered %}
<div>
{{ blob.rendered | safe }}
</div>
{% elif blob.lines %}
<div class="blob-contents">
<div class="left">
<ul>