refactor: github flavoured markdown options to be reusable.
- also fixes repo readmes not rendering tables
Diff
src/configuration/mod.rs | 19 +++++++++++++++++++
src/git.rs | 4 ++--
src/methods/about.rs | 24 +++++++++---------------
3 files changed, 30 insertions(+), 17 deletions(-)
@@ -1,5 +1,6 @@
use std::{path::Path, vec};
use comrak::Options;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -111,3 +112,21 @@ impl AppConfig {
Path::new(&self.root_readme).try_exists().unwrap_or(false)
}
}
pub struct ReadmeConfig;
impl ReadmeConfig {
pub fn gfm() -> Options {
let mut options = Options::default();
options.extension.autolink = true;
options.extension.footnotes = true;
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.tagfilter = true;
options.extension.tasklist = true;
options
}
}
@@ -25,7 +25,7 @@ use syntect::{
use time::OffsetDateTime;
use tracing::{error, instrument, warn};
use crate::syntax_highlight::ComrakSyntectAdapter;
use crate::{configuration::ReadmeConfig, syntax_highlight::ComrakSyntectAdapter};
type ReadmeCacheKey = (PathBuf, Option<Arc<str>>);
@@ -446,7 +446,7 @@ fn parse_and_transform_markdown(s: &str, syntax_set: &SyntaxSet) -> String {
options.extension.tagfilter = true;
options.extension.tasklist = true;
comrak::markdown_to_html_with_plugins(s, &options, &plugins)
comrak::markdown_to_html_with_plugins(s, &ReadmeConfig::gfm(), &plugins)
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1,9 +1,14 @@
use std::path::PathBuf;
use askama::Template;
use axum::{response::IntoResponse, Extension};
use comrak::Options;
use std::path::PathBuf;
use crate::{configuration::AppConfig, into_response, methods::filters, methods::repo::Result};
use crate::{
configuration::{AppConfig, ReadmeConfig},
into_response,
methods::filters,
methods::repo::Result,
};
#[derive(Template)]
#[template(path = "about.html")]
@@ -13,22 +18,11 @@ pub struct View {
}
pub async fn handle(Extension(config): Extension<AppConfig>) -> Result<impl IntoResponse> {
let mut options = Options::default();
options.extension.autolink = true;
options.extension.footnotes = true;
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.tagfilter = true;
options.extension.tasklist = true;
let about = comrak::markdown_to_html(
&get_readme_file(PathBuf::from(&config.root_readme))
.await
.unwrap_or_else(|_| "`Error opening root_readme file.`".to_string()),
&options,
&ReadmeConfig::gfm(),
);
Ok(into_response(View { about, config }))