Versions

  • v132

    5/26/2024
    Open: Version
    Changes from v131 to v132
    +1
    -1
    ⦚ 106 unchanged lines ⦚
    }

    export async function youtube2markdown(url: URL): string | undefined {
    const youtubeVideoID = getYoutubeVideoID(url);
    if (!youtubeVideoID)
    ⦚ 118 unchanged lines ⦚
    ⦚ 106 unchanged lines ⦚
    }

    export async function youtube2markdown(url: URL): Promise<string | undefined> {
    const youtubeVideoID = getYoutubeVideoID(url);
    if (!youtubeVideoID)
    ⦚ 118 unchanged lines ⦚
  • v131

    5/26/2024
    Open: Version
    Changes from v130 to v131
    +6
    -6
    ⦚ 41 unchanged lines ⦚
    }

    function getYoutubeVideoID(url: URL): string | null {
    const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
    const match = url.href.match(regExp);
    return match ? match[1] : null;
    }

    function response(message: string, contentType = "text/markdown"): Response {
    const headers = new Headers();
    headers.set("Access-Control-Allow-Origin", "*");
    ⦚ 52 unchanged lines ⦚
    ret.url = fudgeURL(pathname);
    return ret;
    }

    ⦚ 121 unchanged lines ⦚
    ⦚ 41 unchanged lines ⦚
    }

    function response(message: string, contentType = "text/markdown"): Response {
    const headers = new Headers();
    headers.set("Access-Control-Allow-Origin", "*");
    ⦚ 52 unchanged lines ⦚
    ret.url = fudgeURL(pathname);
    return ret;
    }

    function getYoutubeVideoID(url: URL): string | null {
    const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
    const match = url.href.match(regExp);
    return match ? match[1] : null;
    }

    ⦚ 121 unchanged lines ⦚
  • v130

    5/26/2024
    Open: Version
    Changes from v129 to v130
    +2
    -2
    ⦚ 106 unchanged lines ⦚
    }

    export function youtube2markdown(url: URL): string | undefined {
    const youtubeVideoID = getYoutubeVideoID(url);
    if (!youtubeVideoID)
    ⦚ 53 unchanged lines ⦚
    let markdown = "";

    const youtube_markdown = youtube2markdown(url);
    if (youtube_markdown) {
    markdown = youtube_markdown;
    ⦚ 60 unchanged lines ⦚
    ⦚ 106 unchanged lines ⦚
    }

    export async function youtube2markdown(url: URL): string | undefined {
    const youtubeVideoID = getYoutubeVideoID(url);
    if (!youtubeVideoID)
    ⦚ 53 unchanged lines ⦚
    let markdown = "";

    const youtube_markdown = await youtube2markdown(url);
    if (youtube_markdown) {
    markdown = youtube_markdown;
    ⦚ 60 unchanged lines ⦚
  • v129

    5/26/2024
    Open: Version
    Changes from v128 to v129
    +2
    -3
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    ({ title, markdown }) = r;
    // = r.title;
    // markdown = r.markdown;
    }

    ⦚ 54 unchanged lines ⦚
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    title = r.title;
    markdown = r.markdown;
    }

    ⦚ 54 unchanged lines ⦚
  • v128

    5/26/2024
    Open: Version
    Changes from v127 to v128
    +1
    -1
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    (title, markdown) = r;
    // = r.title;
    // markdown = r.markdown;
    ⦚ 56 unchanged lines ⦚
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    ({ title, markdown }) = r;
    // = r.title;
    // markdown = r.markdown;
    ⦚ 56 unchanged lines ⦚
  • v127

    5/26/2024
    Open: Version
    Changes from v126 to v127
    +2
    -2
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    {title, markdown} = r
    // = r.title;
    // markdown = r.markdown;
    }
    ⦚ 55 unchanged lines ⦚
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    (title, markdown) = r;
    // = r.title;
    // markdown = r.markdown;
    }
    ⦚ 55 unchanged lines ⦚
  • v126

    5/26/2024
    Open: Version
    Changes from v125 to v126
    +3
    -2
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    title = r.title;
    markdown = r.markdown;
    }

    ⦚ 54 unchanged lines ⦚
    ⦚ 169 unchanged lines ⦚
    } else {
    const r = await readability2markdown(html);
    {title, markdown} = r
    // = r.title;
    // markdown = r.markdown;
    }

    ⦚ 54 unchanged lines ⦚
  • v125

    5/26/2024
    Open: Version
    Changes from v124 to v125
    +1
    -0
    ⦚ 166 unchanged lines ⦚
    const youtube_markdown = youtube2markdown(url);
    if (youtube_markdown) {
    } else {
    const r = await readability2markdown(html);
    title = r.title;
    ⦚ 57 unchanged lines ⦚
    ⦚ 166 unchanged lines ⦚
    const youtube_markdown = youtube2markdown(url);
    if (youtube_markdown) {
    markdown = youtube_markdown;
    } else {
    const r = await readability2markdown(html);
    title = r.title;
    ⦚ 57 unchanged lines ⦚
  • v124

    5/26/2024
    Open: Version
    +228
    -0

    import { isProbablyReaderable, Readability } from "npm:@mozilla/readability@^0.5.0";
    import { DOMParser } from "npm:linkedom@0.16.10";
    import { marked } from "npm:marked@12.0.1";
    import { getSubtitles } from "npm:youtube-captions-scraper@^2.0.1";
    import { YouTube } from "npm:youtube-sr@4.3.11";

    const isCloudflareWorker = typeof Request !== "undefined" && typeof Response !== "undefined";

    // init async loading of modules
    const AgentMarkdownImport = isCloudflareWorker ? import("npm:agentmarkdown@6.0.0") : null;
    const TurndownService = isCloudflareWorker ? null : await import("npm:turndown@^7.1.3");

    /**
    * converts HTML to markdown
    * @returns markdown in string
    */
    export async function html2markdown(html: string): Promise<string> {
    if (AgentMarkdownImport) {
    // TurndownService doesn't work on cf
    // Dynamically import AgentMarkdown when running in Cloudflare Worker
    const { AgentMarkdown } = await AgentMarkdownImport;
    return await AgentMarkdown.produce(html);
    } else {
    // Dynamically import TurndownService otherwise
    return new (await TurndownService)().turndown(html);
    }
    }

    /**
    * extracts article from html
    * then converts it to md
    * @returns markdown in string
    */
    export async function readability2markdown(html: string): Promise<{ title: string; markdown: string }> {
    const doc = await (new DOMParser().parseFromString(html, "text/html"));

taras-markdown_download.web.val.run
Updated: October 17, 2024