Skip to content

Commit

Permalink
Merge pull request #11 from husni-zuhdi/enable-table-in-markdownrs-an…
Browse files Browse the repository at this point in the history
…d-tailwindcss

chore: enable GFM during markdown -> html conversion and add tables t…
  • Loading branch information
husni-zuhdi authored Aug 29, 2024
2 parents 6f27ebe + 1276095 commit 0ba3de5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 16 deletions.
26 changes: 13 additions & 13 deletions internal/src/model/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ pub struct Trees {
pub tree: Vec<Tree>,
}

// The file mode one of
// 100644 for file (blob)
// 100755 for executable (blob)
// 040000 for subdirectory (tree)
// 160000 for submodule (commit)
// 120000 for a blob that specifies the path of a symlink.
// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
/// The file mode one of
/// 100644 for file (blob)
/// 100755 for executable (blob)
/// 040000 for subdirectory (tree)
/// 160000 for submodule (commit)
/// 120000 for a blob that specifies the path of a symlink.
/// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum TreeMode {
#[serde(rename(deserialize = "100644"))]
Expand All @@ -133,8 +133,8 @@ pub enum TreeMode {
Symlink,
}

// Either blob, tree, or commit.
// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
/// Either blob, tree, or commit.
/// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum TreeType {
#[serde(rename(deserialize = "blob"))]
Expand All @@ -145,8 +145,8 @@ pub enum TreeType {
Commit,
}

// Tree structure of git
// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
/// Tree structure of git
/// Reference: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Tree {
pub path: String,
Expand All @@ -159,8 +159,8 @@ pub struct Tree {
pub url: String,
}

// Axum state
// Consist of Config and BlogsData
/// Axum state
/// Consist of Config and BlogsData
#[derive(Debug, Clone)]
pub struct AppState {
pub config: Config,
Expand Down
7 changes: 4 additions & 3 deletions internal/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::model::data::VersionData;
use log::debug;
use markdown::to_html;
use markdown::{to_html_with_options, Options};
use regex::Regex;
use std::fs;
use std::io::BufReader;
Expand All @@ -21,8 +21,9 @@ pub fn md_to_html(filename: Option<String>, body: Option<String>) -> Result<Stri
Some(val) => body_md = val,
None => (),
}
// let body_md = fs::read_to_string(filename.unwrap()).expect("Failed to read markdown blog file");
Ok(to_html(&body_md))
let html = to_html_with_options(&body_md, &Options::gfm())
.expect("Failed to convert html with options");
Ok(html)
}

/// read_version_manifest
Expand Down
15 changes: 15 additions & 0 deletions statics/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@
pre {
@apply px-4 text-wrap rounded border-solid border-2 border-gray-500 bg-gray-200;
}
table {
@apply table-auto rounded border-solid border-2 border-gray-500;
}
thead {
@apply bg-gray-400 text-center;
}
th {
@apply px-3 py-1;
}
tbody {
@apply bg-gray-200;
}
td {
@apply px-3 py-1;
}
}
34 changes: 34 additions & 0 deletions statics/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,40 @@ pre {
padding-right: 1rem;
}

table {
table-layout: auto;
border-radius: 0.25rem;
border-width: 2px;
border-style: solid;
--tw-border-opacity: 1;
border-color: rgb(107 114 128 / var(--tw-border-opacity));
}

thead {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
text-align: center;
}

th {
padding-left: 0.75rem;
padding-right: 0.75rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}

tbody {
--tw-bg-opacity: 1;
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
}

td {
padding-left: 0.75rem;
padding-right: 0.75rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}

*, ::before, ::after {
--tw-border-spacing-x: 0;
--tw-border-spacing-y: 0;
Expand Down

0 comments on commit 0ba3de5

Please sign in to comment.