carbon/连字符

在 Neos CMS 中使连字符输入更简单

3.2.0 2023-05-29 16:50 UTC

This package is auto-updated.

Last update: 2024-08-29 19:37:41 UTC


README

Latest stable version Total downloads License GitHub forks GitHub stars GitHub watchers

Neos CMS 的 Carbon.Hyphen 包

简化连字符输入

在 Neos CMS 中输入可选的分词很困难。此包为 phpSyllable 提供了一个 Fusion 包装器。

安装

composer require carbon/hyphen

用法

文本

只需将 Carbon.Hyphen:Text Fusion 对象用作处理器或包装器,处理或包装需要连字符的 Fusion 值。

superlongValue = 'supercalifragilisticexpialidocious'
superlongValue.@process.hyphenate = Carbon.Hyphen:Text {
  locale = 'en-gb'
}

HTML

与文本元素类似,您可以使用 Carbon.Hyphen:Html 处理 HTML 元素。

someFusionHtml.@process.hyphenate = Carbon.Hyphen:Html

Neos CMS 集成示例

您可以使用以下 Fusion 代码轻松激活 Neos CMS 中所有文本和标题节点类型的连字符化

prototype(Foo.Bar:Content.Text) {
  renderer.@process.hyphenate = Carbon.Hyphen:Html
}

prototype(Foo.Bar:Content.Headline) {
  title.@process.hyphenate = Carbon.Hyphen:Text
}

或直接在特定参数上

prototype(Foo.Bar:Component) {
    headline = Neos.Neos:Editable {
        property = 'headline'
        block = false
    }

    renderer = afx`
        <h2>
            <Carbon.Hyphen:Text>{props.headline}</Carbon.Hyphen:Text>
        </h2>
    `
}

参数

locale (字符串) : 引用将进行连字符化的给定字符串的语言
(查看 分词语言 了解可用的语言)

threshold (整数,默认 = 0) : 单词需要具有的最小字符数,在它被连字符化之前。

自定义语言映射

您可能已经定义了一个在 syllable 中不可用的语言。例如,en 不可用,但 en-gb 可用。因此,您可以映射您的语言预设置为另一个 syllable 语言:默认情况下,以下设置在 Settings.Carbon.yaml 中设置

Carbon:
  Hyphen:
    # Throw exception if no hyphen definition is found
    throwException: true
    mapping:
      en: en-gb
      de-de: de
      de-at: de

致谢

此实现受到了 packagefactory/hyphenate 的极大启发。