Skip to content

Commit

Permalink
fix: code highlight & settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
auula committed Jul 12, 2024
1 parent a2bbae5 commit b9a93b0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 31 deletions.
16 changes: 14 additions & 2 deletions settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
similar to mdbook and hugo, but it focuses only on rendering markdown into
an online book, and is easier to use than the other tools.
language: en
keywords: 'typikon,book,website,generator,static,html,css,js,theme,rust'
keywords: typikon,book,website,generator,static,html,css,js,theme,rust
directory:
theme: theme
input: book
Expand All @@ -19,4 +19,16 @@ custom_css:
custom_js:
- /assets/js/bootstrap.min.js
- /assets/js/bootstrap.bundle.js
- /assets/js/fuse.min.js
- /assets/js/fuse.min.js
highlight:
- c
- java
- rust
- cpp
- kotlin
- python
- csharp
- css
- swift
- bash
- javascript
3 changes: 3 additions & 0 deletions src/book/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Builder {
context.insert("chapters", &template.chapters);
context.insert("custom_js", &template.custom_js);
context.insert("custom_css", &template.custom_css);
context.insert("highlight", &template.highlight);
context.insert("description", &template.description);
context.insert("content", &hypertext.to_html());

Expand Down Expand Up @@ -160,6 +161,7 @@ impl Builder {
context.insert("chapters", &template.chapters);
context.insert("custom_js", &template.custom_js);
context.insert("custom_css", &template.custom_css);
context.insert("highlight", &template.highlight);
context.insert("description", &template.description);
context.insert("content", &html_content.to_html());

Expand Down Expand Up @@ -215,6 +217,7 @@ impl Builder {
context.insert("chapters", &template.chapters);
context.insert("custom_js", &template.custom_js);
context.insert("custom_css", &template.custom_css);
context.insert("highlight", &template.highlight);
context.insert("description", &template.description);
context.insert("content", &html_content.to_html());

Expand Down
1 change: 1 addition & 0 deletions src/book/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Settings {
pub keywords: String,
pub description: String,
pub directory: Directory,
pub highlight: Vec<String>,
pub custom_js: Vec<String>,
pub custom_css: Vec<String>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/html/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Template {
pub html_lang: String,
pub description: String,
pub chapters: Vec<Chapter>,
pub highlight: Vec<String>,
pub custom_js: Vec<String>,
pub custom_css: Vec<String>,
}
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Template {
icon: settings.icon.clone(),
keywords: settings.keywords.clone(),
html_lang: settings.language.clone(),
highlight: settings.highlight.clone(),
custom_js: settings.custom_js.clone(),
custom_css: settings.custom_css.clone(),
description: settings.description.clone(),
Expand Down
7 changes: 6 additions & 1 deletion tests/book/settings_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod tests {

use typikon::book::get_settings_from_file;


#[test]
fn test_get_settings() {
// Write a simple settings YAML string for testing
Expand All @@ -25,6 +24,11 @@ mod tests {
- "custom.js"
custom_css:
- "custom.css"
highlight:
- c
- cpp
- java
- rust
"#;

// Write the YAML string to a temporary file for the test
Expand Down Expand Up @@ -53,5 +57,6 @@ mod tests {
assert_eq!(settings.directory.output, "output/");
assert_eq!(settings.custom_js, vec!["custom.js"]);
assert_eq!(settings.custom_css, vec!["custom.css"]);
assert_eq!(settings.highlight, vec!["c", "cpp", "java", "rust"]);
}
}
13 changes: 10 additions & 3 deletions theme/typikon-theme/assets/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ code {
}

blockquote {
border-radius: 5px;
background-color: #333333;
/* Darker background for blockquotes */
border-left: 5px solid #ccc;
padding: 10px;
margin-left: 0;
Expand Down Expand Up @@ -91,6 +91,15 @@ hr {
/* Color for dashed horizontal rule */
}

.md-p {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
unicode-bidi: isolate;
}

.hljs-ln {
position: absolute;
left: -16px;
Expand Down Expand Up @@ -162,7 +171,6 @@ hr {
}

/* 鼠标悬停灰色 */

.col-md-4 a.d-inline-flex:hover,
.col-md-4 a.d-inline-flex:focus {
color: #e0e0e0;
Expand Down Expand Up @@ -195,7 +203,6 @@ hr {
unicode-bidi: isolate;
}


/* 目录菜单悬浮 */
.col-md-4 {
position: -webkit-sticky;
Expand Down
32 changes: 7 additions & 25 deletions theme/typikon-theme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,10 @@
</div>

<script src="/assets/highlight/highlight.min.js"></script>
<script src="/assets/highlight/languages/shell.min.js"></script>
<script src="/assets/highlight/languages/sql.min.js"></script>
<script src="/assets/highlight/languages/java.min.js"></script>
<script src="/assets/highlight/languages/rust.min.js"></script>
<script src="/assets/highlight/languages/javascript.min.js"></script>
<script src="/assets/highlight/languages/c.min.js"></script>
<script src="/assets/highlight/languages/cpp.min.js"></script>
<script src="/assets/highlight/languages/kotlin.min.js"></script>
<script src="/assets/highlight/languages/rust.min.js"></script>
<script src="/assets/highlight/languages/python.min.js"></script>
<script src="/assets/highlight/languages/csharp.min.js"></script>
<script src="/assets/highlight/languages/css.min.js"></script>
<script src="/assets/highlight/languages/swift.min.js"></script>
<script src="/assets/highlight/languages/xml.min.js"></script>
<script src="/assets/highlight/languages/yaml.min.js"></script>
<script src="/assets/highlight/languages/ruby.min.js"></script>
<script src="/assets/highlight/languages/php.min.js"></script>
<script src="/assets/highlight/languages/go.min.js"></script>
<script src="/assets/highlight/languages/dart.min.js"></script>
<script src="/assets/highlight/languages/bash.min.js"></script>
<script src="/assets/highlight/languages/dockerfile.min.js"></script>

{% for lang_path in highlight %}
<script src="/assets/highlight/languages/{{ lang_path }}.min.js"></script>
{% endfor %}

{% for js_path in custom_js %}
<script src="{{ js_path | safe }}"></script>
Expand Down Expand Up @@ -136,7 +119,6 @@
// Listen for changes in OS theme
darkThemeMediaQuery.addListener(changeTheme);


// Initial highlight.js
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
Expand All @@ -145,7 +127,7 @@
var markdownContent = document.getElementById('markdown-content');
if (markdownContent) {
var paragraphs = markdownContent.querySelectorAll('p');
paragraphs.forEach(function (paragraph) {
paragraphs.forEach((paragraph) => {
paragraph.classList.add('md-p');
});
}
Expand Down Expand Up @@ -181,8 +163,8 @@
});
};

const search_text_input = document.getElementById("serach-text");
search_text_input.addEventListener("input", performSearch);
const searchInput = document.getElementById("serach-text");
searchInput.addEventListener("input", performSearch);
};

function themeChange() {
Expand Down

0 comments on commit b9a93b0

Please sign in to comment.