1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 09:26:52 +08:00

add support for highlightjs lang-plugins, bug fixes.

- fix problem that image width is sometimes bigger than 100%
- fix codeblock background config doesn't work
- added codeblock.fg-color config (fix cannot change codeblock text color)
- changes the config name -- make it shorter
This commit is contained in:
A.C.Sukazyo Eyre 2023-01-29 10:41:50 +08:00
parent 4b5a33278f
commit 05f91605c7
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
10 changed files with 224 additions and 29 deletions

View File

@ -11,17 +11,8 @@
############################################################################## ##############################################################################
******************************************************************************/ ******************************************************************************/
:root {
--bcm-color-highlight-bg: #223b5c; /* user define */
}
pre {
background: var(--bcm-color-highlight-bg);
}
.hljs, .hljs,
code.hljs, code.hljs,
pre code.hljs { pre code.hljs {
background: var(--bcm-color-highlight-bg);
padding: 0.2rem 1.2rem 0.6rem; padding: 0.2rem 1.2rem 0.6rem;
} }

View File

@ -245,3 +245,7 @@ mark {
color: var(--bcm-color-font-base-mark); color: var(--bcm-color-font-base-mark);
border-radius: 0.1rem; border-radius: 0.1rem;
} }
img {
max-width: 100%;
}

View File

@ -23,6 +23,7 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-fileinfo": "*", "ext-fileinfo": "*",
"league/commonmark": ">=2.3.8", "league/commonmark": ">=2.3.8",
"symfony/yaml": ">=4.0",
"gregwar/rst": "^1.0", "gregwar/rst": "^1.0",
"xemlock/php-latex": "dev-master" "xemlock/php-latex": "dev-master"
} }

158
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "ffafb389bb041261bde7ae336b613721", "content-hash": "992b2bf6550d780081ce38b8a3010d02",
"packages": [ "packages": [
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
@ -587,6 +587,88 @@
], ],
"time": "2022-11-25T10:21:52+00:00" "time": "2022-11-25T10:21:52+00:00"
}, },
{
"name": "symfony/polyfill-ctype",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-ctype": "*"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.27.0", "version": "v1.27.0",
@ -753,6 +835,80 @@
], ],
"time": "2022-11-03T14:55:06+00:00" "time": "2022-11-03T14:55:06+00:00"
}, },
{
"name": "symfony/yaml",
"version": "v6.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "2bbfbdacc8a15574f8440c4838ce0d7bb6c86b19"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/2bbfbdacc8a15574f8440c4838ce0d7bb6c86b19",
"reference": "2bbfbdacc8a15574f8440c4838ce0d7bb6c86b19",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "^1.8"
},
"conflict": {
"symfony/console": "<5.4"
},
"require-dev": {
"symfony/console": "^5.4|^6.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},
"bin": [
"Resources/bin/yaml-lint"
],
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Yaml\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v6.2.5"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-01-10T18:53:53+00:00"
},
{ {
"name": "xemlock/php-latex", "name": "xemlock/php-latex",
"version": "dev-master", "version": "dev-master",

View File

@ -2,6 +2,6 @@
const APP_NAME = "ph-Bookshelf"; const APP_NAME = "ph-Bookshelf";
const VERSION = "0.3.4"; const VERSION = "0.4.0";
const CHANNEL = "suk-ws"; const CHANNEL = "suk-ws";
const BRANCH = "master"; const BRANCH = "master";

View File

@ -2,6 +2,7 @@
namespace SukWs\Bookshelf\Data; namespace SukWs\Bookshelf\Data;
use SukWs\Bookshelf\Data\SiteConfig\ConfigName;
use SukWs\Bookshelf\Element\BookContent\BookContented; use SukWs\Bookshelf\Element\BookContent\BookContented;
use SukWs\Bookshelf\Element\BookContent\Page; use SukWs\Bookshelf\Element\BookContent\Page;
@ -34,15 +35,36 @@ class PageMeta {
} }
public static function compatibilityOldTitlePolicy (): bool { public static function compatibilityOldTitlePolicy (): bool {
if (self::getConfigurationLevelPage("compatibility.article.title.oldversion") == "true") if (self::getConfigurationLevelPage(ConfigName::old_title_gen) == "true")
return true; return true;
return false; return false;
} }
public static function highlightJsTheme (): string { public static function highlightJsTheme (): string {
$theme = trim(self::getConfigurationLevelPage("customization.article.codeblock.highlightjs.theme")); $theme = trim(self::getConfigurationLevelPage(ConfigName::highlightjs_theme));
if (empty($theme)) return "atom-one-dark"; if (empty($theme)) return "atom-one-dark";
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;
}
$lang = array_unique($lang);
return $lang;
}
} }

View File

@ -3,6 +3,7 @@
namespace SukWs\Bookshelf\Data; namespace SukWs\Bookshelf\Data;
use Exception; use Exception;
use SukWs\Bookshelf\Data\SiteConfig\ConfigName;
use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy; use SukWs\Bookshelf\Data\SiteConfig\RobotsPolicy;
use SukWs\Bookshelf\Element\Bookshelf; use SukWs\Bookshelf\Element\Bookshelf;
@ -39,37 +40,39 @@ 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("customization.article.codeblock.highlightjs")=="false"? (PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false"?
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/".PageMeta::highlightJsTheme().".min.css"), null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/".PageMeta::highlightJsTheme().".min.css"),
(PageMeta::getConfigurationLevelPage("customization.article.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=1", "/assets/bread-card-markdown.css?ver=2",
"/assets/bread-card-markdown-footnote.css?ver=1", "/assets/bread-card-markdown-footnote.css?ver=1",
"/assets/bread-card-markdown-task-list.css?ver=1", "/assets/bread-card-markdown-task-list.css?ver=1",
"/assets/bread-card-markdown-heading-permalink.css?ver=1", "/assets/bread-card-markdown-heading-permalink.css?ver=1",
(PageMeta::getConfigurationLevelPage("customization.article.listing.rainbow.marker")=="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=1", "/assets/bread-card-markdown-compat-highlight-js.css?ver=2",
"/assets/main.css?ver=1", "/assets/main.css?ver=1",
); );
} }
public static function getJavascriptList (): array { public static function getJavascriptList (): array {
return array( return array_merge(array(
// "/assets/gitbook/gitbook.js", // "/assets/gitbook/gitbook.js",
// "/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("customization.article.codeblock.highlightjs")=="false"? (PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false"?
null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"), null:"//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"),
(PageMeta::getConfigurationLevelPage("customization.article.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("enhanced.web.web-title.rolling-title")=="true"? (PageMeta::getConfigurationLevelPage(ConfigName::ext_rolling_title)=="true"?
"/assets/enhanced-rolling-title.js?ver=1":null), "/assets/enhanced-rolling-title.js?ver=1":null),
(PageMeta::getConfigurationLevelPage("customization.article.title.permalink.highlight-on-focus")=="true"? (PageMeta::getConfigurationLevelPage(ConfigName::ext_title_permalink_flash)=="true"?
"/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())
); );
} }
@ -95,7 +98,7 @@ class SiteMeta {
} }
public static function getRobotsPolicy (): RobotsPolicy { public static function getRobotsPolicy (): RobotsPolicy {
return match (self::getConfigurationLevelShelf("site.robots")) { return match (self::getConfigurationLevelShelf(ConfigName::robots_txt)) {
"allow", null => RobotsPolicy::allow, "allow", null => RobotsPolicy::allow,
"deny" => RobotsPolicy::deny, "deny" => RobotsPolicy::deny,
"custom", "file" => RobotsPolicy::file, "custom", "file" => RobotsPolicy::file,
@ -103,4 +106,12 @@ 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;
}
} }

View File

@ -9,6 +9,7 @@ use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\DescriptionList\DescriptionListExtension; use League\CommonMark\Extension\DescriptionList\DescriptionListExtension;
use League\CommonMark\Extension\Footnote\FootnoteExtension; use League\CommonMark\Extension\Footnote\FootnoteExtension;
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension; use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
use League\CommonMark\Extension\Table\TableExtension; use League\CommonMark\Extension\Table\TableExtension;
@ -48,6 +49,9 @@ class Markdown implements PageContentType {
// + heading(title) permalink # [title](#title) // + heading(title) permalink # [title](#title)
$parserEnv->addExtension(new HeadingPermalinkExtension()); $parserEnv->addExtension(new HeadingPermalinkExtension());
// + front matter --- title: Front Matter? ---
$parserEnv->addExtension(new FrontMatterExtension());
// from GitHub Flavor Markdown // from GitHub Flavor Markdown
// + autolink [https://link.to] // + autolink [https://link.to]
// + strikethrough ~~removed~~ // + strikethrough ~~removed~~

View File

@ -1,3 +1,4 @@
<?php use SukWs\Bookshelf\Data\SiteConfig\ConfigName; ?>
<?php use SukWs\Bookshelf\Data\SiteMeta; ?> <?php use SukWs\Bookshelf\Data\SiteMeta; ?>
<?php use SukWs\Bookshelf\Data\PageMeta; ?> <?php use SukWs\Bookshelf\Data\PageMeta; ?>
@ -13,9 +14,9 @@
<script> <script>
bookCurrentId = "<?= PageMeta::$book->getId() ?>"; bookCurrentId = "<?= PageMeta::$book->getId() ?>";
pageCurrentId = "<?= PageMeta::$page->getId() ?>"; pageCurrentId = "<?= PageMeta::$page->getId() ?>";
<?php if (!(PageMeta::getConfigurationLevelPage("customization.article.codeblock.highlightjs")=="false")) : <?php if (!(PageMeta::getConfigurationLevelPage(ConfigName::highlightjs)=="false")) :
?>hljs.highlightAll();<?php endif; ?> ?>hljs.highlightAll();<?php endif; ?>
<?php if (!(PageMeta::getConfigurationLevelPage("customization.article.regex.highlight")=="false")) : <?php if (!(PageMeta::getConfigurationLevelPage(ConfigName::regex_highlight)=="false")) :
?>RegexColorizer.coloringAll();<?php endif; ?> ?>RegexColorizer.coloringAll();<?php endif; ?>
</script> </script>

View File

@ -1,3 +1,4 @@
<?php use SukWs\Bookshelf\Data\SiteConfig\ConfigName; ?>
<?php use SukWs\Bookshelf\Data\SiteMeta; ?> <?php use SukWs\Bookshelf\Data\SiteMeta; ?>
<?php use SukWs\Bookshelf\Data\PageMeta; ?> <?php use SukWs\Bookshelf\Data\PageMeta; ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
@ -26,7 +27,11 @@
<!-- Customs(css) --> <!-- Customs(css) -->
<style> <style>
:root { :root {
----bcm-color-highlight-bg: <?= PageMeta::getConfigurationLevelPage("customization.article.codeblock.background.color") ?>; --bcm-color-codeblock-background: <?= PageMeta::getConfigurationLevelPage(ConfigName::codeblock_bg) ?>;
--bcm-color-codeblock-foreground: <?= PageMeta::getConfigurationLevelPage(ConfigName::codeblock_fg) ?>;
}
pre code {
tab-size: <?= PageMeta::getConfigurationLevelPage(ConfigName::codeblock_tab_size) ?>;
} }
</style> </style>
<style><?= SiteMeta::getCustomCssContent("custom") ?></style> <style><?= SiteMeta::getCustomCssContent("custom") ?></style>