mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2025-02-24 07:00:51 +08:00
change code highlight to Prismjs
This commit is contained in:
parent
9ad171196f
commit
5824548b40
@ -1,18 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
##############################################################################
|
|
||||||
##### #####
|
|
||||||
##### Markdown StyleSheet of ui design BreadCard #####
|
|
||||||
##### compatibility layer #####
|
|
||||||
##### for highlight.js #####
|
|
||||||
##### #####
|
|
||||||
##### @author: Sukazyo Workshop #####
|
|
||||||
##### @version: 1.0 #####
|
|
||||||
##### #####
|
|
||||||
##############################################################################
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
.hljs,
|
|
||||||
code.hljs,
|
|
||||||
pre code.hljs {
|
|
||||||
padding: 0.2rem 1.2rem 0.6rem;
|
|
||||||
}
|
|
@ -223,6 +223,13 @@ code {
|
|||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:not(pre)>code[class*=language-] {
|
||||||
|
padding: 0.2rem;
|
||||||
|
border-radius: 0.3rem;
|
||||||
|
background: var(--bcm-color-code-inline-background);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
margin-left: 1.4rem;
|
margin-left: 1.4rem;
|
||||||
margin-right: 1.4rem;
|
margin-right: 1.4rem;
|
||||||
@ -235,13 +242,24 @@ pre {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre[class*=language-] {
|
||||||
|
margin-left: 1.4rem;
|
||||||
|
margin-right: 1.4rem;
|
||||||
|
padding: 0.7rem 0;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
pre code {
|
pre code {
|
||||||
display: block;
|
display: block;
|
||||||
background: var(--bcm-color-codeblock-background);
|
background: var(--bcm-color-codeblock-background);
|
||||||
overflow-x: scroll;
|
overflow-x: scroll;
|
||||||
padding: 0.2rem 1.2rem 0.6rem;
|
padding: 0.2rem 1.2rem 0.6rem;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-size: inherit;
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre[class*=language-] code[class*=language-] {
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre code::-webkit-scrollbar {
|
pre code::-webkit-scrollbar {
|
||||||
|
@ -88,32 +88,12 @@ class PageMeta {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function highlightJsTheme (): string {
|
public static function prismTheme (): string {
|
||||||
$theme = trim(self::getConfigurationLevelPage(ConfigName::highlightjs_theme));
|
$theme = trim(self::getConfigurationLevelPage(ConfigName::prism_theme));
|
||||||
if (empty($theme)) return "atom-one-dark";
|
if (empty($theme)) return "prism-material-light";
|
||||||
return $theme;
|
return $theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public static function highlightJsLanguages (): array {
|
|
||||||
$langDef = "";
|
|
||||||
{
|
|
||||||
$langDefList = array();
|
|
||||||
$langDefList[] = SiteMeta::getConfigurationLevelShelf(ConfigName::highlightjs_lang);
|
|
||||||
$langDefList[] = PageMeta::getConfigurationLevelBook(ConfigName::highlightjs_lang);
|
|
||||||
$langDefList[] = PageMeta::getConfigurationLevelPage(ConfigName::highlightjs_lang);
|
|
||||||
foreach ($langDefList as $langDefNode) $langDef .= $langDefNode . ";";
|
|
||||||
}
|
|
||||||
$lang = array();
|
|
||||||
foreach (explode(";", $langDef) as $i) {
|
|
||||||
$i = trim($i);
|
|
||||||
if ($i != "") $lang[] =$i;
|
|
||||||
}
|
|
||||||
return array_unique($lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getPagePath (?string $extension = null): string {
|
public static function getPagePath (?string $extension = null): string {
|
||||||
return "./data/" . self::$bookId . "/" . self::$page_id . ($extension == null ? "" : ".".$extension);
|
return "./data/" . self::$bookId . "/" . self::$page_id . ($extension == null ? "" : ".".$extension);
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,8 @@ class ConfigName {
|
|||||||
|
|
||||||
public const robots_txt = "site.robots";
|
public const robots_txt = "site.robots";
|
||||||
|
|
||||||
public const highlightjs = "highlightjs";
|
public const prism = "prism";
|
||||||
public const highlightjs_theme = "highlightjs.theme";
|
public const prism_theme = "prism.theme";
|
||||||
public const highlightjs_lang = "highlightjs.languages";
|
|
||||||
|
|
||||||
public const codeblock_bg = "codeblock.bg-color";
|
public const codeblock_bg = "codeblock.bg-color";
|
||||||
public const codeblock_fg = "codeblock.fg-color";
|
public const codeblock_fg = "codeblock.fg-color";
|
||||||
|
@ -40,8 +40,8 @@ class SiteMeta {
|
|||||||
// "/assets/gitbook/gitbook-plugin-fontsettings/website.css",
|
// "/assets/gitbook/gitbook-plugin-fontsettings/website.css",
|
||||||
// "/assets/gitbook-fix.css",
|
// "/assets/gitbook-fix.css",
|
||||||
// "/assets/ref.css",
|
// "/assets/ref.css",
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false"?
|
(PageMeta::getConfigurationLevelPage(ConfigName::prism)=="false"?
|
||||||
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/".PageMeta::highlightJsTheme().".min.css"),
|
null:"https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/".PageMeta::prismTheme().".min.css"),
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false")?
|
(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false")?
|
||||||
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer-default.min.css",
|
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer-default.min.css",
|
||||||
"/assets/bread-card-markdown.css?ver=2",
|
"/assets/bread-card-markdown.css?ver=2",
|
||||||
@ -50,7 +50,6 @@ class SiteMeta {
|
|||||||
"/assets/bread-card-markdown-heading-permalink.css?ver=1",
|
"/assets/bread-card-markdown-heading-permalink.css?ver=1",
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::ext_listing_rainbow)=="true"?
|
(PageMeta::getConfigurationLevelPage(ConfigName::ext_listing_rainbow)=="true"?
|
||||||
"/assets/bread-card-markdown-enhanced-listing-rainbow.css?ver=1":null),
|
"/assets/bread-card-markdown-enhanced-listing-rainbow.css?ver=1":null),
|
||||||
"/assets/bread-card-markdown-compat-highlight-js.css?ver=2",
|
|
||||||
"/assets/main.css?ver=1",
|
"/assets/main.css?ver=1",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -61,8 +60,10 @@ class SiteMeta {
|
|||||||
// "/assets/gitbook-fix.js",
|
// "/assets/gitbook-fix.js",
|
||||||
// "https://cdn.jsdelivr.net/npm/marked/marked.min.js",
|
// "https://cdn.jsdelivr.net/npm/marked/marked.min.js",
|
||||||
// "/assets/ref.js",
|
// "/assets/ref.js",
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false"?
|
(PageMeta::getConfigurationLevelPage(ConfigName::prism)=="false"?
|
||||||
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"),
|
null:"//cdn.jsdelivr.net/npm/prismjs@v1.x/components/prism-core.min.js"),
|
||||||
|
(PageMeta::getConfigurationLevelPage(ConfigName::prism)=="false"?
|
||||||
|
null:"//cdn.jsdelivr.net/npm/prismjs@v1.x/plugins/autoloader/prism-autoloader.min.js"),
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false"?
|
(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false"?
|
||||||
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer.min.js"),
|
null:"//cdn.jsdelivr.net/gh/suk-ws/regex-colorizer@master/regex-colorizer.min.js"),
|
||||||
(PageMeta::getConfigurationLevelPage(ConfigName::ext_rolling_title)=="true"?
|
(PageMeta::getConfigurationLevelPage(ConfigName::ext_rolling_title)=="true"?
|
||||||
@ -71,8 +72,7 @@ class SiteMeta {
|
|||||||
"/assets/bread-card-markdown-heading-permalink-highlight.js?ver=1":null),
|
"/assets/bread-card-markdown-heading-permalink-highlight.js?ver=1":null),
|
||||||
"/assets/utils-touchscreen-event.js?ver=1",
|
"/assets/utils-touchscreen-event.js?ver=1",
|
||||||
"/assets/main.js?ver=1",
|
"/assets/main.js?ver=1",
|
||||||
),
|
)
|
||||||
self::getHighlightLanguagesJs(PageMeta::highlightJsLanguages())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,12 +106,4 @@ class SiteMeta {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getHighlightLanguagesJs (array $languages): array {
|
|
||||||
$links = array();
|
|
||||||
foreach ($languages as $lang) {
|
|
||||||
$links[] = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/$lang.min.js";
|
|
||||||
}
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
<script>
|
<script>
|
||||||
bookCurrentId = "<?= PageMeta::$bookId ?>";
|
bookCurrentId = "<?= PageMeta::$bookId ?>";
|
||||||
pageCurrentId = "<?= PageMeta::$page_id ?>";
|
pageCurrentId = "<?= PageMeta::$page_id ?>";
|
||||||
<?php if (!(PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false")) :
|
// <?php //if (!(PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false")) :
|
||||||
?>hljs.highlightAll();<?php endif; ?>
|
// ?>//hljs.highlightAll();<?php //endif; ?>
|
||||||
<?php if (!(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false")) :
|
// <?php //if (!(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false")) :
|
||||||
?>RegexColorizer.coloringAll();<?php endif; ?>
|
// ?>//RegexColorizer.coloringAll();<?php //endif; ?>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user