Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customize pre color #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ footer-template = "templates/footer.html"
highlight_code = true
# custom highligh theme
highlight_theme = "ayu-light"
# custom pre block code color, only works if `highlight_code` is disabled
pre_code_color = "#333"
# custom pre block background color, only works if `highlight_code` is disabled
pre_bg_color = "#eee"

# Issue 1
[[issue]]
Expand Down
20 changes: 18 additions & 2 deletions src/entity/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all(deserialize = "snake_case"))]
pub struct MarkdownConfig {
#[serde(default = "MarkdownConfig::default_highlight_code")]
pub highlight_code: bool,
#[serde(default = "MarkdownConfig::default_highlight_theme")]
pub highlight_theme: String,
#[serde(default = "MarkdownConfig::default_pre_code_color")]
pub pre_code_color: String,
#[serde(default = "MarkdownConfig::default_pre_bg_color")]
pub pre_bg_color: String,
}

impl Default for MarkdownConfig {
fn default() -> Self {
Self {
highlight_code: true,
highlight_theme: Self::default_highlight_theme(),
pre_code_color: Self::default_pre_code_color(),
pre_bg_color: Self::default_pre_code_color(),
}
}
}

impl MarkdownConfig {
const DEFAULT_HIGHLIGHT_THEME: &'static str = "monokai";
const DEFAULT_PRE_CODE_COLOR: &'static str = "#61676c";
const DEFAULT_PRE_BG_COLOR: &'static str = "#f5f5f5";

fn default_highlight_theme() -> String {
Self::DEFAULT_HIGHLIGHT_THEME.to_string()
}

fn default_pre_code_color() -> String {
Self::DEFAULT_PRE_CODE_COLOR.to_string()
}

fn default_pre_bg_color() -> String {
Self::DEFAULT_PRE_BG_COLOR.to_string()
}

fn default_highlight_code() -> bool {
true
}
Expand Down
1 change: 1 addition & 0 deletions src/entity/zine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl Entity for Zine {
fn render(&self, mut context: Context, dest: &Path) -> Result<()> {
context.insert("theme", &self.theme);
context.insert("site", &self.site);
context.insert("markdown_config", &self.markdown_config);

// Render all authors pages.
let authors = self.authors();
Expand Down
5 changes: 5 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module.exports = {
strong: {
fontWeight: '500',
},
pre: {
borderRadius: 0,
color: 'var(--pre-code-color)',
backgroundColor: 'var(--pre-bg-color)',
},
blockquote: {
color: "#7c8088",
borderLeftWidth: '2px',
Expand Down
2 changes: 2 additions & 0 deletions templates/base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
--main-color: {{ theme.main_color }};
--link-color: {{ theme.link_color }};
--secondary-color: {{ theme.secondary_color }};
--pre-code-color: {{ markdown_config.pre_code_color }};
--pre-bg-color: {{ markdown_config.pre_bg_color }};
}
</style>
</head>
Expand Down