doclax
v2.0.0
Published
A tool for creating books from Markdown
Downloads
3
Readme
Doclax
Doclax is a command-line tool designed to generate different types of document formats (PDF, EPUB, MOBI) from HTML/Markdown input, with a live preview feature to see the output as you work. The tool is built with Node.js and uses several libraries like Puppeteer, epub-gen, and commander to handle various functionalities.
Features
- Convert Markdown/MDX to PDF
- Live preview server with auto-reload
- Easy configuration and customization
Overall Functionalities
- PDF Generation: Convert HTML/Markdown into a PDF file using Puppeteer.
- EPUB Generation: Convert HTML/Markdown into an EPUB file using epub-gen.
- MOBI Generation: Convert HTML/Markdown into a MOBI file (for Kindle).
- Live Preview: Start a local server to preview your content in the browser while working.
Available Commands
generate-pdf
:- Description: Generates a PDF from the
index.html
file in thepublic
folder. - Usage:
npx doclax generate-pdf
- Output: Saves the PDF in the
output
folder asoutput.pdf
.
- Description: Generates a PDF from the
generate-epub
:- Description: Generates an EPUB from the
index.html
file in thepublic
folder. - Usage:
npx doclax generate-epub
- Output: Saves the EPUB in the
output
folder asoutput.epub
.
- Description: Generates an EPUB from the
generate-mobi
:- Description: Generates a MOBI file from the
index.html
file in thepublic
folder. - Usage:
npx doclax generate-mobi
- Output: Saves the MOBI file in the
output
folder asoutput.mobi
.
- Description: Generates a MOBI file from the
start-preview
:- Description: Starts a live preview server to view the content of the
index.html
file in thepublic
folder. - Usage:
npx doclax start-preview
- Output: Opens the preview in your default web browser at
http://localhost:3000
.
- Description: Starts a live preview server to view the content of the
How the Tool Works
Installation:
- Clone the repository to your local machine.
- Navigate to the directory and install the dependencies:
git clone [email protected]:fasakinhenry/Doclax.git cd Doclax npm install
Usage:
- Run any of the available commands listed above using
npx doclax <command>
. - For example, to generate a PDF, you would run:
npx doclax generate-pdf
- This command uses the
index.html
file in thepublic
folder, generates a PDF, and saves it in theoutput
folder.
- Run any of the available commands listed above using
Folder Structure:
- The primary folders and files:
src/
: Contains the main code for each functionality (e.g.,pdf/generator.js
,epub/generator.js
,mobi/generator.js
, etc.).public/
: Contains theindex.html
file used as the input for document generation.output/
: Created automatically to store the generated documents.doclax.config.js
: (Optional) Configuration file for customizing certain aspects of the tool.
- The primary folders and files:
Configuration:
- The tool is designed to work out of the box with minimal configuration. However, a configuration file (
doclax.config.js
) can be added in theconfig
folder if customization is needed.
- The tool is designed to work out of the box with minimal configuration. However, a configuration file (
How to Publish the Tool
Prepare for Publishing:
- Ensure all dependencies are correctly listed in
package.json
. - Update the version number in
package.json
following semantic versioning. - Write a
README.md
file that describes how to install and use the tool.
- Ensure all dependencies are correctly listed in
Login to npm:
- If you don't already have an npm account, create one.
- Log in to npm in your terminal:
npm login
Publish the Package:
- Run the following command to publish the package to the npm registry:
npm publish --access public
- This will make
Doclax
available as an npm package that anyone can install and use globally.
- Run the following command to publish the package to the npm registry:
Global Installation:
- Once published, users can install
Doclax
globally using:npm install -g doclax
- Once published, users can install
Usage After Installation:
- After global installation, the tool can be used directly without
npx
:doclax generate-pdf doclax generate-epub doclax start-preview
- After global installation, the tool can be used directly without
Future Improvements
- Customization: Allow users to customize the output formats (PDF, EPUB, MOBI) more granularly via a configuration file.
- Template Support: Support for different templates for document generation.
- Improved Error Handling: Enhance error messages and validation to guide users when issues arise.
- Markdown Support: Integrate Markdown parsing directly to support Markdown files as input.
Packages used
Here’s what each package does:
- commander: Helps create command-line interfaces.
- puppeteer-core: Used for rendering HTML to PDF.
- remark, unified, remark-parse, remark-rehype, rehype-stringify: Handle Markdown and MDX to HTML conversion.
- figlet: Generates ASCII art from text.
- chalk: Adds color to the terminal output.
- cli-progress: Creates progress bars in the terminal.
Doclax Feature Checklist
[x] PDF Generation
- Generate PDF from compiled chapters.
- Serve and preview PDF in the browser with live reload on changes.
[x] HTML Preview
- Convert chapters to an HTML template.
- Serve and preview HTML in the browser with live reload on changes.
[x] EPUB Generation
- Generate EPUB format and serve it in the browser.
[x] Terminal Interface Enhancements
- Progress bar during file regeneration.
- Figlet branding in the terminal.
- Inquirer-based prompts for preview format selection.
[x] File Watcher Integration
- Automatically regenerate files and update previews using Chokidar.
[ ] Markdown and MDX Support
- Parse and compile Markdown and MDX content into preview formats (HTML, PDF, EPUB).
[ ] Tailwind CSS Integration
- Allow custom styling using Tailwind CSS in generated documents (HTML, PDF).
[ ] Multi-Format Output
- Seamless generation of additional formats like MOBI.
[ ] Live Reload Enhancements
- Improve the speed and efficiency of live reloading for large projects.
[ ] Theming and Customization
- Support theming and customization of documents, including templates, fonts, colors, and layouts.
[ ] Collaboration and Versioning
- Implement collaborative editing and version control features.
[ ] Improved User Interface for CLI
- Further enhance the visual appeal and usability of the CLI interface.
[ ] Command-Line Tool Enhancements
- Add additional commands or options to cater to a broader range of use cases.
[ ] Efficient Image Handling
- Optimize image handling in documents to maintain quality while reducing file sizes.
[ ] PDF-specific Features
- Explore additional PDF features like bookmarks, table of contents, and internal linking.