From 427bcecefd726434e83aaed0e11d5f0d17140967 Mon Sep 17 00:00:00 2001 From: Talon Poole Date: Wed, 24 Feb 2021 19:57:59 +0000 Subject: [PATCH] fix inline media src and title --- example.gmi | 4 ++-- html.js | 9 ++++++--- spec.js | 46 +++++++++++++++++++++++----------------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/example.gmi b/example.gmi index 0c9bac4..df4aacc 100644 --- a/example.gmi +++ b/example.gmi @@ -23,8 +23,8 @@ but even simpler ### inline media => video.mp4 video -=> image.jpg image -=> audio.mp3 audio +=> image.jpg image +=> audio.mp3 audio => video-no-title.mp4 => image-no-title.mp4 => audio-no-title.mp4 diff --git a/html.js b/html.js index 4005f39..60f3942 100644 --- a/html.js +++ b/html.js @@ -42,13 +42,16 @@ export function block( exts.some((ext) => new RegExp(`\.${ext}$`).test(url)); if (options.image && matchesExt(href, options.image)) { type = "img"; - props += ` src="${href}"` + alt ? ` title="${alt}"` : ""; + props += ` src="${href}"` + props += title ? ` title="${title}"` : ""; } else if (options.audio && matchesExt(href, options.audio)) { type = "audio"; - props += ` controls src="${href}"` + alt ? ` title="${alt}"` : ""; + props += ` controls src="${href}"` + props += title ? ` title="${title}"` : ""; } else if (options.video && matchesExt(href, options.video)) { type = "video"; - props += ` controls src="${href}"` + alt ? ` title="${alt}"` : ""; + props += ` controls src="${href}"` + props += title ? ` title="${title}"` : ""; } else { type = "a"; content = title || href; diff --git a/spec.js b/spec.js index 6363724..ee767b6 100644 --- a/spec.js +++ b/spec.js @@ -33,8 +33,8 @@ test("--body", () => {

inline media

video - image - audio + image + audio

=> video-no-title.mp4

=> image-no-title.mp4

=> audio-no-title.mp4

" @@ -67,8 +67,8 @@ test("--body", () => {

inline media

video - image - audio + image + audio

=> video-no-title.mp4

=> image-no-title.mp4

=> audio-no-title.mp4

" @@ -122,8 +122,8 @@ test("--html en", () => {

inline media

video - image - audio + image + audio

=> video-no-title.mp4

=> image-no-title.mp4

=> audio-no-title.mp4

@@ -142,15 +142,15 @@ test("--image, --audio, --video", () => { audio: ["mp3"], }) ).toMatchInlineSnapshot(` - "

gmi-web

-
a bridge between HTML and Gemini
- https://codeberg.org/talon/gmi-web - on NPM + "

gmi-web

+
a bridge between HTML and Gemini
+ https://codeberg.org/talon/gmi-web + on NPM

-

line-types

+

line-types

-

gmi-web makes writing HTML documents as simple as learning the handful of Gemini line-types:

-