Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cot_string_truncate counting serial space characters in HTML #1389

Closed
macik opened this issue Jan 13, 2015 · 1 comment
Closed

cot_string_truncate counting serial space characters in HTML #1389

macik opened this issue Jan 13, 2015 · 1 comment

Comments

@macik
Copy link
Member

macik commented Jan 13, 2015

🇬🇧

cot_string_truncate function developed to handle HTML text as well as plain text. But in case of HTML it had unexpected result for text with serial space characters as it treats it as separate symbols.
Thats wrong for HTML as serial space characters should be traated as one space.

Let's get example HTML

<p>
        <span class=\"Underline\"><span class=\"Bold\">Test to be cut</span></span>
   </p><p>Some text</p>

and trying to truncate it by cot_string_truncate($test_str, 8)
We expext

<p>
        <span class=\"Underline\"><span class=\"Bold\">Test to</span></span>
   </p>

but get

<p>        </p>

It hapepend as original HTML had multiple space characters each counted before first <span> tag.

🇷🇺

Функция cot_string_truncate была специально разработана, чтобы работать с текстом содержащим HTML теги и корректного их отображения при обрезке. Однако ее результат не всегда правильный с точки зрения обработки HTML, т.к. сейчас последовательные пробельные символы считаются отдельными. Это не правильно т.к. в HTML такие последовательности отображаются как 1 символ (кроме заключенных в теги plaintext и pre).

Для примера возьмем HTML

<p>
        <span class=\"Underline\"><span class=\"Bold\">Test to be cut</span></span>
   </p><p>Some text</p>

и применим функцию cot_string_truncate($test_str, 8) (т.е. обрезать текст до 8-ми символов)
Ожидая следующее

<p>
        <span class=\"Underline\"><span class=\"Bold\">Test to</span></span>
   </p>

Но получаем пустой параграф

<p>        </p>

Это произошло т.к. перед тегом <span> у нас идет цепочка пробелов, которые посчитались за отдельные символы.

@macik
Copy link
Member Author

macik commented Jan 13, 2015

🇬🇧
Exceptions are cases of pre and plaintext tags where it truncates as plain text.

🇷🇺
Еще необходимо корректно обрабатывать случаи, когда в Html встречаются теги pre или plaintext. Внутри таких тегов код должен восприниматься как обычный текст, т.к. все символы внутри таких тегов в выводятся на экран.

@macik macik closed this as completed in 1c27cef Jan 13, 2015
@Alex300 Alex300 added this to the Siena 0.9.18 milestone Jan 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants