schibsted-tech-polska/php-content-stylizer 问题修复 & 功能扩展

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

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

schibsted-tech-polska/php-content-stylizer

Composer 安装命令:

composer require schibsted-tech-polska/php-content-stylizer

包简介

Content stylizer for Schibsted Media Platform data

README 文档

README

This library was written to support converting text objects introduced in Schibsted Media Platform's article format version 5 into HTML in PHP.

To use it you have to create Stylizer instance and define a list of supported tags in one of two ways. Then you can use getHtml method passing text and an array with markups and receiving HTML code as an output.

Basic usage:

Defining tags list (method 1):

$stylizer = new \ContentStylizer\Stylizer([
    [
        'beginning' => '<strong>',
        'end' => '</strong>',
        'type' => 'strong',
    ],
]);

Defining tags list (method 2):

$stylizer = new \ContentStylizer\Stylizer();
$stylizer->addTag('strong', '<strong>', '</strong>');

Converting text into HTML:

$text = 'Sample text';
$markups = [
    [
        'length' => 6,
        'offset' => 0,
        'type' => 'strong',
    ],
];

$html = $stylizer->getHtml($text, $markups);

Parameters inside tags:

Both beginning and end attribute of any tag can be defined using string or anonymous function. The second way allows us to add some logic to HTML creation process and to use parameters passed in markup objects.

Let's define link tag:

$stylizer->addTag('link', function (\stdClass $params) {
    return '<a href="' . $params->uri . '" target="_blank">;
}, '</a>');

Then we can use link markup:

$html = $stylizer->getHtml('Our link', [
    [
        'length' => 4,
        'offset' => 4,
        'type' => 'link',
        'uri' => 'http://www.example.com',
    ],
]);

Note that $params object contains all attributes of markup one except length, offset and type which means that in this example it contains only uri parameter.

Singleton tags:

There is also a way of defining singleton tags, e.g. line breaks - Stylizer will treat as singleton every tag without end parameter defined.

It can be defined in an array passed to constructor:

    ...
    [
        'beginning' => '<br>',
        'type' => 'br',
    ],
    ...

We can define it using addTag method as well:

$stylizer->addTag('br', '<br>');

If we define br tag, Stylizer will also add line break in every place in text before PHP_EOL sign occurence.

Tests:

This library contains unit tests and some other CI tools which can be easily run using Node.js. To do it install Node.js environment, then Grunt CLI:

sudo npm install -g grunt-cli

and project dependencies:

npm install

To start testing just simply execute:

grunt test

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 18
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固