PHPackages                             smmahfujurrahman/docgen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. smmahfujurrahman/docgen

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

smmahfujurrahman/docgen
=======================

A beautiful Laravel package for viewing Markdown documentation with GitHub-style rendering

v1.0.1(7mo ago)027↓90%MITBladePHP ^8.1|^8.2|^8.3

Since Nov 3Pushed 7mo agoCompare

[ Source](https://github.com/MahfujuRahman/docgen)[ Packagist](https://packagist.org/packages/smmahfujurrahman/docgen)[ RSS](/packages/smmahfujurrahman-docgen/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

DocGen - Laravel Documentation Viewer
=====================================

[](#docgen---laravel-documentation-viewer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7405f9536563bb51ca67e063bc8dfdb0f7c13fc7b07214734fa52a420a365f1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6d616866756a75727261686d616e2f646f6367656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smmahfujurrahman/docgen)[![Total Downloads](https://camo.githubusercontent.com/a263f5f831b535443ec533001ae7fbf9b0bdf97a03e33cd103f004bdd0ae5135/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6d616866756a75727261686d616e2f646f6367656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smmahfujurrahman/docgen)

A beautiful Laravel package for viewing Markdown documentation with GitHub-style rendering, search functionality, and zero configuration.

✨ Features
----------

[](#-features)

- 📖 **Beautiful GitHub-Style Rendering** - Professional documentation view
- 🔍 **Real-time Search** - Find docs instantly with Ctrl+K
- 🎨 **Syntax Highlighting** - Code blocks with Highlight.js
- 📱 **Responsive Design** - Works on all devices
- 🔒 **Secure** - Protection against directory traversal
- 📋 **Copy Code Buttons** - One-click code copying
- ⚡ **Zero Configuration** - Works out of the box
- 🗂️ **Folder Organization** - Automatic categorization
- 🎯 **SEO Friendly** - Proper heading structure

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- Laravel 10.x or ^11.x
- Composer

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require smmahfujurrahman/docgen
```

The package will automatically register its service provider.

📦 Publishing Assets
-------------------

[](#-publishing-assets)

Publish all assets at once:

```
php artisan vendor:publish --tag=docgen
```

Or publish specific assets:

```
# Publish configuration
php artisan vendor:publish --tag=docgen-config

# Publish routes
php artisan vendor:publish --tag=docgen-routes

# Publish views
php artisan vendor:publish --tag=docgen-views

# Publish dummy documentation
php artisan vendor:publish --tag=docgen-docs
```

🎯 Usage
-------

[](#-usage)

### Quick Start

[](#quick-start)

1. **Install the package** (see above)
2. **Publish the assets**:

    ```
    php artisan vendor:publish --tag=docgen
    ```
3. **Access your documentation**:

    ```
    http://your-app.test/documentation

    ```

That's it! You'll see the welcome page with dummy documentation.

### Adding Your Documentation

[](#adding-your-documentation)

1. Navigate to the `docs` folder in your Laravel project root
2. Add your `.md` (Markdown) files
3. Refresh the documentation page

**Example structure:**

```
docs/
├── README.md
├── installation.md
├── api/
│   ├── authentication.md
│   └── endpoints.md
└── guides/
    ├── getting-started.md
    └── deployment.md

```

### Linking Routes in Your App

[](#linking-routes-in-your-app)

After publishing, update your `routes/web.php` to include the documentation routes:

```
// At the end of routes/web.php
if (file_exists(base_path('routes/docs.php'))) {
    require base_path('routes/docs.php');
}
```

Or if you want to customize, you can manually define routes using the config:

```
Route::get('/docs', function () {
    // Your custom implementation
});
```

⚙️ Configuration
----------------

[](#️-configuration)

The configuration file will be published to `config/docgen.php`:

```
return [
    // Route prefix for documentation (default: 'documentation')
    'route_prefix' => env('DOCGEN_ROUTE_PREFIX', 'documentation'),

    // Directory where markdown files are stored (default: 'docs')
    'docs_path' => env('DOCGEN_DOCS_PATH', 'docs'),

    // Auto-register routes (default: true)
    'auto_register_routes' => env('DOCGEN_AUTO_ROUTES', true),

    // CommonMark configuration
    'commonmark' => [
        'html_input' => 'allow',
        'allow_unsafe_links' => false,
    ],
];
```

### Environment Variables

[](#environment-variables)

Add these to your `.env` file to customize:

```
DOCGEN_ROUTE_PREFIX=documentation
DOCGEN_DOCS_PATH=docs
DOCGEN_AUTO_ROUTES=true
```

🎨 Customization
---------------

[](#-customization)

### Customizing Views

[](#customizing-views)

Publish the views and modify them:

```
php artisan vendor:publish --tag=docgen-views
```

Views will be copied to `resources/views/documentations/`:

- `docs-index.blade.php` - Documentation index page
- `docs-viewer.blade.php` - Individual document viewer

### Customizing Styles

[](#customizing-styles)

Edit the published views to change colors, fonts, or layout. The views use inline CSS for easy customization.

### Custom Routes

[](#custom-routes)

If you want full control over routes, set `auto_register_routes` to `false` in config and define your own routes:

```
use League\CommonMark\CommonMarkConverter;

Route::get('/my-docs', function () {
    // Your custom documentation logic
});
```

🔒 Security Features
-------------------

[](#-security-features)

DocGen includes built-in security:

1. **File Type Validation**: Only `.md` files are accessible
2. **Directory Traversal Protection**: Prevents `../` attacks
3. **Path Validation**: Uses `realpath()` for secure path resolution
4. **Configurable Paths**: Restrict docs to specific directories

📖 Markdown Support
------------------

[](#-markdown-support)

DocGen supports full Markdown syntax:

### Basic Formatting

[](#basic-formatting)

```
# Heading 1
## Heading 2
### Heading 3

**Bold Text**
*Italic Text*
~~Strikethrough~~

[Link](https://example.com)
![Image](image.jpg)
```

### Code Blocks

[](#code-blocks)

```
```php
