torchlight/torchlight-ibis

为PDF书籍构建工具Ibis设计的Torchlight客户端

v0.1.0 2021-08-05 01:08 UTC

This package is auto-updated.

Last update: 2024-09-05 08:03:18 UTC


README

Latest Stable Version Total Downloads License

为电子书构建工具Ibis设计的Torchlight语法高亮扩展。

Torchlight是一个与VS Code兼容的语法高亮器,无需JavaScript,支持所有语言,所有VS Code主题,行高亮,git diff等功能。

安装

要安装,请通过Composer要求此包

composer require torchlight/torchlight-ibis

如果您还没有这样做,Composer会要求您在书籍目录的根目录中创建一个composer.json文件。

在您的ibis.php文件中,添加以下配置

return [
    /**
     * The book title.
     */
    'title' => 'Laravel Queues in Action',

    // .....

    'configure_commonmark' => function ($environment) {
        \Torchlight\Ibis\TorchlightExtension::make()->register($environment);
    },
];

在您的ibis.php文件顶部,如果还没有,您还需要添加composer自动加载器

<?php

require_once __DIR__ . '/vendor/autoload.php';

return [
    /**
     * The book title.
     */
    'title' => 'Laravel Queues in Action',

    // .....

    'configure_commonmark' => function ($environment) {
        \Torchlight\Ibis\TorchlightExtension::make()->register($environment);
    },
];

要发布Torchlight配置文件,您可以运行./vendor/bin/torchlight。它将在您的ibis.php文件旁边放置一个torchlight.php文件。

您需要添加一些样式到您的样式表中。这些样式与Torchlight使用的默认样式略有不同,因为Ibis使用mPDF将HTML转换为PDF,它有一些具体的要求。

以下是一组良好的起始样式,但请根据您的需求进行调整。

/*
 Margin and rounding are personal preferences,
 overflow-x-auto is recommended.
*/
pre {
    page-break-inside: avoid;
    border: solid 1px #eee;
    margin-bottom: 30px;
    border-radius: 5px;
    overflow-x: auto;
}

/*
 Add some vertical padding and expand the width
 to fill its container. The horizontal padding
 comes at the line level so that background
 colors extend edge to edge.
*/
pre div.torchlight {
    padding-top: 16px;
    padding-bottom: 16px;
}

/*
 Horizontal line padding to match the vertical
 padding from the code block above. Vertical 
 for line height.
*/
pre div.torchlight .line {
    padding: 2px 16px;
}