@david.casillas/writer-chapter-tool
v1.0.0
Published
Command line utility to manage a writing split in chapter files.
Downloads
48
Readme
writer-chapter-tool
Command line utility to manage a lightweight markup writing (markdown for example) split in chapter files.
Prerrequisites
This is a Node.js tool, so you need to have installed it in your system. Download & Install Node.js and the npm package manager.
Geting started
Installing
Install this package globally to have access to the command line cli.
$ npm install -g @david.casillas/writer-chapter-toolConfiguring
By default the tool is configured to work with markdown files, this affects the file extension and the format of the headings inserted in every new chapter file created. There is a config option to change the syntax used, but by now only markdown is supported.
$ wct config-set language markdownThere are 2 options to control the editor used to open chapter files and the preview tool. Set then to your favourite apps using:
$ wct config-set editor BBEdit
$ wct config-set editor MarkdownTo check the current available options:
$ wct config-listAll options are global and will affect all your projects. There is still no local per project settings.
How to use
After installation create a folder to start your project. The folder will start empty.
$ mkdir mybook
$ cd mybookCreating chapters
Start your book creating your first chapter. Since there was nothing created before this will create folders src and src/images in your project folder.
$ wct chapter-create 'Starting here'Now a markdown file for the content of the chapter and a folder src/images/00 to hold the images will be created. Let's see the contents of the project src folder right know:
$ ls -la src
.
|- 00-Starting here.md
|- images
|---- 00
The markdown file contains the header of the chapter:
$ cat src/00-Starting here.md
## Starting hereLet's create another chapter.
$ wct chapter-create 'Other chapter'This will add another chapter, increasing the chapter number. The first chapter is chapter 0.
$ ls -la src
.
|- 00-Starting here.md
|- 01-Other chapter.md
|- images
|---- 00
|---- 01Managing chapters
We can see a list of chapters with the list command.
$ wct chapter-list
00-Starting here
01-Other chapterLet's rename a chapter and change its position in the book.
$ wct chapter-rename 1 'Now I'm the first chapter'
$ wct chapter-move 1 0
$ wct chapter-list
00-Now I'm the first chapter
01-Starting hereNow what was chapter number 1 is now in the 0 position and has been renamed.
We can delete a chapter, ¡be sure to be using version control, since this can not be undone!
$ wct chapter-delete 0
$ wct chapter-list
00-Starting hereAs you can see deleting a chapter reindexes the rest of chapters so they range from 0 to the last chapter.
Adding content to chapters
Finally to start writing on a chapter:
$ wct chapter-edit 0By default the edit command opens the markdown file in BBEdit editor to edit it and in Marked to have a live preview of the content. Check the config section to change the applications used to edit and preview.
In case you need to add images to your document copy the image file in the apropiate folder under src/images matching the chapter number. Then in your document reference the image. Here is an example using markdown syntax.
[images/00/my-image.jpg]()Preview the book
The command preview merges the contents of the src folder into a single markdown file and copies it to the build folder. The images folder is copied as is from src to build so all images keep working with no modification.
The command also opens the result in the application configured to preview the content.
API
This is a full list of all API commands available:
mwt chapter-create <chapter_title>mwt chapter-move <old_chapter_number> <new_chapter_number>mwt chapter-delete <chapter_number>mwt chapter-edit <chapter_number>mwt chapter-rename <chapter_number> <new_title>mwt chapter-listmwt book-compilemwt config-listmwt config-set <property> <value>
API shortcuts
Commands have a shortcut build from the first letter of every command name part. For example the command mwt chapter-list can be written as wct cl.
Config commands do not have a shortcut.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
