switch a bunch of naming from using "commonmark" to "markdown"

while we are actually using a CommonMark renderer instead of Markdown,
i think i just prefer referring to everything related to this as
"markdown" for simplicity's sake. meh.
This commit is contained in:
Gered 2023-06-30 14:56:18 -04:00
parent 913612c6e8
commit 4dfd946204
5 changed files with 20 additions and 20 deletions

View file

@ -9,14 +9,14 @@ posts:
- hello - hello
- testing - testing
- file_path: 2023-02-01-commonmark-testing.md - file_path: 2023-02-01-markdown-testing.md
title: CommonMark Testing title: Markdown Testing
date: 2023-02-01 date: 2023-02-01
slug: commonmark-testing slug: markdown-testing
tags: tags:
- testing - testing
alternate_urls: alternate_urls:
- /testing/commonmark/ - /testing/markdown/
- file_path: 2023-03-20-lorem-ipsum.md - file_path: 2023-03-20-lorem-ipsum.md
title: Lorem Ipsum title: Lorem Ipsum

View file

@ -1,4 +1,4 @@
Here we test some [CommonMark](https://commonmark.org/) things, gloriously rendered via the Here we test some Markdown (actually, [CommonMark](https://commonmark.org/)) things, gloriously rendered via the
[pulldown-cmark](https://github.com/raphlinus/pulldown-cmark) crate! [pulldown-cmark](https://github.com/raphlinus/pulldown-cmark) crate!
--- ---

View file

@ -5,8 +5,8 @@ use anyhow::Context;
use std::env; use std::env;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
mod commonmark;
mod config; mod config;
mod markdown;
mod site; mod site;
mod util; mod util;

View file

@ -4,7 +4,7 @@ use syntect::parsing::SyntaxSet;
use syntect::util::LinesWithEndings; use syntect::util::LinesWithEndings;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum CommonMarkError { pub enum MarkdownError {
#[error("Syntax highlighting error")] #[error("Syntax highlighting error")]
SyntectError(#[from] syntect::Error), SyntectError(#[from] syntect::Error),
} }
@ -13,17 +13,17 @@ struct SyntectContext {
syntax_set: SyntaxSet, syntax_set: SyntaxSet,
} }
pub struct CommonMarkRenderer { pub struct MarkdownRenderer {
syntect_context: SyntectContext, syntect_context: SyntectContext,
} }
impl CommonMarkRenderer { impl MarkdownRenderer {
pub fn new() -> Self { pub fn new() -> Self {
let syntax_set = SyntaxSet::load_defaults_newlines(); let syntax_set = SyntaxSet::load_defaults_newlines();
CommonMarkRenderer { syntect_context: SyntectContext { syntax_set } } MarkdownRenderer { syntect_context: SyntectContext { syntax_set } }
} }
fn highlight_code(&self, code: &str, language: &str) -> Result<String, CommonMarkError> { fn highlight_code(&self, code: &str, language: &str) -> Result<String, MarkdownError> {
let syntax = self let syntax = self
.syntect_context .syntect_context
.syntax_set .syntax_set
@ -44,7 +44,7 @@ impl CommonMarkRenderer {
fn highlight_codeblocks<'input>( fn highlight_codeblocks<'input>(
&self, &self,
events: Parser<'input, '_>, events: Parser<'input, '_>,
) -> Result<impl Iterator<Item = Event<'input>> + 'input, CommonMarkError> { ) -> Result<impl Iterator<Item = Event<'input>> + 'input, MarkdownError> {
let mut modified_events = Vec::new(); let mut modified_events = Vec::new();
let mut code_buffer = String::new(); let mut code_buffer = String::new();
let mut is_in_code_block = false; let mut is_in_code_block = false;
@ -81,7 +81,7 @@ impl CommonMarkRenderer {
Ok(modified_events.into_iter()) Ok(modified_events.into_iter())
} }
pub fn render_to_html(&self, s: &str) -> Result<String, CommonMarkError> { pub fn render_to_html(&self, s: &str) -> Result<String, MarkdownError> {
let parser = Parser::new_ext(s, pulldown_cmark::Options::all()); let parser = Parser::new_ext(s, pulldown_cmark::Options::all());
let events = self.highlight_codeblocks(parser)?; let events = self.highlight_codeblocks(parser)?;
let mut output = String::new(); let mut output = String::new();

View file

@ -7,7 +7,7 @@ use actix_web::{Either, HttpRequest, HttpResponse};
use chrono::{Datelike, TimeZone}; use chrono::{Datelike, TimeZone};
use itertools::Itertools; use itertools::Itertools;
use crate::{commonmark, config}; use crate::{config, markdown};
type UriPath = String; type UriPath = String;
type Tag = String; type Tag = String;
@ -17,17 +17,17 @@ pub enum ContentError {
#[error("Content rendering I/O error with path {0}")] #[error("Content rendering I/O error with path {0}")]
IOError(PathBuf, #[source] std::io::Error), IOError(PathBuf, #[source] std::io::Error),
#[error("CommonMark rendering error with path {0}")] #[error("Markdown rendering error with path {0}")]
CommonMarkError(PathBuf, #[source] commonmark::CommonMarkError), MarkdownError(PathBuf, #[source] markdown::MarkdownError),
} }
pub struct ContentRenderer { pub struct ContentRenderer {
commonmark_renderer: commonmark::CommonMarkRenderer, markdown_renderer: markdown::MarkdownRenderer,
} }
impl ContentRenderer { impl ContentRenderer {
pub fn new() -> Result<Self, ContentError> { pub fn new() -> Result<Self, ContentError> {
Ok(ContentRenderer { commonmark_renderer: commonmark::CommonMarkRenderer::new() }) Ok(ContentRenderer { markdown_renderer: markdown::MarkdownRenderer::new() })
} }
pub fn render(&self, path: &PathBuf) -> Result<String, ContentError> { pub fn render(&self, path: &PathBuf) -> Result<String, ContentError> {
@ -36,8 +36,8 @@ impl ContentRenderer {
Ok(s) => s, Ok(s) => s,
}; };
match path.extension().unwrap_or_default().to_str() { match path.extension().unwrap_or_default().to_str() {
Some("md") => match self.commonmark_renderer.render_to_html(&raw_content) { Some("md") => match self.markdown_renderer.render_to_html(&raw_content) {
Err(e) => return Err(ContentError::CommonMarkError(path.clone(), e)), Err(e) => return Err(ContentError::MarkdownError(path.clone(), e)),
Ok(output) => Ok(output), Ok(output) => Ok(output),
}, },
Some("html") | Some("htm") => Ok(raw_content), Some("html") | Some("htm") => Ok(raw_content),