extract-webpage 1.2.419 → 1.2.421

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.
Files changed (39) hide show
  1. package/README.md +7 -1
  2. package/dist/extract-webpage.cjs.js +1 -1
  3. package/dist/extract-webpage.cjs.js.map +1 -1
  4. package/dist/extract-webpage.es.js +2 -4
  5. package/dist/extract-webpage.es.js.map +1 -1
  6. package/dist/html-to-content/highlight.d.ts +8 -0
  7. package/dist/index.d.ts +3 -2
  8. package/package.json +6 -6
  9. package/src/html-to-content/highlight.ts +59 -0
  10. package/src/html-to-content/html-to-content.ts +1 -2
  11. package/src/html-to-content/html-utils.ts +11 -20
  12. package/src/index.ts +5 -2
  13. package/src/url-to-content/docx-to-content.ts +9 -5
  14. package/dist/html-to-cite/extract-author.d.ts +0 -11
  15. package/dist/html-to-cite/extract-cite.d.ts +0 -33
  16. package/dist/html-to-cite/extract-date/date-extractors.d.ts +0 -40
  17. package/dist/html-to-cite/extract-date/date-validators.d.ts +0 -15
  18. package/dist/html-to-cite/extract-date/extract-date-quick.d.ts +0 -8
  19. package/dist/html-to-cite/extract-date/extract-date.d.ts +0 -26
  20. package/dist/html-to-cite/extract-source.d.ts +0 -11
  21. package/dist/html-to-cite/extract-title.d.ts +0 -11
  22. package/dist/html-to-cite/human-names-recognize.d.ts +0 -16
  23. package/dist/html-to-cite/metadata-to-cite.d.ts +0 -16
  24. package/dist/html-to-cite/url-to-domain.d.ts +0 -20
  25. package/dist/html-to-content/prism-global.d.ts +0 -12
  26. package/src/html-to-cite/extract-author.ts +0 -125
  27. package/src/html-to-cite/extract-cite.ts +0 -97
  28. package/src/html-to-cite/extract-date/date-extractors.ts +0 -484
  29. package/src/html-to-cite/extract-date/date-validators.ts +0 -191
  30. package/src/html-to-cite/extract-date/extract-date-quick.ts +0 -184
  31. package/src/html-to-cite/extract-date/extract-date.ts +0 -1049
  32. package/src/html-to-cite/extract-source.ts +0 -35
  33. package/src/html-to-cite/extract-title.ts +0 -78
  34. package/src/html-to-cite/human-names-92k.json +0 -1
  35. package/src/html-to-cite/human-names-recognize.ts +0 -396
  36. package/src/html-to-cite/metadata-to-cite.ts +0 -77
  37. package/src/html-to-cite/url-to-domain.ts +0 -50
  38. package/src/html-to-content/prism-global.d.ts +0 -40
  39. package/src/html-to-content/prism-global.ts +0 -82
@@ -0,0 +1,8 @@
1
+ import { default as hljs } from 'highlight.js/lib/core';
2
+ /**
3
+ * Highlights `code` as `lang`, returning HTML made of `hljs-*` spans, or
4
+ * `null` when `lang` is not a registered language or alias — callers render
5
+ * that block escaped and unhighlighted.
6
+ */
7
+ export declare function highlightCode(code: string, lang: string): string | null;
8
+ export { hljs };
package/dist/index.d.ts CHANGED
@@ -13,12 +13,13 @@ export * from './tokenize/text-to-sentences';
13
13
  export * from './tokenize/text-to-chunks';
14
14
  export * from './url-to-content/url-to-content';
15
15
  export * from './url-to-content/url-to-html';
16
- export * from './html-to-cite/url-to-domain';
16
+ export { convertURLToDomain, isURLValid } from 'extract-cite';
17
17
  export * from './url-to-content/youtube-helpers';
18
18
  export * from './url-to-content/docx-to-content';
19
19
  export * from './html-to-content/html-to-content';
20
20
  export * from './html-to-content/extract-content/extract-content-readability';
21
21
  export * from './html-to-content/extract-content/extract-content-mercury';
22
22
  export * from './html-to-content/html-to-basic-html';
23
- export * from './html-to-cite/extract-cite';
23
+ export { extractCite } from 'extract-cite';
24
+ export type { ExtractCiteResult, ExtractCiteOptions } from 'extract-cite';
24
25
  export * from './html-to-content/html-utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-webpage",
3
- "version": "1.2.419",
3
+ "version": "1.2.421",
4
4
  "module": "./dist/extract-webpage.es.js",
5
5
  "description": "Search, extract, cite, and outline the web for a topic with AI Research Agent.",
6
6
  "author": "vtempest <grokthiscontact@gmail.com>",
@@ -74,11 +74,12 @@
74
74
  "dependencies": {
75
75
  "@huggingface/transformers": "^4.2.0",
76
76
  "ai": "^7.0.94",
77
- "chat-agent-toolkit": "^1.2.425",
78
- "chrono-node": "^2.10.1",
77
+ "chat-agent-toolkit": "^1.2.427",
79
78
  "drizzle-orm": "^0.45.2",
80
- "extract-pdf": "^0.1.408",
81
- "extract-youtube": "^1.0.413",
79
+ "extract-cite": "^1.0.108",
80
+ "extract-pdf": "^0.1.548",
81
+ "extract-youtube": "^1.0.414",
82
+ "highlight.js": "^11.12.0",
82
83
  "html-entities": "^2.6.0",
83
84
  "js-yaml": "^5.4.1",
84
85
  "jsdom": "^30.0.1",
@@ -87,7 +88,6 @@
87
88
  "marked": "^18.0.12",
88
89
  "marked-highlight": "^2.2.4",
89
90
  "node-fetch": "^3.3.2",
90
- "prismjs": "^1.30.0",
91
91
  "qwksearch-api-client": "^0.9.225",
92
92
  "zod": "^4.5.4"
93
93
  },
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module html-to-content/highlight
3
+ * @description Syntax highlighting for fenced code blocks, on highlight.js'
4
+ * core build with an explicit set of languages.
5
+ *
6
+ * Every language below is an ordinary ES module import, registered
7
+ * synchronously when this module loads, so there is no global to publish and
8
+ * no load order to protect. Only the core and the listed grammars are bundled,
9
+ * not highlight.js' full set of ~190 languages, which keeps the Worker bundles
10
+ * that pull this package in small.
11
+ */
12
+ import hljs from "highlight.js/lib/core";
13
+ import bash from "highlight.js/lib/languages/bash";
14
+ import c from "highlight.js/lib/languages/c";
15
+ import cpp from "highlight.js/lib/languages/cpp";
16
+ import css from "highlight.js/lib/languages/css";
17
+ import go from "highlight.js/lib/languages/go";
18
+ import java from "highlight.js/lib/languages/java";
19
+ import javascript from "highlight.js/lib/languages/javascript";
20
+ import json from "highlight.js/lib/languages/json";
21
+ import markdown from "highlight.js/lib/languages/markdown";
22
+ import python from "highlight.js/lib/languages/python";
23
+ import rust from "highlight.js/lib/languages/rust";
24
+ import sql from "highlight.js/lib/languages/sql";
25
+ import typescript from "highlight.js/lib/languages/typescript";
26
+ import xml from "highlight.js/lib/languages/xml";
27
+ import yaml from "highlight.js/lib/languages/yaml";
28
+
29
+ hljs.registerLanguage("bash", bash);
30
+ hljs.registerLanguage("c", c);
31
+ hljs.registerLanguage("cpp", cpp);
32
+ hljs.registerLanguage("css", css);
33
+ hljs.registerLanguage("go", go);
34
+ hljs.registerLanguage("java", java);
35
+ hljs.registerLanguage("javascript", javascript);
36
+ hljs.registerLanguage("json", json);
37
+ hljs.registerLanguage("markdown", markdown);
38
+ hljs.registerLanguage("python", python);
39
+ hljs.registerLanguage("rust", rust);
40
+ hljs.registerLanguage("sql", sql);
41
+ hljs.registerLanguage("typescript", typescript);
42
+ hljs.registerLanguage("xml", xml);
43
+ hljs.registerLanguage("yaml", yaml);
44
+ // highlight.js' JavaScript and TypeScript grammars already understand JSX.
45
+ hljs.registerAliases(["jsx"], { languageName: "javascript" });
46
+ hljs.registerAliases(["tsx"], { languageName: "typescript" });
47
+ hljs.registerAliases(["markup"], { languageName: "xml" });
48
+
49
+ /**
50
+ * Highlights `code` as `lang`, returning HTML made of `hljs-*` spans, or
51
+ * `null` when `lang` is not a registered language or alias — callers render
52
+ * that block escaped and unhighlighted.
53
+ */
54
+ export function highlightCode(code: string, lang: string): string | null {
55
+ if (!lang || !hljs.getLanguage(lang)) return null;
56
+ return hljs.highlight(code, { language: lang, ignoreIllegals: true }).value;
57
+ }
58
+
59
+ export { hljs };
@@ -4,14 +4,13 @@
4
4
  * Cleans boilerplate (nav, footer, ads) to produce clean Markdown or text.
5
5
  */
6
6
  import { parseHTML } from "linkedom";
7
- import { extractCite } from "../html-to-cite/extract-cite";
7
+ import { extractCite, extractHumanName } from "extract-cite";
8
8
  import { convertHTMLToBasicHTML } from "./html-to-basic-html";
9
9
  import {
10
10
  convertMarkdownToFormattedHTML,
11
11
  detectMarkdown,
12
12
  removeMarkdownNavigation,
13
13
  } from "./html-utils";
14
- import { extractHumanName } from "../html-to-cite/human-names-recognize";
15
14
  import { extractMainContentFromHTML } from "./extract-content/extract-content-readability";
16
15
  import { extractMainContentFromHTML2 } from "./extract-content/extract-content-mercury";
17
16
 
@@ -139,32 +139,23 @@ export function convertURLToAbsoluteURL(base, relative) {
139
139
  }
140
140
 
141
141
  import { marked } from "marked";
142
- // `prism-global` owns both the Prism instance and the grammars beyond the ones
143
- // prismjs' entry point bundles; importing `prismjs/components/*` here directly
144
- // would reintroduce the load-order crash its docs describe.
145
- import Prism, { loadPrismGrammars } from "./prism-global";
142
+ import { highlightCode } from "./highlight";
146
143
 
147
- // Start the grammars loading now, and again from the renderer below — the
148
- // second call is what guarantees they are requested at all, since a bundler is
149
- // free to drop this one as a side effect of a module it thinks is pure.
150
- void loadPrismGrammars();
151
-
152
- // Configure marked once at module load with Prism.js syntax highlighting.
144
+ // Configure marked once at module load with highlight.js syntax highlighting.
153
145
  // marked v17 removed the `highlight` option from setOptions, so highlighting
154
146
  // is wired via a custom `code` renderer instead.
155
147
  marked.use({
156
148
  renderer: {
157
149
  code({ text, lang }) {
158
- void loadPrismGrammars();
159
- const language = lang && Prism.languages[lang] ? lang : null;
160
- const highlighted = language
161
- ? Prism.highlight(text, Prism.languages[language], language)
162
- : text
163
- .replace(/&/g, "&amp;")
164
- .replace(/</g, "&lt;")
165
- .replace(/>/g, "&gt;");
166
- const cls = language ? ` class="language-${language}"` : "";
167
- return `<pre><code${cls}>${highlighted}</code></pre>\n`;
150
+ const highlighted = lang ? highlightCode(text, lang) : null;
151
+ const body =
152
+ highlighted ??
153
+ text
154
+ .replace(/&/g, "&amp;")
155
+ .replace(/</g, "&lt;")
156
+ .replace(/>/g, "&gt;");
157
+ const cls = highlighted !== null ? ` class="language-${lang}"` : "";
158
+ return `<pre><code${cls}>${body}</code></pre>\n`;
168
159
  },
169
160
  },
170
161
  });
package/src/index.ts CHANGED
@@ -13,7 +13,9 @@ export * from "./tokenize/text-to-sentences";
13
13
  export * from "./tokenize/text-to-chunks";
14
14
  export * from "./url-to-content/url-to-content";
15
15
  export * from "./url-to-content/url-to-html";
16
- export * from "./html-to-cite/url-to-domain";
16
+ // Citation extraction moved to the extract-cite package; re-exported so
17
+ // existing `import { extractCite } from "extract-webpage"` callers keep working.
18
+ export { convertURLToDomain, isURLValid } from "extract-cite";
17
19
  export * from "./url-to-content/youtube-helpers";
18
20
  // PDF export removed from main index to prevent pdfjs-serverless from being evaluated at build time
19
21
  // Import directly from "./pdf-to-html/pdfToHtml" when needed
@@ -22,5 +24,6 @@ export * from "./html-to-content/html-to-content";
22
24
  export * from "./html-to-content/extract-content/extract-content-readability";
23
25
  export * from "./html-to-content/extract-content/extract-content-mercury";
24
26
  export * from "./html-to-content/html-to-basic-html";
25
- export * from "./html-to-cite/extract-cite";
27
+ export { extractCite } from "extract-cite";
28
+ export type { ExtractCiteResult, ExtractCiteOptions } from "extract-cite";
26
29
  export * from "./html-to-content/html-utils";
@@ -155,8 +155,8 @@ export async function convertDOCXToHTML(input, options = {}) {
155
155
  const defaults = defaultMatch[0];
156
156
  // Parse font, size, etc.
157
157
  styles.document = {
158
- fontFamily: /<w:rFonts[^>]*w:ascii="([^"]+)"/.exec(defaults)?.[1],
159
- fontSize: /<w:sz[^>]*w:val="([^"]+)"/.exec(defaults)?.[1],
158
+ font: /<w:rFonts[^>]*w:ascii="([^"]+)"/.exec(defaults)?.[1],
159
+ size: /<w:sz[^>]*w:val="([^"]+)"/.exec(defaults)?.[1],
160
160
  color: /<w:color[^>]*w:val="([^"]+)"/.exec(defaults)?.[1],
161
161
  };
162
162
  }
@@ -429,10 +429,14 @@ function generateHtml(content, styles) {
429
429
  function styleToCSS(style) {
430
430
  if (!style) return "";
431
431
 
432
+ // OOXML stores colours as bare hex ("FF0000"); CSS needs the "#".
433
+ const cssColor = (value) =>
434
+ /^[0-9a-f]{6}$/i.test(String(value)) ? `#${value}` : value;
432
435
  const cssMap = {
433
- alignment: "text-align",
434
- color: "color",
435
- highlight: "background-color",
436
+ alignment: (value) =>
437
+ `text-align: ${value === "both" || value === "distribute" ? "justify" : value}`,
438
+ color: (value) => `color: ${cssColor(value)}`,
439
+ highlight: (value) => `background-color: ${cssColor(value)}`,
436
440
  size: (value) => `font-size: ${parseInt(value) / 2}pt`,
437
441
  spacing: (value) => `line-height: ${parseInt(value) / 240}`,
438
442
  indentation: (value) => `margin-left: ${parseInt(value) / 20}pt`,
@@ -1,11 +0,0 @@
1
- /**
2
- * Extracts the author from the document and validates it as a human name
3
- *
4
- * @param {Document} document
5
- * @returns {object|null} author_cite, author_short, author_type - or null if no valid author found
6
- */
7
- export declare function extractAuthor(document: any): {
8
- author_cite: any;
9
- author_short: any;
10
- author_type: number;
11
- };
@@ -1,33 +0,0 @@
1
- export interface ExtractCiteResult {
2
- author?: string;
3
- author_cite?: string;
4
- date?: string;
5
- title?: string;
6
- source?: string;
7
- }
8
- export interface ExtractCiteOptions {
9
- url?: string;
10
- }
11
- /**
12
- * ### \u1f4da\u1f48e Extract Expert Excerpt
13
- * <img width="350px" src="https://i.imgur.com/4GOOM9s.jpeg" />
14
- *
15
- * Extract author, date, source, and title from HTML using meta tags
16
- * and common class names. Validates human name from author string to check
17
- * against common list of 90k first names, last names,and organizations to infer
18
- * if it should be reversed starting by author last name (accounting for affixes/titles),
19
- * since organizations are not reversed.
20
- * [Article Extraction Benchmark](https://github.com/scrapinghub/article-extraction-benchmark?tab=readme-ov-file#results)
21
- * @param {Document | string} document dom object or html string with article content
22
- * @param {ExtractCiteOptions} [options={}]
23
- * @returns {ExtractCiteResult | null} An object containing extracted citation information.
24
- * @category Extract
25
- * @author [vtempest (2025)](https://github.com/vtempest)
26
- */
27
- export declare function extractCite(document: Document | string, options?: ExtractCiteOptions): {
28
- author: string;
29
- author_cite: any;
30
- date: string;
31
- title: string;
32
- source: string;
33
- };
@@ -1,40 +0,0 @@
1
- declare const FAST_PREPEND = "";
2
- declare const MIN_SEGMENT_LEN = 6;
3
- declare const MAX_SEGMENT_LEN = 52;
4
- declare const DATE_EXPRESSIONS: string;
5
- declare const SLOW_PREPEND = "";
6
- declare const FREE_TEXT_EXPRESSIONS = ".//*[self::div or self::h2 or self::h3 or self::h4 or self::li or self::p or self::span or self::time or self::ul]/text()";
7
- declare const THREE_COMP_REGEX_A: RegExp;
8
- declare const THREE_COMP_REGEX_B: RegExp;
9
- declare const TWO_COMP_REGEX: RegExp;
10
- declare const YEAR_PATTERN: RegExp;
11
- declare const COPYRIGHT_PATTERN: RegExp;
12
- declare const THREE_PATTERN: RegExp;
13
- declare const THREE_CATCH: RegExp;
14
- declare const THREE_LOOSE_PATTERN: RegExp;
15
- declare const THREE_LOOSE_CATCH: RegExp;
16
- declare const SELECT_YMD_PATTERN: RegExp;
17
- declare const SELECT_YMD_YEAR: RegExp;
18
- declare const YMD_YEAR: RegExp;
19
- declare const DATESTRINGS_PATTERN: RegExp;
20
- declare const DATESTRINGS_CATCH: RegExp;
21
- declare const SLASHES_PATTERN: RegExp;
22
- declare const SLASHES_YEAR: RegExp;
23
- declare const YYYYMM_PATTERN: RegExp;
24
- declare const YYYYMM_CATCH: RegExp;
25
- declare const MMYYYY_PATTERN: RegExp;
26
- declare const MMYYYY_YEAR: RegExp;
27
- declare const SIMPLE_PATTERN: RegExp;
28
- declare const YMD_PATTERN: RegExp;
29
- declare const TIMESTAMP_PATTERN: RegExp;
30
- declare function discard_unwanted(tree: any): any[];
31
- declare function extract_url_date(testurl: any, options: any): string;
32
- declare function regex_parse(string: any): Date;
33
- declare function custom_parse(string: any, outputformat: any, min_date: any, max_date: any): any;
34
- declare function external_date_parser(string: any, outputformat: any): string;
35
- declare function try_date_expr(string: any, outputformat: any, extensive_search: any, min_date: any, max_date: any): any;
36
- declare function img_search(tree: any, options: any): string;
37
- declare function pattern_search(text: any, date_pattern: any, options: any): any;
38
- declare function json_search(tree: any, options: any): any;
39
- declare function idiosyncrasies_search(htmlstring: any, options: any): any;
40
- export { discard_unwanted, extract_url_date, regex_parse, custom_parse, external_date_parser, try_date_expr, img_search, pattern_search, json_search, idiosyncrasies_search, DATE_EXPRESSIONS, FAST_PREPEND, SLOW_PREPEND, FREE_TEXT_EXPRESSIONS, MAX_SEGMENT_LEN, MIN_SEGMENT_LEN, YEAR_PATTERN, YMD_PATTERN, COPYRIGHT_PATTERN, TIMESTAMP_PATTERN, THREE_PATTERN, THREE_CATCH, THREE_LOOSE_PATTERN, THREE_LOOSE_CATCH, SELECT_YMD_PATTERN, SELECT_YMD_YEAR, YMD_YEAR, DATESTRINGS_PATTERN, DATESTRINGS_CATCH, SLASHES_PATTERN, SLASHES_YEAR, YYYYMM_PATTERN, YYYYMM_CATCH, MMYYYY_PATTERN, MMYYYY_YEAR, SIMPLE_PATTERN, THREE_COMP_REGEX_A, THREE_COMP_REGEX_B, TWO_COMP_REGEX, };
@@ -1,15 +0,0 @@
1
- /**
2
- * @fileoverview Validation and filtering logic for extracted date candidates.
3
- * Ensures dates fall within plausible ranges and meet format requirements.
4
- */
5
- declare function is_valid_date(date_input: any, outputformat: any, earliest: any, latest: any): boolean;
6
- declare function is_valid_format(outputformat: any): boolean;
7
- declare function plausible_year_filter(htmlstring: any, pattern: any, yearpat: any, earliest: any, latest: any, incomplete?: boolean): Map<any, any>;
8
- declare function compare_values(reference: any, attempt: any, options: any): any;
9
- declare function filter_ymd_candidate(bestmatch: any, pattern: any, original_date: any, copyear: any, outputformat: any, min_date: any, max_date: any): any;
10
- declare function convert_date(datestring: any, inputformat: any, outputformat: any): any;
11
- declare function check_extracted_reference(reference: any, options: any): string;
12
- declare function check_date_input(date_object: any, default_date: any): any;
13
- declare function get_min_date(min_date: any): any;
14
- declare function get_max_date(max_date: any): any;
15
- export { is_valid_date, is_valid_format, plausible_year_filter, compare_values, filter_ymd_candidate, convert_date, check_extracted_reference, check_date_input, get_min_date, get_max_date };
@@ -1,8 +0,0 @@
1
- /**
2
- * Extract date from document using various methods
3
- *
4
- * @param {Document} document - DOM object with article content
5
- * @param {string} url - URL of the page
6
- * @returns {string|null} Extracted date or null if not found
7
- */
8
- export declare function extractDateQuick(document: any, url: any): any;
@@ -1,26 +0,0 @@
1
- declare const DATE_ATTRIBUTES: Set<string>;
2
- declare const NAME_MODIFIED: Set<string>;
3
- declare const PROPERTY_MODIFIED: Set<string>;
4
- declare const ITEMPROP_ATTRS_ORIGINAL: Set<string>;
5
- declare const ITEMPROP_ATTRS_MODIFIED: Set<string>;
6
- declare const ITEMPROP_ATTRS: Set<string>;
7
- declare const CLASS_ATTRS: Set<string>;
8
- declare const NON_DIGITS_REGEX: RegExp;
9
- export { DATE_ATTRIBUTES, NAME_MODIFIED, PROPERTY_MODIFIED, ITEMPROP_ATTRS_ORIGINAL, ITEMPROP_ATTRS_MODIFIED, ITEMPROP_ATTRS, CLASS_ATTRS, NON_DIGITS_REGEX, };
10
- /**
11
- * Extract date from document using various methods
12
- *
13
- * @param {Document} htmlobject - DOM object with article content
14
- * @param {boolean} [extensive_search=true] - perform extensive search if true
15
- * @param {boolean} [original_date=false] - return original date if true
16
- * @param {string} [outputformat="%Y-%m-%d"] - output format
17
- * @param {string} [url=null] - URL of the page
18
- * @param {boolean} [verbose=false] - log debug messages if true
19
- * @param {Date} [min_date=null] - minimum date to consider
20
- * @param {Date} [max_date=null] - maximum date to consider
21
- * @param {boolean} [deferred_url_extractor=false] - if true, do not extract date from URL
22
- * @returns {string|null} Extracted date or null if not found
23
- * @author [vtempest (2025)](https://github.com/vtempest)
24
- * Based on [Barbaresi (2020)](https://github.com/adbar/htmldate/)
25
- */
26
- export declare function extractDate(htmlobject: any, extensive_search?: boolean, original_date?: boolean, outputformat?: string, url?: any, verbose?: boolean, min_date?: any, max_date?: any, deferred_url_extractor?: boolean): any;
@@ -1,11 +0,0 @@
1
- /**
2
- * @fileoverview Utility for extracting the publication/source name from a
3
- * document's `og:site_name` meta tag or class-based markers.
4
- */
5
- /**
6
- * Extract source from document using common class names
7
- *
8
- * @param {document} document document or dom object with article content
9
- * @returns {object} source
10
- */
11
- export declare function extractSource(document: any): any;
@@ -1,11 +0,0 @@
1
- /**
2
- * @fileoverview Utility for identifying, extracting, and normalizing document titles from HTML.
3
- * Handles metadata, selectors, and breadcrumb cleaning.
4
- */
5
- /**
6
- * Extract and clean title from document
7
- *
8
- * @param {Document} document - DOM object with article content
9
- * @returns {string} Extracted and cleaned title
10
- */
11
- export declare function extractTitle(document: any): string;
@@ -1,16 +0,0 @@
1
- export interface ExtractHumanNameOptions {
2
- formatCiteShortenAuthor?: boolean;
3
- maxAuthorsBeforeEtAl?: number;
4
- }
5
- /**
6
- * Validates and formats author names properly handling multiple authors and multi-word names
7
- *
8
- * @param {string} author - The author name string(s) to be processed
9
- * @param {ExtractHumanNameOptions} [options={}] - Configuration options
10
- * @returns {object} Formatted author information for citation
11
- */
12
- export declare function extractHumanName(author: string, options?: ExtractHumanNameOptions): {
13
- author_cite: any;
14
- author_short: any;
15
- author_type: number;
16
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * @fileoverview Extracts citation metadata (author, date, title, source) from
3
- * a document's `<meta>` tags using a list of commonly used property/name attributes.
4
- */
5
- export interface CiteMetadata {
6
- author?: string;
7
- date?: string;
8
- title?: string;
9
- source?: string;
10
- }
11
- /**
12
- * Extract cite info from common property names in webpage's metadata
13
- * @param {Document} doc dom object of document
14
- * @returns {CiteMetadata} author, date, title, source
15
- */
16
- export declare function extractCiteFromMetadata(doc: Document): CiteMetadata;
@@ -1,20 +0,0 @@
1
- /**
2
- * @fileoverview Utility for extracting and normalizing domain names from URLs.
3
- * Handles subdomains and TLD cleaning for source attribution.
4
- */
5
- /**
6
- * Extract TLD and hostname from domain in Regex. There's [two or more part
7
- * TLDs](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains)
8
- * so it is hard to tell if host.secondTLD.tld or host.tld is correct way
9
- * to get root domain (e.g. abc.go.jp, abc.co.uk)
10
- * @param {string} domain
11
- * @returns {string} rootDomain
12
- */
13
- export declare function convertURLToDomain(domain: any): any;
14
- /**
15
- * Checks if a string is a valid URL.
16
- * @param {string} string
17
- * @returns {boolean} true if the string is a valid URL
18
- * @private
19
- */
20
- export declare function isURLValid(string: any): boolean;
@@ -1,12 +0,0 @@
1
- import { default as Prism } from 'prismjs';
2
- /**
3
- * Registers the grammars above, once per runtime. Cheap to call repeatedly —
4
- * callers are meant to invoke it wherever they are about to highlight, so that
5
- * the work does not hinge on a module-level statement surviving tree-shaking.
6
- *
7
- * Never rejects: a grammar that fails to load just leaves its language out of
8
- * `Prism.languages`, which every caller already treats as "render this block
9
- * unhighlighted".
10
- */
11
- export declare function loadPrismGrammars(): Promise<void>;
12
- export default Prism;
@@ -1,125 +0,0 @@
1
- /**
2
- * @fileoverview Utility for identifying and extracting author names from HTML metadata and content.
3
- * Handles individual authors, multiple authors, and organizational authors.
4
- */
5
- import { extractHumanName } from "./human-names-recognize";
6
-
7
- // https://www.scribbr.com/citation/generator/folders/2rx21jyIjZIKRrcwLk2oXE/lists/4OeJQ4euxzyTk9BiPTRjwn/
8
- const AUTHOR_META_TAGS = [
9
- "byl",
10
- "clmst",
11
- "dc.author",
12
- "dcsext.author",
13
- "dc.creator",
14
- "rbauthors",
15
- "authors",
16
- "sailthru.author",
17
- "article:author",
18
- "parsely-author",
19
- ];
20
-
21
- const AUTHOR_SELECTORS = [
22
- ".entry .entry-author",
23
- ".author.vcard .fn",
24
- ".author .vcard .fn",
25
- ".byline.vcard .fn",
26
- ".byline .vcard .fn",
27
- ".byline .by .author",
28
- ".byline .by",
29
- ".byline .author",
30
- ".post-author.vcard",
31
- ".post-author .vcard",
32
- "a[rel=author]",
33
- "#by_author",
34
- ".by_author",
35
- "#entryAuthor",
36
- ".entryAuthor",
37
- ".byline a[href*=author]",
38
- "#author .authorname",
39
- ".author .authorname",
40
- "#author",
41
- ".author",
42
- ".articleauthor",
43
- ".ArticleAuthor",
44
- ".byline",
45
- ];
46
-
47
- const AUTHOR_MAX_LENGTH = 300;
48
- const BYLINE_REGEX = /^[\n\s]*By\s*:?\s*/i;
49
- const CLEAN_AUTHOR_RE = /^\s*(posted |written )?by\s*:?\s*(.*)/i;
50
-
51
- /**
52
- * Extracts the author from the document and validates it as a human name
53
- *
54
- * @param {Document} document
55
- * @returns {object|null} author_cite, author_short, author_type - or null if no valid author found
56
- */
57
- export function extractAuthor(document) {
58
-
59
-
60
- // 1. Check meta tags
61
- for (const tag of AUTHOR_META_TAGS) {
62
- const metaElement = document.querySelector(
63
- `meta[name="${tag}"], meta[property="${tag}"]`
64
- );
65
- if (metaElement) {
66
- const author = extractAndValidateHumanName(
67
- metaElement.getAttribute("content")
68
- );
69
- if (author) return author;
70
- }
71
- }
72
-
73
- // 2. Check selectors
74
- for (const selector of AUTHOR_SELECTORS) {
75
- const element = document.querySelector(selector);
76
- if (element) {
77
- const author = extractAndValidateHumanName(element.textContent);
78
- if (author) return author;
79
- }
80
- }
81
-
82
- // 4. Broader search in divs and spans
83
- const elements = [
84
- ...document.getElementsByTagName("div"),
85
- ...document.getElementsByTagName("span"),
86
- ];
87
- for (const element of elements) {
88
- if (
89
- element.id.match(/author|byline/i) ||
90
- element?.className?.match(/author|byline/i)
91
- ) {
92
- const author = extractAndValidateHumanName(element.innerText);
93
- if (author) return author;
94
- }
95
- }
96
-
97
-
98
- return null;
99
- }
100
-
101
- // Helper function to clean and validate author string
102
- const validateAuthor = (author) => {
103
- if (!author) return null;
104
-
105
- if (author.startsWith("@")) author = author.slice(1);
106
- if (author.startsWith("http")) return null;
107
-
108
- author = author?.replace(CLEAN_AUTHOR_RE, "$2").trim();
109
- return author.length > 0 && author.length < AUTHOR_MAX_LENGTH
110
- ? author
111
- : null;
112
- };
113
-
114
- // Function to extract and validate human name
115
- const extractAndValidateHumanName = (author) => {
116
- const validatedAuthor = validateAuthor(author);
117
- if (validatedAuthor) {
118
- return extractHumanName(validatedAuthor, {
119
- formatCiteShortenAuthor: false
120
- });
121
- }
122
- return null;
123
- };
124
-
125
-