定制 hirasso/prose 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hirasso/prose

Composer 安装命令:

composer require hirasso/prose

包简介

Format rich text / prose HTML: obfuscate addresses, mark external links, tidy empty tags 🐘

README 文档

README

Latest Version on Packagist Test Status Code Coverage

Format rich text / prose HTML in PHP. Fully HTML5-compatible 🐘

A tiny, framework-agnostic formatter for WYSIWYG / rich text content. Pass a string, get a string back:

  • Obfuscate email/phone links against spam bots (via hirasso/html-obfuscator)
  • Mark external links (target="_blank", custom attributes)
  • Strip tags to an allowlist
  • Remove whitespace-only elements (e.g. empty <p>)

Installation

composer require hirasso/prose

Usage

use Hirasso\Prose\Prose;
use Hirasso\Prose\ProseOptions;

// Minimal: sensible defaults (obfuscate + prune empty <p>)
echo Prose::format($html);

// Configured
echo Prose::format($html, new ProseOptions(
    allowedTags: ['p', 'a', 'br', 'strong', 'em', 'ul', 'li'],
    siteUrl: 'https://example.com',      // required to detect external links
    removeEmptyElements: ['p'],
    obfuscate: true,
));

Note

Prose::format() expects a prose fragment, not a full HTML document. It throws an InvalidArgumentException if the input contains <!doctype>, <html>, <head> or <body>.

Options

Option Default Purpose
allowedTags null Tags to keep when stripping. null = don't strip.
obfuscate true Obfuscate email/phone links.
removeEmptyElements ['p'] Selectors of whitespace-only elements to prune.
siteUrl null Your site's URL. Required to detect external links.
externalLinkAttributes ['data-external' => '', 'target' => '_blank'] Attributes added to external links.

WordPress / ACF

The package ships no framework glue. Wire it into an acf/format_value filter in your project:

add_filter('acf/format_value/type=wysiwyg', function (mixed $value, $postID, array $field): mixed {
    if (!is_string($value) || trim($value) === '') {
        return $value;
    }
    return Prose::format($value, new ProseOptions(
        allowedTags: ['p', 'a', 'br', 'blockquote', 'strong', 'b', 'i', 'em', 'ul', 'li', 'sup'],
        siteUrl: home_url(),
    ));
}, 11, 3);

// Inject the obfuscator client script once, in <head>:
add_action('wp_head', fn () => print(\Hirasso\HTMLObfuscator\clientScript()));

License

MIT © Rasso Hilber

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固