1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 01:16:53 +08:00

支持了从外来源加载 markdown 内容和 md extra 特性,版本号更新为 0.2-dev

- 将版本号修改为 0.2-dev
- 添加了 <ref source="xx"> 标签声明外源引用文本
  - 添加 marked.js 用于处理外源 markdown 资料
  - 添加了自定义的 `$(xx)` 用于在 md 中声明外源资料
  - 添加了配套的 ref.css 和 ref.js
  - 同时更新了 pjax 支持
- 将 Parsedown 更新为 ParsedownExtra
This commit is contained in:
A.C.Sukazyo Eyre 2021-05-31 17:17:03 +08:00
parent 6e5f71b96b
commit 2820eda6a0
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
7 changed files with 61 additions and 3 deletions

View File

@ -163,6 +163,8 @@ function updatePage (bookId, pageId = "") {
// history
window.history.pushState(document.documentElement.innerHTML, document.title, url);
pageContainer.classList.remove("loading");
// post-process
updateRef();
}
}

6
assets/ref.css Normal file
View File

@ -0,0 +1,6 @@
ref {
display: block;
border: 2px solid var(--color-graystyle);
padding: 1em 2em;
margin: 1.7em 0
}

15
assets/ref.js Normal file
View File

@ -0,0 +1,15 @@
function updateRef () {
for (let node of document.getElementsByTagName("ref")) {
node.innerHTML = "...";
const request = new XMLHttpRequest();
request.open("GET", node.getAttribute("source"), true);
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
node.innerHTML = marked(request.responseText);
} else if (request.readyState === 4) {
node.innerHTML = "ERROR "+ request.status;
}
}
request.send();
}
} updateRef();

View File

@ -2,7 +2,7 @@
const APP_NAME = "ph-Bookshelf";
const VERSION = "0.1-dev";
const VERSION = "0.2-dev";
const CHANNEL = "workshop-origin";
const BRANCH = "master";

View File

@ -3,12 +3,12 @@
require_once "./src/Data/SiteMeta.php";
require_once "./src/Data/PageMeta.php";
require_once "./lib/Parsedown/Parsedown.php";
require_once "./src/Utils/ParsedownExtend.php";
require_once "./src/Utils/PageParse.php";
require_once "./src/Utils/RequestNotExistException.php";
require_once "./constant.php";
$parser = new Parsedown();
$parser = new ParsedownExtend();
$parser->setMarkupEscaped(false);
$parser->setSafeMode(false);

View File

@ -31,6 +31,7 @@ class SiteMeta {
"/assets/gitbook/style.css",
"/assets/gitbook/gitbook-plugin-fontsettings/website.css",
"/assets/gitbook-fix.css",
"/assets/ref.css",
);
}
@ -38,6 +39,8 @@ class SiteMeta {
return array(
"/assets/gitbook/gitbook.js",
"/assets/gitbook-fix.js",
"https://cdn.jsdelivr.net/npm/marked/marked.min.js",
"/assets/ref.js",
);
}

View File

@ -0,0 +1,32 @@
<?php
require_once "./lib/Parsedown/Parsedown.php";
require_once "./lib/Parsedown/ParsedownExtra.php";
class ParsedownExtend extends ParsedownExtra {
function __construct() {
$this->InlineTypes['$'][] = 'RefMarkdown';
$this->inlineMarkerList .= '$';
}
protected function inlineRefMarkdown ($excerpt) {
if (preg_match('/^\$\(([\S ]*?)\)/', $excerpt['text'], $matches)) {
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'ref',
'text' => '',
'attributes' => array(
'source' => $matches[1],
),
),
);
}
}
}