/typographie

Preparation of russian texts before web publication

Primary LanguagePHPMIT LicenseMIT

#Typographie  Build Status

Easy-to-use service for basic typographical preparation of russian texts before web publication.
Also available as an extension for Google Chrome.

Web service

Available as online service at typographie.ru

typographie

Installation

Require packet in a composer.json

"asleepwalker/typographie": "~1.3.0"

Run Composer: php composer.phar install

composer require asleepwalker/typographie "~1.3.0"

Example

Require packet in a composer.json

<?php
use asleepwalker\typographie\Typographie;

	$raw = 'Сервис "Typographie" - подготовка текстов к веб-публикации онлайн (с) 2014-2017';
	$engine = new Typographie('inquot,dashes,specials,paragraphs');
	$result = $engine->process($raw);

	echo $result;
	// > Сервис «Typographie» — подготовка текстов к веб-публикации онлайн © 2014–2017

Library

You can use Typographie as a standalone library in your PHP project.

<?php

	$raw = 'Сервис "Typographie" - подготовка текстов к веб-публикации онлайн (с) 2014-2017';

	require_once('Typographie.php');
	$engine = new Typographie('inquot,dashes,specials,paragraphs');
	$result = $engine->process($raw);

	echo $result;
	// > Сервис «Typographie» — подготовка текстов к веб-публикации онлайн © 2014–2017

Include lib/typographie.class.php or install using Composer asleepwalker/typographie.

API

Web service also has API.

For processing text, you need to create HTTP request and send params using POST method to URL http://api.typographie.ru/.

Parameters

raw (required) : The text to be processed.
actions : List of actions, separated by a comma (default — all).
in : Mode of the input, plain (by default) or html.
out : Mode of the output, plain (by default) or html.

Encoding — UTF-8.

Available actions

quotes : Correction of quotes: "" becomes «».
inquot (needs quotes) : Nested quotes: «„“» (otherwise — duplicate quotes stashing).
dashes : If necessary replace hyphens with dashes and minus signs.
angles : Replace asterisks and quotes with degrees, feet, inches.
dblspace : Fix duplicate spaces in the text.
specials : Insert special characters (from the symbol table).
mathchars : Insert mathematical symbols (from the same table).
punctuation : Fix punctuation, such as spaces before commas.
specialspaces : Fix the wrong skip special characters with spaces.
nbsp : Attach short words to following words in the text.
hellip : Replace repeating dot symbols with ellipsis.
paragraphs : Puts paragraphs (<p>) when converting to HTML (with empty string as a delimeter).
safehtml : Do not process the text inside the HTML-tags <code> and <pre>.

List should be comma separated, somethink like action1,action2,action3.

Response example

The response comes in the JSON format.

{"version":"1.3.0","result":"Your text."}

Error codes

BAD_REQUEST : Not received a required parameter — the text for processing (raw).
ACTIONLIST_EMPTY : Not specified actions. To perform all available actions just skip the action parameter.
ACTIONLIST_INVALID : Non-existent actions found in the list.
INPUT_MODE_INVALID : Invalid input text mode.
OUTPUT_MODE_INVALID : Invalid output text mode.

License

The MIT License.