Skip to content

Commit

Permalink
trim nbsp (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv authored Nov 24, 2023
1 parent 08c95bb commit a4086d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.1 (November 24, 2023)
* Trim NBSP unicode for Portuguese, Italian and Japanese.

## 1.1.0 (November 1, 2023)
* This makes content paragraph parsing for Portuguese slightly less brittle.

Expand Down
9 changes: 9 additions & 0 deletions src/FetchMeditation/ItalianJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public function fetch(): JFTEntry
$quoteParts = explode('--', $result['quote']);
$result['quote'] = $quoteParts[0] ?? '';
$result['source'] = $quoteParts[1] ?? $result['source'];
$result = array_map(function ($item) {
if (is_array($item)) {
return array_map(function ($paragraph) {
return trim($paragraph, "\xC2\xA0");
}, $item);
} else {
return trim($item, "\xC2\xA0");
}
}, $result);

return new JFTEntry(
$result['date'],
Expand Down
4 changes: 3 additions & 1 deletion src/FetchMeditation/JapaneseJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public function fetch(): JFTEntry
$paragraphs[] .= trim($nextNode->textContent);
$nextNode = $nextNode->nextSibling;
}
$result['content'] = array_values(array_filter($paragraphs));
$result['content'] = array_map(function ($paragraph) {
return trim(preg_replace('/\s+/u', ' ', $paragraph));
}, array_values(array_filter($paragraphs)));
}

return new JFTEntry(
Expand Down
4 changes: 3 additions & 1 deletion src/FetchMeditation/PortugueseJFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function fetch(): JFTEntry
}
}
$result['page'] = '';
$result['content'] = array_map('trim', $paragraphs);
$result['content'] = array_map(function ($paragraph) {
return trim(preg_replace('/\s+/u', ' ', $paragraph));
}, $paragraphs);

return new JFTEntry(
$result['date'],
Expand Down

0 comments on commit a4086d5

Please sign in to comment.