Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building / exporting HTML #28

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ jobs:
run: |
mkdir export
./ibis-next init
./ibis-next build
./ibis-next pdf
./ibis-next epub
./ibis-next html
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.12 - 4th February 2024
- Exporting HTML

## 1.0.11 - 3rd February 2024
- Adding PHPstan for static code analysis
- Adding ext-* dependencies in composer.json
Expand Down
14 changes: 8 additions & 6 deletions ibis-next
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@

use Ibis\Commands\BuildEpubCommand;
use Ibis\Commands\BuildPdfCommand;
use Ibis\Commands\BuildHtmlCommand;
use Ibis\Commands\InitCommand;
use Ibis\Commands\SampleCommand;
use Ibis\Commands\SortContentCommand;
use Symfony\Component\Console\Application;

if (file_exists(__DIR__.'/../../autoload.php')) {
require __DIR__.'/../../autoload.php';
if (file_exists(__DIR__ . '/../../autoload.php')) {
require __DIR__ . '/../../autoload.php';
} else {
require __DIR__.'/vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';
}

/**
* Start the console application.
*/
$app = new Application('Ibis Next', '1.0.x');
$app = new Application('Ibis Next', '1.0.12');
//$app->setDefaultCommand("build");


// Authentication...
$app->add(new InitCommand());
$app->add(new BuildPdfCommand);
$app->add(new BuildHtmlCommand());
$app->add(new BuildPdfCommand());
$app->add(new BuildEpubCommand());
$app->add(new SampleCommand);
$app->add(new SampleCommand());
$app->add(new SortContentCommand());

$app->run();
24 changes: 19 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Create eBooks with Markdown

Ibis Next is an open-source tool developed for ebook creators who want to focus on content creation.
Ibis Next supports writing in Markdown format and can generate ebooks in PDF or EPUB format. The tool aims to simplify the ebook creation process, allowing the writers to concentrate on their content while providing functionality for converting it into polished ebooks efficiently.
Ibis Next supports writing in Markdown format and can generate ebooks in PDF, EPUB or HTML format. The tool aims to simplify the ebook creation process, allowing the writers to concentrate on their content while providing functionality for converting it into polished ebooks efficiently.

### What is Ibis Next?

Expand All @@ -16,15 +16,15 @@ Ibis Next is a PHP-based tool that simplifies the entire eBook creation process.
### Key features

- **Markdown**: Write your content using the simplicity and versatility of Markdown.
- **Automatic Generation**: Effortlessly create PDF or EPUB files with a single command using the `ibis-next pdf` command or `ibis-next epub`.
- **Automatic Generation**: Effortlessly create PDF, EPUB or HTML files with a single command using the `ibis-next pdf` command or `ibis-next epub` or `ibis-next html`.
- **Aesthetic Appeal**: create your eBooks with a custom cover photo, a clickable auto-generated table of contents, and code syntax highlighting.
- **Theme Options**: Choose between two visually appealing themes - Light and Dark (theme support available for PDFs).

### Why Choose Ibis Next?

Ibis Next is a powerful tool for effortlessly creating digital books (e-books) in EPUB and PDF formats. With Ibis Next, writers can concentrate on crafting content without worrying about formatting. The content is authored in Markdown format, allowing for simplicity and flexibility.
Ibis Next is a powerful tool for effortlessly creating digital books (e-books) in EPUB, PDF, and HTML formats. With Ibis Next, writers can concentrate on crafting content without worrying about formatting. The content is authored in Markdown format, allowing for simplicity and flexibility.

Ibis Next seamlessly handles the conversion process, ensuring a hassle-free transition from Markdown to the correct EPUB and PDF formats. Embracing markdown streamlines the writing process and enhances collaboration and ease of editing, making it an ideal choice for authors seeking efficiency and focusing on content creation.
Ibis Next seamlessly handles the conversion process, ensuring a hassle-free transition from Markdown to the correct EPUB, PDF and HTML formats. Embracing markdown streamlines the writing process and enhances collaboration and ease of editing, making it an ideal choice for authors seeking efficiency and focusing on content creation.

Get ready to revolutionize your eBook creation process with Ibis Next!

Expand All @@ -33,7 +33,7 @@ Thank you to Mohamed for creating this tool.
Ibis was used to create [Laravel Queues in Action](https://learn-laravel-queues.com), an eBook Mohamed published in August 2020. [Click here](https://learn-laravel-queues.com/laravel-queues-in-action.zip) for the sample.

We forked the repository to speed up the process of supporting PHP 8.2, **PHP 8.3**, **Laravel 10**, **Symfony 7**, **Commonmark 2**, and other dependencies upgrades.
With Ibis Next, we also added the **support for generating the EPUB format**. So, with Ibis Next, you can create Markdown files and export them into PDF and EPUB for better compatibility with your devices and software.
With Ibis Next, we also added the **support for generating the EPUB format** and **HTML format**. So, with Ibis Next, you can create Markdown files and export them into PDF, EPUB, and HTML for better compatibility with your devices and software.

## Installation

Expand Down Expand Up @@ -110,6 +110,7 @@ This will generate the following files and directories:
- `/assets/theme-light.html`
- `/assets/theme-dark.html`
- `/assets/style.css`
- `/assets/theme-html.html`
- `/content`
- `/ibis.php`

Expand Down Expand Up @@ -315,6 +316,19 @@ You can combine the usage of the `-c` option for defining the content directory

> You can organize your Markdown files in your content directory in subfolders.

### Generating HTML eBook

To automatically generate an HTML file from your Markdown content, use the `html` command:

~~~shell
ibis-next html
~~~

Ibis Next will parse files alphabetically and store the HTML file in the `export` directory. You can easily read the HTML file with any Browsers.

By default, the `assets/theme-html.html` file is used to generate the HTML file.


## Generating A Sample

```
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output = $output;
$this->output->writeln('✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨');
$this->output->writeln('<info>✨ EPUB generation is a Working in Progress!! ✨</info>');
$this->output->writeln('<info>✨ Stay tuned!! ✨</info>');
$this->output->writeln('✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨');
//return 0;
$this->output->writeln('<info>✨ Building EPUB file ✨</info>');

if (!$this->preExecute($input, $output)) {
return Command::INVALID;
Expand Down
116 changes: 116 additions & 0 deletions src/Commands/BuildHtmlCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Ibis\Commands;

use Ibis\Config;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Collection;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;

class BuildHtmlCommand extends BaseBuildCommand
{
/**
* Configure the command.
*
* @return void
*/
protected function configure()
{
$this
->setName('html')

->addOption(
'content',
'c',
InputOption::VALUE_OPTIONAL,
'The path of the content directory',
''
)
->addOption(
'workingdir',
'd',
InputOption::VALUE_OPTIONAL,
'The path of the working directory where `ibis.php` and `assets` directory are located',
''
)
->setDescription('Generate the book in HTML format.');
}

/**
* Execute the command.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output = $output;
$this->output->writeln('<info>✨ Building HTML file ✨</info>');

if (!$this->preExecute($input, $output)) {
return Command::INVALID;
}


$this->ensureExportDirectoryExists($this->config->workingPath);


$this->config->config["breakLevel"] = 1;
$result = $this->buildHtmlFile(
$this->buildHtml($this->config->contentPath, $this->config->config),
$this->config->config,
$this->config->workingPath
);

$this->output->writeln('');
if ($result) {

$this->output->writeln('<info>Book Built Successfully!</info>');
} else {
$this->output->writeln('<error>Book Built Failed!</error>');
}


return Command::SUCCESS;
}


/**
* @throws FileNotFoundException
*/
protected function buildHtmlFile(Collection $chapters, array $config, string $currentPath): bool
{
$template = $this->disk->get($currentPath . '/assets/theme-html.html');
$outputHtml = str_replace("{{\$title}}", $this->config->title(), $template);
$outputHtml = str_replace("{{\$author}}", $this->config->author(), $outputHtml);




$html = "";
foreach ($chapters as $chapter) {
$this->output->writeln('<fg=yellow>==></> ❇️ ' . $chapter["mdfile"] . ' ...');
$html .= $chapter["html"];
}

$outputHtml = str_replace("{{\$body}}", $html, $outputHtml);



$htmlFilename = Config::buildPath(
$currentPath,
"export",
$this->config->outputFileName() . '.html'
);
file_put_contents($htmlFilename, $outputHtml);


$this->output->writeln('<fg=green>==></> HTML file ' . $htmlFilename . ' created');
return true;
}


}
2 changes: 2 additions & 0 deletions src/Commands/BuildPdfCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output = $output;
$this->output->writeln('<info>✨ Building PDF file ✨</info>');


if (!$this->preExecute($input, $output)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'cover-ibis.webp',
'theme-dark.html',
'theme-light.html',
'style.css'
'style.css',
'theme-html.html',
];

foreach ($assetsToCopy as $assetToCopy) {
Expand Down
25 changes: 25 additions & 0 deletions stubs/assets/theme-html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{$title}}</title>
<!-- CSS Reset -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
<!-- Milligram CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
<!-- Highlight CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/github-gist.min.css">
</head>
<body>
<main class='container'>
<div class="row">
<div class="column"><h1>{{$title}}</h1></div>
</div>
<div class="row">
<div class="column"><h2>{{$author}}</h2></div>
</div>
{{$body}}
</main>
</body>
</html>