Chinese typesetting: better Chinese copywriting

Welcome to correct. GitHub address: https://github.com/jxlwqq/chinese-typesetting

Better Chinese copywriting

Unify the usage of Chinese copywriting and typesetting, reduce the communication cost between team members, and enhance the quality of the website.

install

Use composer to install:

composer require "jxlwqq/chinese-typesetting"

Use

Add spaces

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

$text = 'Today, I am Apple Store Purchased a 13 inch MacBook Pro The laptop cost 14188 yuan.';
$chineseTypesetting->insertSpace($text);
// Today, I bought a 13 inch MacBook Pro laptop in the Apple Store, which cost 14188 yuan..

$text = 'αThe carbon atom is the first carbon atom connected with the functional group in the organic matter, and the second isβCarbon atoms, and so on.';
$chineseTypesetting->insertSpace($text);
// α carbon atom is the first carbon atom connected with functional group in organic matter, the second is β carbon atom, and so on.

Add spaces between Chinese and English letters / Greek letters / numbers for mathematics, science and engineering. Reference basis: Chinese copywriting North: blank

At present, the most popular convention is to add spaces between Chinese and English. On this basis, I have increased my support for the Greek alphabet for mathematics, science and engineering.

Full angle half angle

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

$text = 'The name is ABC The cake is only for 1000 yuan.';
$chineseTypesetting->full2Half($text);
// The cake called ABC only costs 1000 yuan.

Limited full width (half width characters are used for English, numbers, spaces and some special characters). Reference basis: Chinese text typesetting refers to the North: full angle and half angle

Clear styles for HTML tags

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

// Clear Class attribute
$text = '<p class="class-name">Hello World!</p>';
$chineseTypesetting->removeClass($text);
// <p>Hello World!</p>

// Clear ID attribute
$text = '<p id="id-name">Hello World!</p>';
$chineseTypesetting->removeId($text);
// <p>Hello World!</p>

// Clear Style properties
$text = '<p style="color: #FFFFFF;">Hello World!</p>';
$chineseTypesetting->removeStyle($text);
// <p>Hello World!</p>

Clear empty paragraph labels

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

// Clear empty paragraph labels
$text = '<p>Hello World!</p><p></p>';
$chineseTypesetting->removeEmptyParagraph($text);
// <p>Hello World!</p>

Clear all empty labels

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

// Clear all empty labels
$text = '<p>Hello World!<span></span></p>';
$chineseTypesetting->removeEmptyTag($text);
// <p>Hello World!</p>

Clear first indent

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

// Clear first indent
$text = '<p>  Hello World!</p>';
$chineseTypesetting->removeIndent($text);
// <p>Hello World!</p>

Is the first line indented, More controversial Personal preference for two spaces at the beginning of a paragraph will destroy the aesthetic point of view.

Use all or specified methods to correct typography

use Jxlwqq\ChineseTypesetting\ChineseTypesetting;

$chineseTypesetting = new ChineseTypesetting();

// Use all methods to correct typography
$text = '<p class="class-name" style="color: #Ffffff; "> Hello world. </p>';
$chineseTypesetting->correct($text);
// <p>Hello world. </p>

// Use specified methods to correct typography
$text = '<p class="class-name" style="color: #Ffffff; "> Hello world. </p>';
$chineseTypesetting->correct($text, ['insertSpace', 'removeClass']);
// < P style = "color:" ffffff; "> Hello world. </p>

Tags: PHP github Attribute

Posted on Fri, 31 Jan 2020 04:50:02 -0800 by Technex