├── .gitignore ├── LICENSE ├── README.md ├── example ├── README.md ├── docsify-remote-markdown.js └── index.html ├── package.json └── src ├── index.js └── remote-markdown.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | /dist 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 - present, JerryC Huang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docsify-remote-markdown 2 | [![npm](https://img.shields.io/npm/v/docsify-remote-markdown.svg?style=flat-square)](https://www.npmjs.com/package/docsify-remote-markdown) 3 | 4 | ## Install 5 | 1. Configure docsify-remote-markdown (optional): 6 | 7 | ```html 8 | 15 | ``` 16 | 17 | 2. Insert script into docsify document: 18 | 19 | ```html 20 | 21 | ``` 22 | 23 | 24 | ## Usage 25 | Write your remote-markdown code like this: 26 | 27 | ```markdown 28 | [remoteMarkdownUrl](https://raw.githubusercontent.com/docsifyjs/docsify/develop/README.md) 29 | ``` 30 | 31 | It will be replaced by the raw text of the url above into your doc file content. 32 | 33 | ## Options 34 | ## tag 35 | By default, we set the tag as `remoteMarkdownUrl` for you. 36 | However, you can change this options as you like: 37 | 38 | ```javascript 39 | window.$docsify = { 40 | remoteMarkdown: { 41 | tag: 'customTag', 42 | }, 43 | } 44 | ``` 45 | 46 | Will match the code in you doc file: 47 | 48 | ```markdown 49 | [customTag](https://raw.githubusercontent.com/docsifyjs/docsify/develop/README.md) 50 | ``` 51 | 52 | ## Example 53 | - [index.html](example/index.html) 54 | - [README.md](https://raw.githubusercontent.com/jerryc8080/docsify-remote-markdown/master/example/README.md) 55 | 56 | # License 57 | This project is licensed under the [MIT license](LICENSE). 58 | Copyright (c) JerryC Huang (huangjerryc@gmail.com) -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | [remoteMarkdownUrl](https://raw.githubusercontent.com/docsifyjs/docsify/develop/README.md) 4 | -------------------------------------------------------------------------------- /example/docsify-remote-markdown.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | /******/ 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | /******/ 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) { 10 | /******/ return installedModules[moduleId].exports; 11 | /******/ } 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ i: moduleId, 15 | /******/ l: false, 16 | /******/ exports: {} 17 | /******/ }; 18 | /******/ 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | /******/ 22 | /******/ // Flag the module as loaded 23 | /******/ module.l = true; 24 | /******/ 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | /******/ 29 | /******/ 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | /******/ 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | /******/ 36 | /******/ // define getter function for harmony exports 37 | /******/ __webpack_require__.d = function(exports, name, getter) { 38 | /******/ if(!__webpack_require__.o(exports, name)) { 39 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 40 | /******/ } 41 | /******/ }; 42 | /******/ 43 | /******/ // define __esModule on exports 44 | /******/ __webpack_require__.r = function(exports) { 45 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 46 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 47 | /******/ } 48 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 49 | /******/ }; 50 | /******/ 51 | /******/ // create a fake namespace object 52 | /******/ // mode & 1: value is a module id, require it 53 | /******/ // mode & 2: merge all properties of value into the ns 54 | /******/ // mode & 4: return value when already ns object 55 | /******/ // mode & 8|1: behave like require 56 | /******/ __webpack_require__.t = function(value, mode) { 57 | /******/ if(mode & 1) value = __webpack_require__(value); 58 | /******/ if(mode & 8) return value; 59 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 60 | /******/ var ns = Object.create(null); 61 | /******/ __webpack_require__.r(ns); 62 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 63 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 64 | /******/ return ns; 65 | /******/ }; 66 | /******/ 67 | /******/ // getDefaultExport function for compatibility with non-harmony modules 68 | /******/ __webpack_require__.n = function(module) { 69 | /******/ var getter = module && module.__esModule ? 70 | /******/ function getDefault() { return module['default']; } : 71 | /******/ function getModuleExports() { return module; }; 72 | /******/ __webpack_require__.d(getter, 'a', getter); 73 | /******/ return getter; 74 | /******/ }; 75 | /******/ 76 | /******/ // Object.prototype.hasOwnProperty.call 77 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 78 | /******/ 79 | /******/ // __webpack_public_path__ 80 | /******/ __webpack_require__.p = ""; 81 | /******/ 82 | /******/ 83 | /******/ // Load entry module and return exports 84 | /******/ return __webpack_require__(__webpack_require__.s = "./src/index.js"); 85 | /******/ }) 86 | /************************************************************************/ 87 | /******/ ({ 88 | 89 | /***/ "./src/index.js": 90 | /*!**********************!*\ 91 | !*** ./src/index.js ***! 92 | \**********************/ 93 | /*! no exports provided */ 94 | /***/ (function(module, __webpack_exports__, __webpack_require__) { 95 | 96 | "use strict"; 97 | eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _remote_markdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./remote-markdown */ \"./src/remote-markdown.js\");\n\n\nif (!window.$docsify) {\n window.$docsify = {}\n}\n\nwindow.$docsify.plugins = (window.$docsify.plugins || []).concat(_remote_markdown__WEBPACK_IMPORTED_MODULE_0__[\"install\"])\n\n\n//# sourceURL=webpack:///./src/index.js?"); 98 | 99 | /***/ }), 100 | 101 | /***/ "./src/remote-markdown.js": 102 | /*!********************************!*\ 103 | !*** ./src/remote-markdown.js ***! 104 | \********************************/ 105 | /*! exports provided: getFile, install */ 106 | /***/ (function(module, __webpack_exports__, __webpack_require__) { 107 | 108 | "use strict"; 109 | eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getFile\", function() { return getFile; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"install\", function() { return install; });\nfunction getFile(target) {\n return Promise\n .resolve()\n .then(() => fetch(target))\n .then((response) => {\n if (!response.ok) {\n throw new Error('HTTP error, status = ' + response.status);\n }\n return response.text();\n })\n}\n\nfunction install(hook, vm) {\n const config = Object.assign({}, {\n\t\ttag: 'remoteMarkdownUrl',\n\t}, vm.config.remoteMarkdown);\n\n hook.beforeEach(function (content, next) {\n const reg = new RegExp(`\\\\[${config.tag}\\\\]\\\\((http|https://.+)\\\\)`);\n // const reg = /\\[remoteMarkdownUrl\\]\\((http|https:\\/\\/.+)\\)/;\n const result = content.match(reg);\n\n if (result && result[1]) {\n const targetFile = result[1];\n getFile(targetFile)\n .then((data) => next(content.replace(reg, `\\n ${data} \\n`)))\n .catch((err) => console.error(err));\n } else {\n next(content);\n }\n });\n}\n\n\n//# sourceURL=webpack:///./src/remote-markdown.js?"); 110 | 111 | /***/ }) 112 | 113 | /******/ }); -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Docsify-Remote-Markdown Example 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docsify-remote-markdown", 3 | "version": "1.0.1", 4 | "description": "remote markdown plugin of docsify", 5 | "main": "src", 6 | "scripts": { 7 | "build": "npm run build:dev && npm run build:prod", 8 | "build:dev": "webpack src/index.js -o dist/docsify-remote-markdown.js --mode=development", 9 | "build:prod": "webpack src/index.js -o dist/docsify-remote-markdown.min.js --mode=production", 10 | "build:example": "webpack src/index.js -o example/docsify-remote-markdown.js --mode=development" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+ssh://git@github.com/jerryc8080/docsify-remote-markdown.git" 15 | }, 16 | "keywords": [ 17 | "docsify", 18 | "remote markdown" 19 | ], 20 | "files": [ 21 | "src", 22 | "dist", 23 | "README.md" 24 | ], 25 | "author": "JerryC Huang(huangjerryc@gmail.com)", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/jerryc8080/docsify-remote-markdown/issues" 29 | }, 30 | "homepage": "https://github.com/jerryc8080/docsify-remote-markdown#readme", 31 | "devDependencies": { 32 | "webpack": "^4.31.0", 33 | "webpack-cli": "^3.3.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { install } from './remote-markdown' 2 | 3 | if (!window.$docsify) { 4 | window.$docsify = {} 5 | } 6 | 7 | window.$docsify.plugins = (window.$docsify.plugins || []).concat(install) 8 | -------------------------------------------------------------------------------- /src/remote-markdown.js: -------------------------------------------------------------------------------- 1 | export function getFile(target) { 2 | return Promise 3 | .resolve() 4 | .then(() => fetch(target)) 5 | .then((response) => { 6 | if (!response.ok) { 7 | throw new Error('HTTP error, status = ' + response.status); 8 | } 9 | return response.text(); 10 | }) 11 | } 12 | 13 | export function install(hook, vm) { 14 | const config = Object.assign({}, { 15 | tag: 'remoteMarkdownUrl', 16 | }, vm.config.remoteMarkdown); 17 | 18 | hook.beforeEach(function (content, next) { 19 | const reg = new RegExp(`\\[${config.tag}\\]\\((http|https://.+)\\)`); 20 | const result = content.match(reg); 21 | 22 | if (result && result[1]) { 23 | const targetFile = result[1]; 24 | getFile(targetFile) 25 | .then((data) => next(content.replace(reg, `\n ${data} \n`))) 26 | .catch((err) => console.error(err)); 27 | } else { 28 | next(content); 29 | } 30 | }); 31 | } 32 | --------------------------------------------------------------------------------