## Issue - [URLを展開する · Issue \#7 · tadashi\-aikawa/obsidian\-free\-writing](https://github.com/tadashi-aikawa/obsidian-free-writing/issues/7) ## 仕様 - URLがHTMLを取得する場合はソーシャルカードを表示する - URLが画像を取得する場合はimgタグで画像を表示する - 他のケースは一旦保留 - 動画など考えられるケースは多いけど ## メモ ### `requestUrl`のレスポンス 上がHTML、下が画像(jpeg)。 ![[Pasted image 20230805152550.png]] ### HTMLの解析ロジック [[🧊Obsidian Templater Insert link card]]を参考にする。 上記は[[JavaScript]]なので[[TypeScript]]になおす(型定義を追加する)必要あり。 ### 不要になったけどせっかく作ったので... ```ts export function trimMax(str: string, num: number): string { return str.length > num ? `${str.substring(0, num)}...` : str; } export function trimEmptyLine(str: string): string { return str .split("\n") .filter((x) => x) .join("\n"); } describe.each` text | num | expected ${"1234567890"} | ${0} | ${"..."} ${"1234567890"} | ${1} | ${"1..."} ${"1234567890"} | ${9} | ${"123456789..."} ${"1234567890"} | ${10} | ${"1234567890"} `("trimMax", ({ text, num, expected }) => { test(`trimMax(${text}, ${num}) = ${expected}`, () => { expect(trimMax(text, num)).toBe(expected); }); }); describe.each` text | expected ${"aaa\n\nbbb\n"} | ${"aaa\nbbb"} ${"aaa"} | ${"aaa"} ${""} | ${""} `("trimEmptyLine", ({ text, expected }) => { test(`trimEmptyLine(${text}) = ${expected}`, () => { expect(trimEmptyLine(text)).toBe(expected); }); }); ```