File tree Expand file tree Collapse file tree 4 files changed +280
-6
lines changed
Expand file tree Collapse file tree 4 files changed +280
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ GitBook Plugin for including file.
661 . [ Installation] ( #installation )
772 . [ Plugin options] ( #plugin-options )
883 . [ Usage] ( #usage )
9+ 4 . [ Example] ( #example )
10+ 5 . [ CLI] ( #cli )
911
1012
1113## Installation
@@ -172,7 +174,7 @@ Option can be passed locally and may depend on the template your are using.
172174| ` title ` | ` "<your title>" ` | Title for the code ** full template required** |
173175| ` name ` | ` "<your_filename>" ` | name of the included file ** full template required** |
174176| ` class ` | ` "<your_classname>" ` | html class for the title ** full template required** |
175- | ` id ` | ` "<your_id>" ` | hmlt class for custom style ** full template required** |
177+ | ` id ` | ` "<your_id>" ` | html class for custom style ** full template required** |
176178| ` label ` | ` "<your_ref_label>" ` | reference label (latex like) ** full template required** |
177179| ` edit ` | ` {"true","false"} ` | allow edit code (** ace template required** ) |
178180| ` check ` | ` {"true","false"} ` | check syntax (** ace template required** ) |
@@ -331,6 +333,15 @@ Please See [examples/](examples/).
331333
332334[ ![ screenshot] ( https://monosnap.com/file/ydUDWzqXtC2bvPPBmqtplldO8l2QJK.png )] ( example/ )
333335
336+ ## CLI
337+
338+ This gitbook plugin include Command line tools.
339+ It just convert markdown to markdown.
340+
341+ $ npm install -g gitbook-plugin-include-codeblock
342+ # Convert Markdown to Markdown
343+ $ include-codeblock ./README.md --output RENDER_README.md
344+
334345## FAQ
335346
336347### How to migrate Version 1.x to 2.x
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ 'use strict' ;
3+ const meow = require ( 'meow' ) ;
4+ const fs = require ( 'fs' ) ;
5+ const path = require ( 'path' ) ;
6+ const parse = require ( "../lib/parser" ) . parse ;
7+ const cli = meow ( `
8+ Usage
9+ $ include-codeblock <input-file-path> --output <output-file-path>
10+
11+ Options
12+ --output Output to write index json file
13+
14+ Other Options:
15+ same with gitbook config
16+ For example, --unindent=true
17+
18+ Example:
19+ $ include-codeblock ./README.md --output RENDER_README.md
20+ ` ) ;
21+ // main
22+ const input = cli . input [ 0 ] ;
23+ if ( ! input ) {
24+ cli . showHelp ( ) ;
25+ }
26+ const inputContent = fs . readFileSync ( input , "utf-8" ) ;
27+ const baseDir = path . dirname ( path . resolve ( process . cwd ( ) , input ) ) ;
28+ const replacements = parse ( inputContent , baseDir , cli . flags ) ;
29+ const replaceContent = ( inputContent , replacements ) => {
30+ replacements . forEach ( result => {
31+ const { target, replaced } = result ;
32+ inputContent = inputContent . replace ( target , replaced ) ;
33+ } ) ;
34+ return inputContent ;
35+ } ;
36+ const outputContent = replaceContent ( inputContent , replacements ) ;
37+ if ( cli . flags . output ) {
38+ fs . writeFileSync ( cli . flags . output , outputContent , "utf-8" ) ;
39+ } else {
40+ console . log ( outputContent ) ;
41+ }
Original file line number Diff line number Diff line change 1414 "version" : " 3.1.4" ,
1515 "description" : " GitBook plugin for including file" ,
1616 "main" : " lib/include-codeblock.js" ,
17+ "bin" : {
18+ "include-codeblock" : " ./bin/include-codeblock.js"
19+ },
1720 "files" : [
1821 " lib" ,
1922 " templates" ,
9093 },
9194 "dependencies" : {
9295 "entities" : " ^1.1.1" ,
93- "language-map" : " ^1.1.1" ,
9496 "handlebars" : " ^4.0.5" ,
97+ "language-map" : " ^1.1.1" ,
98+ "meow" : " ^4.0.0" ,
9599 "winston-color" : " ^1.0.0"
96100 },
97101 "devDependencies" : {
You can’t perform that action at this time.
0 commit comments