mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2024-12-05 09:26:52 +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:
parent
6e5f71b96b
commit
2820eda6a0
@ -163,6 +163,8 @@ function updatePage (bookId, pageId = "") {
|
|||||||
// history
|
// history
|
||||||
window.history.pushState(document.documentElement.innerHTML, document.title, url);
|
window.history.pushState(document.documentElement.innerHTML, document.title, url);
|
||||||
pageContainer.classList.remove("loading");
|
pageContainer.classList.remove("loading");
|
||||||
|
// post-process
|
||||||
|
updateRef();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
assets/ref.css
Normal file
6
assets/ref.css
Normal 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
15
assets/ref.js
Normal 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();
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const APP_NAME = "ph-Bookshelf";
|
const APP_NAME = "ph-Bookshelf";
|
||||||
|
|
||||||
const VERSION = "0.1-dev";
|
const VERSION = "0.2-dev";
|
||||||
const CHANNEL = "workshop-origin";
|
const CHANNEL = "workshop-origin";
|
||||||
const BRANCH = "master";
|
const BRANCH = "master";
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
require_once "./src/Data/SiteMeta.php";
|
require_once "./src/Data/SiteMeta.php";
|
||||||
require_once "./src/Data/PageMeta.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/PageParse.php";
|
||||||
require_once "./src/Utils/RequestNotExistException.php";
|
require_once "./src/Utils/RequestNotExistException.php";
|
||||||
require_once "./constant.php";
|
require_once "./constant.php";
|
||||||
|
|
||||||
$parser = new Parsedown();
|
$parser = new ParsedownExtend();
|
||||||
|
|
||||||
$parser->setMarkupEscaped(false);
|
$parser->setMarkupEscaped(false);
|
||||||
$parser->setSafeMode(false);
|
$parser->setSafeMode(false);
|
||||||
|
@ -31,6 +31,7 @@ class SiteMeta {
|
|||||||
"/assets/gitbook/style.css",
|
"/assets/gitbook/style.css",
|
||||||
"/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",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ class SiteMeta {
|
|||||||
return array(
|
return 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",
|
||||||
|
"/assets/ref.js",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
src/Utils/ParsedownExtend.php
Normal file
32
src/Utils/ParsedownExtend.php
Normal 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],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user