awcodes/content-faker 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

awcodes/content-faker

Composer 安装命令:

composer require awcodes/content-faker

包简介

Generate fake Markdown, HTML, and rich editor content for Laravel factories, seeders, tests, and previews.

README 文档

README

Generate realistic fake Markdown, HTML, and rich editor content for Laravel model factories, database seeders, rich text previews, documentation examples, renderer tests, CMS demos, and UI screenshots.

The package ships three fluent generators:

MarkdownFaker
HtmlFaker
└── RichEditorFaker

RichEditorFaker is editor-friendly HTML only — it does not require Filament, Tiptap, ProseMirror, Livewire, or any editor package.

Requirements

  • PHP 8.3+
  • Laravel-friendly (works outside a full Laravel app where practical)

Installation

composer require awcodes/content-faker

The service provider is auto-discovered. To customize defaults, publish the config:

php artisan vendor:publish --tag="content-faker-config"

Basic Usage

Every faker exposes a fluent API that returns itself, plus render() / toString() / string casting:

use Awcodes\ContentFaker\MarkdownFaker;

$markdown = MarkdownFaker::make()
    ->h1('Getting Started')
    ->paragraph()
    ->render();

Helper functions are also available:

markdown_faker();
html_faker();
rich_editor_faker();

Markdown Usage

use Awcodes\ContentFaker\MarkdownFaker;

$content = MarkdownFaker::make()
    ->h1('Getting Started')
    ->paragraph()
    ->alert('Make sure your environment is configured.', 'IMPORTANT')
    ->h2('Installation')
    ->codeBlock('composer require vendor/package', 'bash')
    ->unorderedList([
        'Install dependencies',
        'Publish the config',
        'Run migrations',
    ])
    ->render();

GitHub-style alerts use NOTE, TIP, IMPORTANT, WARNING, CAUTION (invalid types fall back to NOTE). callout() delegates to alert().

HTML Usage

use Awcodes\ContentFaker\HtmlFaker;

$content = HtmlFaker::make()
    ->h1('Getting Started')
    ->paragraphs(2)
    ->figure()
    ->h2('Features')
    ->unorderedList([
        'Safe HTML escaping',
        'Inline formatting',
        'Tables',
    ])
    ->render();

HTML output is article-body content only — never <html>, <head>, or <body>. All text and attribute values are escaped.

Rich Editor Usage

use Awcodes\ContentFaker\RichEditorFaker;

$content = RichEditorFaker::make()
    ->h1('Welcome')
    ->paragraphWithMergeTags(['first_name', 'company_name'])
    ->lead()
    ->button('Get Started', '/start')
    ->filamentBlock('hero', [
        'heading' => '{{ company_name }}',
        'subheading' => 'Build faster with realistic demo content.',
    ])
    ->columns(2)
    ->render();

Merge tags render as {{ key }} or {{ key|fallback }}. Keys are validated (letters, numbers, underscores, hyphens, dots); invalid keys fall back to value. Filament block helpers are placeholders only and require no Filament dependency.

Laravel Factory Examples

public function definition(): array
{
    return [
        'title' => fake()->sentence(),

        'markdown_content' => markdown_faker()
            ->docsPage()
            ->render(),

        'html_content' => html_faker()
            ->article()
            ->render(),

        'rich_content' => rich_editor_faker()
            ->paragraphWithMergeTags()
            ->filamentBlock('cta')
            ->render(),
    ];
}

Presets

Each faker implements: article(), blogPost(), docsPage(), technicalDocs(), releaseNotes(). RichEditorFaker overrides article() and docsPage() to include editor-specific content (lead paragraphs, buttons, callouts, columns, merge tags).

Available Methods

Shared across all fakers: make(), render(), toString(), __toString(), withInlineDecorations(), withoutInlineDecorations(), inlineProbability(), linkProbability(), codeProbability(), maxInlineDecorationsPerParagraph(), inlineTypes(), plus heading()/h1()h6(), paragraph(), paragraphs(), lists, codeBlock(), table(), blockquote(), image(), alert(), details(), horizontalRule(), and random().

RichEditorFaker adds: lead(), small(), button(), buttonGroup(), callout(), columns(), customPlaceholder(), mergeTag(), paragraphWithMergeTags(), headingWithMergeTags(), filamentBlock(), filamentBlocks().

Security & Escaping

HtmlFaker and RichEditorFaker escape all generated text and attribute values via htmlspecialchars() with ENT_QUOTES | ENT_SUBSTITUTE. Inline decorations are only applied to text nodes — image/figure attributes and other attribute values are never decorated.

Front Matter

Markdown front matter is opt-in only via frontMatter(). Presets never include front matter.

markdown_faker()
    ->frontMatter(['title' => 'Example', 'description' => 'Example description'])
    ->docsPage()
    ->render();

Testing

composer install
composer test

Code Style

The package uses Laravel Pint for formatting, Rector for automated refactoring, and Larastan for static analysis:

composer format     # apply Pint fixes
composer lint       # check formatting without changing files
composer rector     # apply Rector refactorings
composer rector:dry # preview Rector changes
composer analyse    # run Larastan static analysis

License

MIT — see LICENSE.md.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-24