08-27-周三_17-09-29
This commit is contained in:
21
node_modules/gitbook-plugin-code/LICENSE
generated
vendored
Normal file
21
node_modules/gitbook-plugin-code/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 David Moreno García
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
31
node_modules/gitbook-plugin-code/README.md
generated
vendored
Normal file
31
node_modules/gitbook-plugin-code/README.md
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# Code plugin for GitBook
|
||||
|
||||
Code blocks are cool but can be cooler. This plugin adds lines numbers for multi-line blocks and a copy button to easily copy the content of your block.
|
||||
|
||||
## Cool, can I see it working?
|
||||
|
||||
The next image shows a single line code block:
|
||||
|
||||

|
||||
|
||||
When displaying code with multiple lines, line numbers will be added:
|
||||
|
||||

|
||||
|
||||
## How can I use this plugin?
|
||||
|
||||
You only have to edit your book.json and modify it adding something like this:
|
||||
|
||||
```json
|
||||
"plugins" : [ "code" ],
|
||||
```
|
||||
|
||||
This will set up everything for you. If you want to get rid of the copy buttons use add this section too:
|
||||
|
||||
```json
|
||||
"pluginsConfig": {
|
||||
"code": {
|
||||
"copyButtons": false
|
||||
}
|
||||
}
|
||||
```
|
37
node_modules/gitbook-plugin-code/assets/plugin.css
generated
vendored
Normal file
37
node_modules/gitbook-plugin-code/assets/plugin.css
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
#code-textarea {
|
||||
height: 0;
|
||||
position: fixed;
|
||||
top: -1000px;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.code-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.code-wrapper i {
|
||||
color: #c1c7cd;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
position: absolute;
|
||||
right: 1em;
|
||||
top: 1em;
|
||||
}
|
||||
|
||||
.code-wrapper pre {
|
||||
background: #f7f8f9;
|
||||
border-radius: 3px;
|
||||
counter-reset: line;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.code-wrapper pre > code > span.code-line:before {
|
||||
counter-increment: line;
|
||||
color: #c1c7cd;
|
||||
content: counter(line);
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
margin-right: 1.5em;
|
||||
width: 1em;
|
||||
}
|
91
node_modules/gitbook-plugin-code/assets/plugin.js
generated
vendored
Normal file
91
node_modules/gitbook-plugin-code/assets/plugin.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
require(['gitbook', 'jQuery'], function(gitbook, $) {
|
||||
|
||||
const TERMINAL_HOOK = '**[terminal]'
|
||||
|
||||
var pluginConfig = {};
|
||||
var timeouts = {};
|
||||
|
||||
function addCopyButton(wrapper) {
|
||||
wrapper.append(
|
||||
$('<i class="fa fa-clone t-copy"></i>')
|
||||
.click(function() {
|
||||
copyCommand($(this));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function addCopyTextarea() {
|
||||
|
||||
/* Add also the text area that will allow to copy */
|
||||
$('body').append('<textarea id="code-textarea" />');
|
||||
}
|
||||
|
||||
function copyCommand(button) {
|
||||
pre = button.parent();
|
||||
textarea = $('#code-textarea');
|
||||
textarea.val(pre.text());
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
document.execCommand('copy');
|
||||
pre.focus();
|
||||
updateCopyButton(button);
|
||||
}
|
||||
|
||||
function initializePlugin(config) {
|
||||
pluginConfig = config.code;
|
||||
}
|
||||
|
||||
function format_code_block(block) {
|
||||
/*
|
||||
* Add line numbers for multiline blocks.
|
||||
*/
|
||||
code = block.children('code');
|
||||
lines = code.html().split('\n');
|
||||
|
||||
if (lines[lines.length - 1] == '') {
|
||||
lines.splice(-1, 1);
|
||||
}
|
||||
|
||||
if (lines.length > 1) {
|
||||
console.log(lines);
|
||||
lines = lines.map(line => '<span class="code-line">' + line + '</span>');
|
||||
console.log(lines);
|
||||
code.html(lines.join('\n'));
|
||||
}
|
||||
|
||||
// Add wrapper to pre element
|
||||
wrapper = block.wrap('<div class="code-wrapper"></div>');
|
||||
|
||||
if (pluginConfig.copyButtons) {
|
||||
addCopyButton(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCopyButton(button) {
|
||||
id = button.attr('data-command');
|
||||
button.removeClass('fa-clone').addClass('fa-check');
|
||||
|
||||
// Clear timeout
|
||||
if (id in timeouts) {
|
||||
clearTimeout(timeouts[id]);
|
||||
}
|
||||
timeouts[id] = window.setTimeout(function() {
|
||||
button.removeClass('fa-check').addClass('fa-clone');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
gitbook.events.bind('start', function(e, config) {
|
||||
initializePlugin(config);
|
||||
|
||||
if (pluginConfig.copyButtons) {
|
||||
addCopyTextarea();
|
||||
}
|
||||
});
|
||||
|
||||
gitbook.events.bind('page.change', function() {
|
||||
$('pre').each(function() {
|
||||
format_code_block($(this));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
13
node_modules/gitbook-plugin-code/index.js
generated
vendored
Normal file
13
node_modules/gitbook-plugin-code/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
|
||||
website: {
|
||||
assets: './assets',
|
||||
js: [
|
||||
'plugin.js'
|
||||
],
|
||||
css: [
|
||||
'plugin.css'
|
||||
]
|
||||
}
|
||||
|
||||
};
|
101
node_modules/gitbook-plugin-code/package.json
generated
vendored
Normal file
101
node_modules/gitbook-plugin-code/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "gitbook-plugin-code",
|
||||
"raw": "gitbook-plugin-code@0.1.0",
|
||||
"rawSpec": "0.1.0",
|
||||
"scope": null,
|
||||
"spec": "0.1.0",
|
||||
"type": "version"
|
||||
},
|
||||
"F:\\tmp\\gitbook"
|
||||
]
|
||||
],
|
||||
"_from": "gitbook-plugin-code@0.1.0",
|
||||
"_id": "gitbook-plugin-code@0.1.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-code",
|
||||
"_nodeVersion": "6.11.1",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/gitbook-plugin-code_0.1.0_1521325832371_0.8220407988151179"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "david.mogar@gmail.com",
|
||||
"name": "david.mogar"
|
||||
},
|
||||
"_npmVersion": "5.6.0",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "gitbook-plugin-code",
|
||||
"raw": "gitbook-plugin-code@0.1.0",
|
||||
"rawSpec": "0.1.0",
|
||||
"scope": null,
|
||||
"spec": "0.1.0",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/gitbook-plugin-code/-/gitbook-plugin-code-0.1.0.tgz",
|
||||
"_shasum": "811a9600baef7558ae193cee7d5810001667e97b",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "gitbook-plugin-code@0.1.0",
|
||||
"_where": "F:\\tmp\\gitbook",
|
||||
"author": {
|
||||
"email": "david.mogar@gmail.com",
|
||||
"name": "David Moreno-García"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/davidmogar/gitbook-plugin-code/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Gitbook plugin to change style of code blocks",
|
||||
"devDependencies": {},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"fileCount": 6,
|
||||
"integrity": "sha512-TE8CUFlN7da4SiN2LYx8qk+FX5w2O2IicEcn48sPTpA8gj9qKQqpYpGEdwgsDEev11shEjCZhDwFN//GQ7bdnA==",
|
||||
"shasum": "811a9600baef7558ae193cee7d5810001667e97b",
|
||||
"tarball": "https://registry.npmjs.org/gitbook-plugin-code/-/gitbook-plugin-code-0.1.0.tgz",
|
||||
"unpackedSize": 5586
|
||||
},
|
||||
"engines": {
|
||||
"gitbook": ">2.5.0"
|
||||
},
|
||||
"gitHead": "241bd8e89b0ac53691214ada384777c8658aaa0c",
|
||||
"gitbook": {
|
||||
"properties": {
|
||||
"copyButtons": {
|
||||
"default": true,
|
||||
"title": "Adds buttons to copy the commands",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"homepage": "https://github.com/davidmogar/gitbook-plugin-code",
|
||||
"keywords": [
|
||||
"gitbook",
|
||||
"github",
|
||||
"code",
|
||||
"plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "david.mogar@gmail.com",
|
||||
"name": "david.mogar"
|
||||
}
|
||||
],
|
||||
"name": "gitbook-plugin-code",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/davidmogar/gitbook-plugin-code.git"
|
||||
},
|
||||
"version": "0.1.0"
|
||||
}
|
Reference in New Issue
Block a user