@crawlee/utils 4.0.0-beta.176 → 4.0.0-beta.177

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ const BLOCK_TAGS_REGEX = /^(p|h1|h2|h3|h4|h5|h6|ol|ul|li|pre|address|blockquote|
30
30
  * @return Plain text
31
31
  */
32
32
  export async function htmlToText(htmlOrCheerioElement) {
33
- const { load } = await import('cheerio');
33
+ const { load } = await import('cheerio/slim');
34
34
  if (!htmlOrCheerioElement)
35
35
  return '';
36
36
  const $ = typeof htmlOrCheerioElement === 'function' ? htmlOrCheerioElement : load(htmlOrCheerioElement);
@@ -42,8 +42,10 @@ export async function htmlToText(htmlOrCheerioElement) {
42
42
  if (elem.type === 'text') {
43
43
  // Compress spaces, unless we're inside <pre> element
44
44
  let compr;
45
- if (elem.parent?.tagName === 'pre')
46
- compr = elem.data;
45
+ if (elem.parent?.tagName === 'pre') {
46
+ // Strip single newline right after `<pre>` that htmlparser2 keeps
47
+ compr = elem.parent.children?.[0] === elem ? elem.data.replace(/^\r?\n/, '') : elem.data;
48
+ }
47
49
  else
48
50
  compr = elem.data.replace(/\s+/g, ' ');
49
51
  // If text is empty or ends with a whitespace, don't add the leading whitespace
@@ -1,7 +1,7 @@
1
1
  import { isTag } from 'domhandler';
2
2
  export async function extractMicrodata(htmlOrCheerioElement) {
3
3
  // Dynamic so that importing `@crawlee/utils` does not pull in cheerio - see #3836.
4
- const { load } = await import('cheerio');
4
+ const { load } = await import('cheerio/slim');
5
5
  const $ = typeof htmlOrCheerioElement === 'string' ? load(htmlOrCheerioElement) : htmlOrCheerioElement;
6
6
  const context = { $ };
7
7
  return $('[itemscope]')
@@ -366,7 +366,7 @@ const parseOpenGraphProperty = (property, $) => {
366
366
  };
367
367
  };
368
368
  export async function parseOpenGraph(item, additionalProperties) {
369
- const { load } = await import('cheerio');
369
+ const { load } = await import('cheerio/slim');
370
370
  const $ = typeof item === 'string' ? load(item) : item;
371
371
  return [...(additionalProperties || []), ...OPEN_GRAPH_PROPERTIES].reduce((acc, curr) => {
372
372
  return {
@@ -590,7 +590,7 @@ export const DISCORD_REGEX_GLOBAL = new RegExp(DISCORD_REGEX_STRING, 'ig');
590
590
  * @return An object with the social handles.
591
591
  */
592
592
  export async function parseHandlesFromHtml(html, data = null) {
593
- const cheerio = await import('cheerio');
593
+ const cheerio = await import('cheerio/slim');
594
594
  const result = {
595
595
  emails: [],
596
596
  phones: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/utils",
3
- "version": "4.0.0-beta.176",
3
+ "version": "4.0.0-beta.177",
4
4
  "description": "A set of shared utilities that can be used by crawlers",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -44,8 +44,8 @@
44
44
  "dependencies": {
45
45
  "@apify/ps-tree": "^1.2.0",
46
46
  "@apify/validations": "^1.1.0",
47
- "@crawlee/http-client": "4.0.0-beta.176",
48
- "@crawlee/types": "4.0.0-beta.176",
47
+ "@crawlee/http-client": "4.0.0-beta.177",
48
+ "@crawlee/types": "4.0.0-beta.177",
49
49
  "@types/sax": "^1.2.7",
50
50
  "cheerio": "^1.0.0",
51
51
  "domhandler": "^5.0.3",
@@ -64,5 +64,5 @@
64
64
  }
65
65
  }
66
66
  },
67
- "gitHead": "3e9e27d524dff8fe72aaf337e3d24fc2232eb241"
67
+ "gitHead": "bfd191ba71902fc682dd21fb9ab17590037a60d5"
68
68
  }