diff --git a/.gitattributes b/.gitattributes
index 20c7d6b3..0bb91f72 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,5 +1,6 @@
.gitattributes export-ignore
.gitignore export-ignore
+.github export-ignore
.travis.yml export-ignore
tests export-ignore
*.sh eol=lf
diff --git a/.github/issue_template.md b/.github/issue_template.md
new file mode 100644
index 00000000..750f02ab
--- /dev/null
+++ b/.github/issue_template.md
@@ -0,0 +1,16 @@
+- bug report? yes/no
+- feature request? yes/no
+- version: ?.?.?
+
+### Description
+...
+
+### Steps To Reproduce
+... If possible a minimal demo of the problem ...
+
+
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 00000000..b41cb73a
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,11 @@
+- bug fix? yes/no
+- new feature? yes/no
+- BC break? yes/no
+
+
diff --git a/.travis.yml b/.travis.yml
index 6c80531d..893bb9eb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,7 +29,7 @@ jobs:
# Install Nette Code Checker
- travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-progress
script:
- - php temp/code-checker/src/code-checker.php --short-arrays -i windows-1250.html -i windows-1250.texy
+ - php temp/code-checker/src/code-checker.php --short-arrays
- stage: Code Coverage
diff --git a/composer.json b/composer.json
index ba75a86e..3e10457c 100644
--- a/composer.json
+++ b/composer.json
@@ -23,5 +23,10 @@
"autoload": {
"classmap": ["src/"],
"files": ["src/texy.php"]
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0-dev"
+ }
}
}
diff --git a/contributing.md b/contributing.md
index 8ce237d6..1bec8d4b 100644
--- a/contributing.md
+++ b/contributing.md
@@ -1,27 +1,31 @@
How to contribute & use the issue tracker
=========================================
-The issue tracker is the preferred channel for bug reports, features requests
-and submitting pull requests, but please respect the following restrictions:
+Texy welcomes your contributions. There are several ways to help out:
-* Please **do not** use the issue tracker for personal support requests (use
- [Texy forum](https://forum.texy.info) or [Stack Overflow](http://stackoverflow.com)).
+* Create an issue on GitHub, if you have found a bug
+* Write test cases for open bug issues
+* Write fixes for open bug/feature issues, preferably with test cases included
+* Contribute to the documentation
-* Please **do not** derail or troll issues. Keep the discussion on topic and
- respect the opinions of others.
+Issues
+------
-* Use the GitHub **issue search** — check if the issue has already been
- reported.
+Please **do not use the issue tracker to ask questions**. We will be happy to help you
+on [Texy forum](https://forum.texy.info).
-A good **bug report** shouldn't leave others needing to chase you up for more
+A good bug report shouldn't leave others needing to chase you up for more
information. Please try to be as detailed as possible in your report.
**Feature requests** are welcome. But take a moment to find out whether your idea
fits with the scope and aims of the project. It's up to *you* to make a strong
case to convince the project's developers of the merits of this feature.
-We welcome **pull requests**. If you'd like to contribute, please take a moment
-to [read the guidelines](https://nette.org/en/contributing) in order to make
-the contribution process easy and effective for everyone involved.
+Contributing
+------------
-Thanks!
+The best way to propose a feature is to discuss your ideas on [Texy forum](https://forum.texy.info) before implementing them.
+
+Please do not fix whitespace, format code, or make a purely cosmetic patch.
+
+Thanks! :heart:
diff --git a/examples/1-2-3 start/demo.php b/examples/1-2-3 start/demo.php
index 07e37688..a10c053d 100644
--- a/examples/1-2-3 start/demo.php
+++ b/examples/1-2-3 start/demo.php
@@ -12,7 +12,6 @@
$texy = new Texy();
// other OPTIONAL configuration
-$texy->encoding = 'windows-1250'; // disable UTF-8
$texy->imageModule->root = 'images/'; // specify image folder
$texy->allowed['phrase/ins'] = true;
$texy->allowed['phrase/del'] = true;
@@ -27,7 +26,7 @@
// echo formated output
-header('Content-type: text/html; charset=' . $texy->encoding);
+header('Content-type: text/html; charset=utf-8');
echo '';
echo '
' . $texy->headingModule->title . '';
echo $html;
diff --git a/examples/cache/mytexy.php b/examples/cache/mytexy.php
index 59c36f4f..8ecdc7d0 100644
--- a/examples/cache/mytexy.php
+++ b/examples/cache/mytexy.php
@@ -38,12 +38,12 @@ public function process($text, $useCache = true)
$cacheFile = $this->cachePath . $md5 . '.html';
$content = is_file($cacheFile) ? unserialize(file_get_contents($cacheFile)) : null;
if ($content) { // read from cache
- list($html, $this->styleSheet, $this->headingModule->title) = $content;
+ list($html, $this->headingModule->title) = $content;
} else { // doesn't exists
$html = parent::process($text);
file_put_contents($cacheFile,
- serialize([$html, $this->styleSheet, $this->headingModule->title])
+ serialize([$html, $this->headingModule->title])
);
}
diff --git a/examples/syntax highlighting/demo-geshi.php b/examples/syntax highlighting/demo-geshi.php
index 4139ce29..224a70a2 100644
--- a/examples/syntax highlighting/demo-geshi.php
+++ b/examples/syntax highlighting/demo-geshi.php
@@ -56,7 +56,8 @@ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content,
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
// save generated stylesheet
- $texy->styleSheet .= $geshi->get_stylesheet();
+ global $styleSheet
+ $styleSheet .= $geshi->get_stylesheet();
$content = $geshi->parse_code();
@@ -76,7 +77,7 @@ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content,
$texy->addHandler('block', 'blockHandler');
// prepare CSS stylesheet
-$texy->styleSheet = 'pre { padding:10px } ';
+$styleSheet = 'pre { padding:10px } ';
// processing
$text = file_get_contents('sample.texy');
@@ -84,7 +85,7 @@ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content,
// echo Geshi Stylesheet
header('Content-type: text/html; charset=utf-8');
-echo '';
+echo '';
echo '' . $texy->headingModule->title . '';
// echo formated output
echo $html;
diff --git a/readme.md b/readme.md
index 3f01e040..c0b0a204 100644
--- a/readme.md
+++ b/readme.md
@@ -3,6 +3,7 @@ Texy! [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https:
[![Downloads this Month](https://img.shields.io/packagist/dm/texy/texy.svg)](https://packagist.org/packages/texy/texy)
[![Build Status](https://travis-ci.org/dg/texy.svg?branch=master)](https://travis-ci.org/dg/texy)
+[![Coverage Status](https://coveralls.io/repos/github/dg/texy/badge.svg?branch=master)](https://coveralls.io/github/dg/texy?branch=master)
[![Latest Stable Version](https://poser.pugx.org/dg/texy/v/stable)](https://github.com/dg/texy/releases)
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/dg/texy/blob/master/license.md)
@@ -27,3 +28,9 @@ Refer to the 'examples' directory for examples. Texy documentation is
available on the homepage https://texy.info.
If you like Texy, **[please make a donation now](https://nette.org/make-donation?to=texy)**. Thank you!
+
+
+Dockerized Texy service
+-----------------------
+
+I am not quite sure how to contact the Texy community anywhere else, so herebe I am letting you know that I created a [Docker image with Texy converter](https://hub.docker.com/r/ondrazizka/texy-service/tags/).
diff --git a/src/Texy/DTD.php b/src/Texy/DTD.php
index 67554e4b..f1d17e31 100644
--- a/src/Texy/DTD.php
+++ b/src/Texy/DTD.php
@@ -470,3 +470,5 @@
$dtd['th'][0] += ['nowrap' => 1, 'bgcolor' => 1, 'width' => 1, 'height' => 1];
// missing: FRAMESET, FRAME, BGSOUND, XMP, ...
+
+return $dtd;
diff --git a/src/Texy/HandlerInvocation.php b/src/Texy/HandlerInvocation.php
index 964be387..840c037b 100644
--- a/src/Texy/HandlerInvocation.php
+++ b/src/Texy/HandlerInvocation.php
@@ -78,10 +78,4 @@ public function getTexy()
{
return $this->parser->getTexy();
}
-
-
- /** @deprecated */
- public function free()
- {
- }
}
diff --git a/src/Texy/HtmlElement.php b/src/Texy/HtmlElement.php
index 7fb618f5..4463eb24 100644
--- a/src/Texy/HtmlElement.php
+++ b/src/Texy/HtmlElement.php
@@ -159,24 +159,6 @@ final public function &__get($name)
}
- /**
- * Overloaded setter for element's attribute.
- * @param string attribute name
- * @param array value
- * @return self
- */
-/*
- final public function __call($m, $args)
- {
- if (count($args) !== 1) {
- throw new \InvalidArgumentException("Just one argument is required.");
- }
- $this->attrs[$m] = $args[0];
- return $this;
- }
-*/
-
-
/**
* Special setter for element's attribute.
* @param string path
diff --git a/src/Texy/Modules/BlockModule.php b/src/Texy/Modules/BlockModule.php
index d17d2655..ba9e45ec 100644
--- a/src/Texy/Modules/BlockModule.php
+++ b/src/Texy/Modules/BlockModule.php
@@ -83,14 +83,6 @@ public function pattern(Texy\BlockParser $parser, array $matches)
}
- // for backward compatibility
- public function outdent($s)
- {
- trigger_error('Use Texy\Helpers::outdent()', E_USER_WARNING);
- return Helpers::outdent($s);
- }
-
-
/**
* Finish invocation.
* @return HtmlElement|string|false
diff --git a/src/Texy/Modules/FigureModule.php b/src/Texy/Modules/FigureModule.php
index 1ee6dfdb..1fda0e8f 100644
--- a/src/Texy/Modules/FigureModule.php
+++ b/src/Texy/Modules/FigureModule.php
@@ -38,7 +38,7 @@ public function __construct($texy)
$texy->registerBlockPattern(
[$this, 'pattern'],
'#^\[\* *+([^\n' . Patterns::MARK . ']{1,1000})' . Patterns::MODIFIER . '? *+(\*|(?|<)\]' // [* urls .(title)[class]{style} >]
- . '(?::(' . Patterns::LINK_URL . '|:))?? ++\*\*\* ++(.{0,2000})' . Patterns::MODIFIER_H . '?()$#mUu',
+ . '(?::(' . Patterns::LINK_URL . '|:))??(?: ++\*\*\* ++(.{0,2000}))?' . Patterns::MODIFIER_H . '?()$#mUu',
'figure'
);
}
@@ -102,8 +102,12 @@ public function solve(Texy\HandlerInvocation $invocation, Texy\Image $image, Tex
$mod->decorate($texy, $el);
$el[0] = $elImg;
- $el[1] = new Texy\HtmlElement('p');
- $el[1]->parseLine($texy, ltrim($content));
+
+ $content = ltrim($content);
+ if ($content) {
+ $el[1] = new Texy\HtmlElement('p');
+ $el[1]->parseLine($texy, $content);
+ }
$class = $this->class;
if ($hAlign) {
diff --git a/src/Texy/Modules/ImageModule.php b/src/Texy/Modules/ImageModule.php
index 1c5f232a..9b9592ef 100644
--- a/src/Texy/Modules/ImageModule.php
+++ b/src/Texy/Modules/ImageModule.php
@@ -134,7 +134,7 @@ public function patternImage(Texy\LineParser $parser, array $matches)
*/
public function addReference($name, Image $image)
{
- $image->name = Texy\Utf::strtolower($name);
+ $image->name = function_exists('mb_strtolower') ? mb_strtolower($name, 'UTF-8') : $name;
$this->references[$image->name] = $image;
}
@@ -146,7 +146,7 @@ public function addReference($name, Image $image)
*/
public function getReference($name)
{
- $name = Texy\Utf::strtolower($name);
+ $name = function_exists('mb_strtolower') ? mb_strtolower($name, 'UTF-8') : $name;
if (isset($this->references[$name])) {
return clone $this->references[$name];
}
diff --git a/src/Texy/Modules/LinkModule.php b/src/Texy/Modules/LinkModule.php
index a6ce1665..26cea1ea 100644
--- a/src/Texy/Modules/LinkModule.php
+++ b/src/Texy/Modules/LinkModule.php
@@ -190,7 +190,7 @@ public function patternUrlEmail(LineParser $parser, array $matches, $name)
*/
public function addReference($name, Link $link)
{
- $link->name = Texy\Utf::strtolower($name);
+ $link->name = function_exists('mb_strtolower') ? mb_strtolower($name, 'UTF-8') : $name;
$this->references[$link->name] = $link;
}
@@ -202,7 +202,7 @@ public function addReference($name, Link $link)
*/
public function getReference($name)
{
- $name = Texy\Utf::strtolower($name);
+ $name = function_exists('mb_strtolower') ? mb_strtolower($name, 'UTF-8') : $name;
if (isset($this->references[$name])) {
return clone $this->references[$name];
diff --git a/src/Texy/Texy.php b/src/Texy/Texy.php
index 59b5db57..0e2224aa 100644
--- a/src/Texy/Texy.php
+++ b/src/Texy/Texy.php
@@ -25,7 +25,7 @@ class Texy
const NONE = false;
// Texy version
- const VERSION = '2.9.3';
+ const VERSION = '3.0-dev';
const REVISION = 'released on 2018-06-22';
// types of protection marks
@@ -49,9 +49,6 @@ class Texy
const XHTML1_STRICT = 3; // Texy::HTML4_STRICT | Texy::XML;
const XHTML5 = 6; // Texy::HTML5 | Texy::XML;
- /** @var string input & output text encoding */
- public $encoding = 'utf-8';
-
/** @var array Texy! syntax configuration */
public $allowed = [];
@@ -83,9 +80,6 @@ class Texy
'preload' => [],
];
- /** @var string Generated stylesheet */
- public $styleSheet = '';
-
/** @var array CSS classes for align modifiers */
public $alignClasses = [
'left' => null,
@@ -100,9 +94,6 @@ class Texy
/** @var bool remove soft hyphens (SHY)? */
public $removeSoftHyphens = true;
- /** @deprecated */
- public static $advertisingNotice = false;
-
/** @var string */
public $nontextParagraph = 'div';
@@ -208,12 +199,6 @@ class Texy
private $mode;
- /** DEPRECATED */
- public static $strictDTD;
- public $cleaner;
- public $xhtml;
-
-
public function __construct()
{
if (defined('PCRE_VERSION') && PCRE_VERSION == 8.34 && PHP_VERSION_ID < 50513) {
@@ -225,18 +210,9 @@ public function __construct()
trigger_error("Texy: mb_internal_encoding changed to 'pass'", E_USER_WARNING);
}
- // load all modules
$this->loadModules();
- // DEPRECATED
- if (self::$strictDTD !== null) {
- $this->setOutputMode(self::$strictDTD ? self::XHTML1_STRICT : self::XHTML1_TRANSITIONAL);
- } else {
- $this->setOutputMode(self::XHTML1_TRANSITIONAL);
- }
-
- // DEPRECATED
- $this->cleaner = &$this->htmlOutputModule;
+ $this->setOutputMode(self::XHTML1_TRANSITIONAL);
// examples of link references ;-)
$link = new Link('https://texy.info/');
@@ -266,8 +242,7 @@ public function setOutputMode($mode)
}
if (!isset(self::$dtdCache[$mode])) {
- require __DIR__ . '/DTD.php';
- self::$dtdCache[$mode] = $dtd;
+ self::$dtdCache[$mode] = require __DIR__ . '/DTD.php';
}
$this->mode = $mode;
@@ -405,9 +380,6 @@ public function process($text, $singleLine = false)
$this->_styles = $this->allowedStyles;
}
- // convert to UTF-8 (and check source encoding)
- $text = Utf::toUtf($text, $this->encoding);
-
if ($this->removeSoftHyphens) {
$text = str_replace("\xC2\xAD", '', $text);
}
@@ -458,8 +430,7 @@ public function process($text, $singleLine = false)
$html = str_replace("\r", "\n", $html);
$this->processing = false;
-
- return Utf::utf2html($html, $this->encoding);
+ return $html;
}
@@ -477,14 +448,11 @@ public function processLine($text)
/**
* Makes only typographic corrections.
- * @param string input text (in encoding defined by Texy::$encoding)
- * @return string output text (in UTF-8)
+ * @param string input text
+ * @return string output text
*/
public function processTypo($text)
{
- // convert to UTF-8 (and check source encoding)
- $text = Utf::toUtf($text, $this->encoding);
-
// standardize line endings and spaces
$text = Helpers::normalize($text);
@@ -495,7 +463,7 @@ public function processTypo($text)
$text = $this->longWordsModule->postLine($text);
}
- return Utf::utf2html($text, $this->encoding);
+ return $text;
}
@@ -509,12 +477,12 @@ public function toText()
throw new \RuntimeException('Call $texy->process() first.');
}
- return Utf::utfTo($this->DOM->toText($this), $this->encoding);
+ return $this->DOM->toText($this);
}
/**
- * Converts internal string representation to final HTML code in UTF-8.
+ * Converts internal string representation to final HTML code.
* @return string
*/
final public function stringToHtml($s)
@@ -554,7 +522,7 @@ final public function stringToHtml($s)
/**
- * Converts internal string representation to final HTML code in UTF-8.
+ * Converts internal string representation to final HTML code.
* @return string
*/
final public function stringToText($s)
@@ -760,9 +728,4 @@ final public static function prependRoot($URL, $root)
return Helpers::prependRoot($URL, $root);
}
-
- /** @deprecated */
- final public function free()
- {
- }
}
diff --git a/src/Texy/Utf.php b/src/Texy/Utf.php
deleted file mode 100644
index c0f5fb61..00000000
--- a/src/Texy/Utf.php
+++ /dev/null
@@ -1,134 +0,0 @@
- charset table
- self::$xlat = &self::$xlatCache[strtolower($encoding)];
- if (!self::$xlat) {
- for ($i = 128; $i < 256; $i++) {
- $ch = @iconv($encoding, 'UTF-8//IGNORE', chr($i)); // intentionally @
- if ($ch) {
- self::$xlat[$ch] = chr($i);
- }
- }
- }
-
- // convert
- return preg_replace_callback('#[\x80-\x{FFFF}]#u', [__CLASS__, 'cb'], $s);
- }
-
-
- /**
- * Callback; converts UTF-8 to HTML entity OR character in dest encoding.
- */
- private static function cb($m)
- {
- $m = $m[0];
- if (isset(self::$xlat[$m])) {
- return self::$xlat[$m];
- }
-
- $ch1 = ord($m[0]);
- $ch2 = ord($m[1]);
- if (($ch2 >> 6) !== 2) {
- return '';
- }
-
- if (($ch1 & 0xE0) === 0xC0) {
- return '' . ((($ch1 & 0x1F) << 6) + ($ch2 & 0x3F)) . ';';
- }
-
- if (($ch1 & 0xF0) === 0xE0) {
- $ch3 = ord($m[2]);
- if (($ch3 >> 6) !== 2) {
- return '';
- }
- return '' . ((($ch1 & 0xF) << 12) + (($ch2 & 0x3F) << 06) + (($ch3 & 0x3F))) . ';';
- }
-
- return '';
- }
-}
diff --git a/src/compatibility.php b/src/compatibility.php
deleted file mode 100644
index 9b7e60d3..00000000
--- a/src/compatibility.php
+++ /dev/null
@@ -1,29 +0,0 @@
- 'Texy.php',
- 'Texy\BlockParser' => 'BlockParser.php',
- 'Texy\Configurator' => 'Configurator.php',
- 'Texy\HandlerInvocation' => 'HandlerInvocation.php',
- 'Texy\Helpers' => 'Helpers.php',
- 'Texy\HtmlElement' => 'HtmlElement.php',
- 'Texy\LineParser' => 'LineParser.php',
- 'Texy\Modifier' => 'Modifier.php',
- 'Texy\Module' => 'Module.php',
- 'Texy\Parser' => 'Parser.php',
- 'Texy\Patterns' => 'Patterns.php',
- 'Texy\Regexp' => 'Regexp.php',
- 'Texy\Strict' => 'Strict.php',
- 'Texy\Utf' => 'Utf.php',
- 'Texy\Modules\BlockModule' => 'Modules/BlockModule.php',
- 'Texy\Modules\BlockQuoteModule' => 'Modules/BlockQuoteModule.php',
- 'Texy\Modules\EmoticonModule' => 'Modules/EmoticonModule.php',
- 'Texy\Modules\FigureModule' => 'Modules/FigureModule.php',
- 'Texy\Modules\HeadingModule' => 'Modules/HeadingModule.php',
- 'Texy\Modules\HorizLineModule' => 'Modules/HorizLineModule.php',
- 'Texy\Modules\HtmlModule' => 'Modules/HtmlModule.php',
- 'Texy\Modules\HtmlOutputModule' => 'Modules/HtmlOutputModule.php',
- 'Texy\Image' => 'Image.php',
- 'Texy\Modules\ImageModule' => 'Modules/ImageModule.php',
- 'Texy\Link' => 'Link.php',
- 'Texy\Modules\LinkModule' => 'Modules/LinkModule.php',
- 'Texy\Modules\ListModule' => 'Modules/ListModule.php',
- 'Texy\Modules\LongWordsModule' => 'Modules/LongWordsModule.php',
- 'Texy\Modules\ParagraphModule' => 'Modules/ParagraphModule.php',
- 'Texy\Modules\PhraseModule' => 'Modules/PhraseModule.php',
- 'Texy\Modules\ScriptModule' => 'Modules/ScriptModule.php',
- 'Texy\Modules\TableCellElement' => 'Modules/TableCellElement.php',
- 'Texy\Modules\TableModule' => 'Modules/TableModule.php',
- 'Texy\Modules\TypographyModule' => 'Modules/TypographyModule.php',
- ], $old2new = [
+ static $old2new = [
'Texy' => 'Texy\Texy',
'TexyConfigurator' => 'Texy\Configurator',
'TexyHtml' => 'Texy\HtmlElement',
@@ -60,9 +25,7 @@
'TexyLongWordsModule' => 'Texy\Modules\LongWordsModule',
'TexyTypographyModule' => 'Texy\Modules\TypographyModule',
];
- if (isset($map[$class])) {
- require __DIR__ . '/Texy/' . $map[$class];
- } elseif (isset($old2new[$class])) {
+ if (isset($old2new[$class])) {
class_alias($old2new[$class], $class);
}
});
@@ -74,5 +37,3 @@ class_alias($old2new[$class], $class);
'TexyImage',
'TexyLink',
]);
-
-require_once __DIR__ . '/compatibility.php';
diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml
new file mode 100644
index 00000000..82764a3f
--- /dev/null
+++ b/tests/.coveralls.yml
@@ -0,0 +1,4 @@
+# for php-coveralls
+service_name: travis-ci
+coverage_clover: coverage.xml
+json_path: coverage.json
diff --git a/tests/Texy/expected/special.html b/tests/Texy/expected/special.html
index 91ad2fa3..97b889f0 100644
--- a/tests/Texy/expected/special.html
+++ b/tests/Texy/expected/special.html
@@ -1,4 +1,4 @@
-
Texy! je pøevadìè textu do formátovaného HTML kódu. Díky nìmu
-mùžete psát strukturované dokumenty i bez znalosti nebo použití jazyka
-HTML. Dokument napíšete v pøehledné, èistì textové, formì a Texy! jej
-automaticky pøevede do validního (X)HTML kódu.
-
-
Texy! je jedním z nejkomplexnìjších formátovaèù.
-Umí zpracovávat obrázky, odkazy, vnoøené seznamy, tabulky a má také plnou
-podporu CSS.
-
-
-
rozdìlení velmi dlouhých slov podle èeských pravidel. Pøíklad:
- nejneobhospodaøovávatelnìjšími