Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

## [0.36.1] - 2026-11-13

### Changed (JS/TS port)
- **Headings are left untouched by default** in `humanizeHtml()`: `headingFactor`
now defaults to `0` (was `0.45`) because h1–h6 carry SEO keywords. Pass a
positive `headingFactor` to opt back in.
- **No comma after bare adverbs** opening a sentence ("Также X", "Także X",
"También X" instead of "Также, X").
- **No colon openers** ("Заметим:", "Zauważmy:") when the dictionary entry has
a regular alternative.
- **`warnings` in `humanizeHtml()` results** — words mixing Cyrillic and Latin
letters ("манning") are reported (`{ type: 'mixed_script', token }`). They are
generator glitches or homoglyphs; the intended spelling is unknown, so they are
reported rather than fixed. Found in 3 of 40 live production articles.

## [0.36.0] - 2026-11-13

### JS/TS port: new publication-safe engine (`js/`)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ readability, and internal risk signals; it is not a bypass guarantee.
[![Tests](https://img.shields.io/badge/tests-2269%20passed-2ea44f.svg?logo=pytest&logoColor=white)](https://github.com/ksanyok/TextHumanize/actions/workflows/ci.yml)
  
[![Zero Dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)]()
[![PyPI](https://img.shields.io/badge/pypi-v0.36.0-3775A9.svg?logo=pypi&logoColor=white)](https://pypi.org/project/texthumanize/)
[![PyPI](https://img.shields.io/badge/pypi-v0.36.1-3775A9.svg?logo=pypi&logoColor=white)](https://pypi.org/project/texthumanize/)
[![License](https://img.shields.io/badge/license-Dual%20(Free%20%2B%20Commercial)-blue.svg)](LICENSE)

<br/>
Expand Down Expand Up @@ -195,7 +195,7 @@ git clone https://github.com/ksanyok/TextHumanize.git
cd TextHumanize && pip install -e .
```

> **Tip:** Pin your version for production: `pip install texthumanize==0.36.0`
> **Tip:** Pin your version for production: `pip install texthumanize==0.36.1`

<details>
<summary><b>PHP / TypeScript</b></summary>
Expand Down Expand Up @@ -1475,7 +1475,7 @@ reporting rules, and detector limitations.

```
┌──────────────────────────────────────────────────────────┐
│ TextHumanize v0.36.0 — AI Score Benchmark │
│ TextHumanize v0.36.1 — AI Score Benchmark │
├──────────────────────────────────────────────────────────┤
│ EN (web/50): 94% → 27% (reduction: -67pp) │
│ EN (web/60): 94% → 23% (reduction: -71pp) │
Expand Down Expand Up @@ -1887,7 +1887,7 @@ Try the [Live Demo](https://texthumanize.link/). For local use, the REST API + S

---

## 🆕 What's New in v0.36.0
## 🆕 What's New in v0.36.1

### JS/TS port — publication-safe engine for 9 languages (0.36.0)
- **`humanizeHtml(html, options)`** — rewrites article HTML while keeping links, anchors, attributes, `<code>`/`<pre>` and inline formatting byte-identical (`data-humanize="off"` opts a block out). `humanize()` routes HTML input there automatically.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ksanyok/text-humanize",
"version": "0.36.0",
"version": "0.36.1",
"description": "Zero-dependency PHP library for algorithmic text humanization — transforms machine-generated text into natural prose",
"type": "library",
"keywords": [
Expand Down
6 changes: 3 additions & 3 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ What is never touched: `<a>…</a>` (anchor text included), `<code>`, `<pre>`,
`<script>`, `<style>`, attributes, entities, and any element with
`data-humanize="off"`, `translate="no"` or class `notranslate`. Inline tags
(`<strong>`, `<em>`, `<br>` …) are kept in place; if a block's markup would not
survive, the block is left as it was (`stats.reverted`). Headings get
`headingFactor` (0.45) of the intensity and list items/table cells `listFactor`
(0.75).
survive, the block is left as it was (`stats.reverted`). Headings are not
touched by default (`headingFactor: 0`, they carry SEO keywords; pass e.g. 0.45
to opt in); list items/table cells get `listFactor` (0.75) of the intensity.

### What the engine does

Expand Down
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "texthumanize",
"version": "0.36.0",
"version": "0.36.1",
"description": "Algorithmic text humanization — transforms AI-generated text into natural-sounding content",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions js/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ function isAllCaps(s: string): boolean {
const BARE_CONJ = new Set([
'and', 'but', 'yet', 'и', 'но', 'а', 'да', 'і', 'але', 'та', 'ale', 'i', 'a', 'y', 'pero',
'e', 'mas', 'und', 'aber', 'et', 'mais', 'ma', 'і ще', 'и ещё', 'and also',
// adverbs that take no comma at sentence start ("Также X", not "Также, X")
'также', 'ещё', 'еще', 'плюс', 'тоже', 'також', 'ще', 'теж', 'także', 'również', 'też',
'también', 'também', 'auch', 'aussi', 'anche',
]);

export interface EngineOptions {
Expand Down
31 changes: 27 additions & 4 deletions js/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function humanizeHtml(html: string, options: HumanizeHtmlOptions = {}): H

const rng = new Rng(options.seed || hashSeed(html));
const keepBase = [...(options.preserve?.brandTerms ?? []), ...(options.constraints?.keepKeywords ?? [])];
const headingFactor = options.headingFactor ?? 0.45;
const headingFactor = options.headingFactor ?? 0;
const listFactor = options.listFactor ?? 0.75;
const maxLinkShare = options.maxLinkShare ?? 0.6;
const noSplitProfile = options.profile === 'formal' || options.profile === 'academic' || options.profile === 'docs';
Expand All @@ -167,7 +167,8 @@ export function humanizeHtml(html: string, options: HumanizeHtmlOptions = {}): H
const linkChars = u.parts.filter(p => p.kind === 'atom' && /^<a\b/i.test(p.raw)).reduce((s, p) => s + p.visible.trim().length, 0);
const visChars = visible.trim().length || 1;
const atoms = u.parts.filter(p => p.kind === 'atom').length;
if (!pack || effective === 0 || words < 4 || linkChars / visChars > maxLinkShare || atoms > PH_MAX) {
const blockFactor = HEADINGS.has(u.tag) ? headingFactor : LISTISH.has(u.tag) ? listFactor : 1;
if (!pack || effective === 0 || blockFactor <= 0 || words < 4 || linkChars / visChars > maxLinkShare || atoms > PH_MAX) {
stats.skipped++;
out.push(original);
afterVisible.push(visible);
Expand All @@ -182,7 +183,7 @@ export function humanizeHtml(html: string, options: HumanizeHtmlOptions = {}): H
else { encoded += String.fromCharCode(PH_BASE + atomList.length); atomList.push(p); }
}

const factor = HEADINGS.has(u.tag) ? headingFactor : LISTISH.has(u.tag) ? listFactor : 1;
const factor = blockFactor;
const keep = [...keepBase];
for (const m of encoded.matchAll(PROTECT_RE)) keep.push(m[0]);

Expand Down Expand Up @@ -216,7 +217,10 @@ export function humanizeHtml(html: string, options: HumanizeHtmlOptions = {}): H

const result = out.join('');
const aiScoreAfter = wantScore ? aiScore(afterVisible.join('\n'), lang) : -1;
return { html: result, lang, changes, stats, aiScoreBefore: wantScore ? aiScoreBefore : -1, aiScoreAfter };
return {
html: result, lang, changes, stats, aiScoreBefore: wantScore ? aiScoreBefore : -1, aiScoreAfter,
warnings: findMixedScript(afterVisible.join('\n')),
};
}

/**
Expand Down Expand Up @@ -255,6 +259,25 @@ function tokenize(html: string): Array<{ tag?: string; text?: string }> {
return segments;
}

/**
* Words that mix Cyrillic and Latin letters ("манning", "кoмпания" with a Latin
* "o"). Usually a generator glitch or a homoglyph; reported, never auto-fixed,
* because the intended spelling is unknown.
*/
export function findMixedScript(text: string): Array<{ type: 'mixed_script'; token: string }> {
const out: Array<{ type: 'mixed_script'; token: string }> = [];
const seen = new Set<string>();
for (const m of text.matchAll(/[\p{L}\p{M}]+/gu)) {
const w = m[0];
if (/\p{Script=Cyrillic}/u.test(w) && /\p{Script=Latin}/u.test(w) && !seen.has(w)) {
seen.add(w);
out.push({ type: 'mixed_script', token: w });
if (out.length >= 20) break;
}
}
return out;
}

function pushText(parts: Part[], text: string): void {
let last = 0;
for (const m of text.matchAll(ENTITY_RE)) {
Expand Down
7 changes: 0 additions & 7 deletions js/src/lang/generated/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,28 +1547,23 @@ export const de: LangData = {
"öffnet Türen"
],
"es ist erwähnenswert, dass": [
"erwähnenswert:",
""
],
"es ist festzustellen": [
"es zeigt sich",
"klar ist"
],
"es ist wichtig zu beachten, dass": [
"beachte:",
"wichtig:",
""
],
"es ist wichtig zu betonen, dass": [
"betont sei:",
""
],
"es lässt sich konstatieren": [
"man sieht",
"es zeigt sich"
],
"es sei darauf hingewiesen, dass": [
"übrigens:",
""
],
"hinsichtlich": [
Expand Down Expand Up @@ -1884,8 +1879,6 @@ export const de: LangData = {
"unterm Strich"
],
"zusammenfassend lässt sich sagen, dass": [
"kurz gesagt:",
"unterm Strich:",
""
],
"zwecks": [
Expand Down
3 changes: 1 addition & 2 deletions js/src/lang/generated/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,7 @@ export const fr: LangData = {
"notons que"
],
"il est à souligner": [
"soulignons",
"important:"
"soulignons"
],
"il importe de": [
"il faut",
Expand Down
5 changes: 0 additions & 5 deletions js/src/lang/generated/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1332,11 +1332,9 @@ export const pl: LangData = {
"warto powiedzieć"
],
"należy podkreślić, że": [
"podkreślę:",
""
],
"należy zauważyć, że": [
"zauważmy:",
""
],
"nie da się pominąć": [
Expand Down Expand Up @@ -1550,12 +1548,9 @@ export const pl: LangData = {
"w związku z tym"
],
"warto podkreślić, że": [
"podkreślę:",
""
],
"warto zauważyć, że": [
"zauważmy:",
"warto dodać:",
""
],
"ważne jest, aby zrozumieć, że": [
Expand Down
6 changes: 0 additions & 6 deletions js/src/lang/generated/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2171,15 +2171,13 @@ export const ru: LangData = {
],
"важно отметить, что": [
"отмечу, что",
"заметим:",
""
],
"важно подчеркнуть, что": [
"важно, что",
"стоит сказать, что"
],
"важно понимать, что": [
"поймите:",
"суть в том, что",
""
],
Expand Down Expand Up @@ -2433,7 +2431,6 @@ export const ru: LangData = {
"стоит отметить"
],
"необходимо учитывать, что": [
"учтите:",
""
],
"несмотря на тот факт, что": [
Expand Down Expand Up @@ -2541,7 +2538,6 @@ export const ru: LangData = {
],
"подводя итог,": [
"короче,",
"итого:",
""
],
"позволяет раскрыть потенциал": [
Expand Down Expand Up @@ -2668,7 +2664,6 @@ export const ru: LangData = {
],
"следует отметить, что": [
"отмечу, что",
"заметим:",
""
],
"ставить задачу": [
Expand All @@ -2695,7 +2690,6 @@ export const ru: LangData = {
""
],
"стоит помнить, что": [
"помните:",
""
],
"стремительно развивающийся": [
Expand Down
4 changes: 0 additions & 4 deletions js/src/lang/generated/uk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,15 +1575,13 @@ export const uk: LangData = {
],
"важливо зазначити, що": [
"зазначу, що",
"звернімо увагу:",
""
],
"важливо підкреслити, що": [
"важливо, що",
"варто сказати, що"
],
"важливо розуміти, що": [
"зрозумійте:",
"суть у тому, що",
""
],
Expand All @@ -1592,7 +1590,6 @@ export const uk: LangData = {
"зауважимо, що"
],
"варто підкреслити, що": [
"підкреслю:",
""
],
"веде діяльність": [
Expand Down Expand Up @@ -1983,7 +1980,6 @@ export const uk: LangData = {
],
"слід зазначити, що": [
"зазначу, що",
"звернімо увагу:",
""
],
"слід мати на увазі": [
Expand Down
7 changes: 6 additions & 1 deletion js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface ChangeEntry {

/** Options for HTML-aware humanization. */
export interface HumanizeHtmlOptions extends HumanizeOptions {
/** Intensity multiplier for headings (h1–h6). Default 0.45. */
/** Intensity multiplier for headings (h1–h6). Default 0: headings carry SEO keywords and are left untouched. */
headingFactor?: number;
/** Intensity multiplier for list items / table cells. Default 0.75. */
listFactor?: number;
Expand All @@ -92,6 +92,11 @@ export interface HumanizeHtmlResult {
stats: { blocks: number; changed: number; reverted: number; skipped: number };
aiScoreBefore: number;
aiScoreAfter: number;
/**
* Problems found in the source that the engine does not fix by itself, e.g.
* words mixing Cyrillic and Latin letters ("манning") left by a generator.
*/
warnings: Array<{ type: 'mixed_script'; token: string }>;
}

/** Publication-safe dictionaries exported from the Python packs. */
Expand Down
2 changes: 1 addition & 1 deletion js/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.36.0';
export const VERSION = '0.36.1';
38 changes: 38 additions & 0 deletions js/tests/multilang.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,41 @@ describe('pathological input (ReDoS guard)', () => {
});
}
});

describe('0.36.1: headings and connector punctuation', () => {
const headings = (h: string) => [...h.matchAll(/<h[1-6][^>]*>[\s\S]*?<\/h[1-6]>/g)].map(m => m[0]);

it.each(LANGS)('leaves headings untouched by default (%s)', lang => {
const html = fixture(lang);
for (let seed = 1; seed <= 10; seed++) {
expect(headings(humanizeHtml(html, { lang, intensity: 100, seed }).html)).toEqual(headings(html));
}
});

it('still rewrites headings when headingFactor is set', () => {
const html = '<h2>Furthermore, it is important to note that SEO matters a lot today</h2>';
const outs = Array.from({ length: 10 }, (_, i) => humanizeHtml(html, { lang: 'en', intensity: 100, seed: i + 1, headingFactor: 1 }).html);
expect(outs.some(o => o !== html)).toBe(true);
});

it.each(LANGS)('no comma after bare adverbs and no colon openers (%s)', lang => {
const html = fixture(lang);
for (let seed = 1; seed <= 15; seed++) {
const text = visible(humanizeHtml(html, { lang, intensity: 100, seed }).html);
expect(text).not.toMatch(/(?:^|[.!?]\s+)(Также|Ещё|Плюс|Також|Ще|Także|Również|También|Também),/u);
expect(text).not.toMatch(/(?:^|[.!?]\s+)(Заметим|Отмечу|Zauważmy|Звернімо увагу|Warto dodać):/u);
}
});
});

describe('0.36.1: mixed-script warnings', () => {
it('reports words mixing Cyrillic and Latin letters', () => {
const html = '<p>Платформа объединяет предложения судовладельцев, менеджеров и манning агентств по всему миру сегодня.</p>';
const r = humanizeHtml(html, { lang: 'ru' });
expect(r.warnings).toEqual([{ type: 'mixed_script', token: 'манning' }]);
});

it.each(LANGS)('has no warnings on clean fixtures (%s)', lang => {
expect(humanizeHtml(fixture(lang), { lang }).warnings).toEqual([]);
});
});
Loading
Loading