diff --git a/assets/gitbook-fix.js b/assets/gitbook-fix.js index 41874cc..6f0bc45 100644 --- a/assets/gitbook-fix.js +++ b/assets/gitbook-fix.js @@ -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(); } } diff --git a/assets/ref.css b/assets/ref.css new file mode 100644 index 0000000..9b6ac88 --- /dev/null +++ b/assets/ref.css @@ -0,0 +1,6 @@ +ref { + display: block; + border: 2px solid var(--color-graystyle); + padding: 1em 2em; + margin: 1.7em 0 +} \ No newline at end of file diff --git a/assets/ref.js b/assets/ref.js new file mode 100644 index 0000000..1e063ca --- /dev/null +++ b/assets/ref.js @@ -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(); diff --git a/constant.php b/constant.php index c9c4e01..c9e96e8 100644 --- a/constant.php +++ b/constant.php @@ -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"; diff --git a/index.php b/index.php index 28286a5..72b258b 100644 --- a/index.php +++ b/index.php @@ -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); diff --git a/src/Data/SiteMeta.php b/src/Data/SiteMeta.php index 65a1fe3..6f27882 100644 --- a/src/Data/SiteMeta.php +++ b/src/Data/SiteMeta.php @@ -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", ); } diff --git a/src/Utils/ParsedownExtend.php b/src/Utils/ParsedownExtend.php new file mode 100644 index 0000000..56df302 --- /dev/null +++ b/src/Utils/ParsedownExtend.php @@ -0,0 +1,32 @@ +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], + ), + ), + + ); + } + } + +}