From a9c14556e292243bd2f6d036a6ad44fe578cd148 Mon Sep 17 00:00:00 2001 From: Ben Burdette <> Date: Fri, 10 Oct 2025 11:19:42 -0600 Subject: [PATCH] note -> image, video, audio --- elm/src/MdCommon.elm | 28 +++++++++++++------------ elm/src/MdGui.elm | 4 ++-- elm/src/MdInlineXform.elm | 43 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/elm/src/MdCommon.elm b/elm/src/MdCommon.elm index c647cb9d..d18d4391 100644 --- a/elm/src/MdCommon.elm +++ b/elm/src/MdCommon.elm @@ -329,7 +329,7 @@ type alias HtmlFns a = , panelView : String -> List a -> a , imageView : String -> String -> Maybe String -> List a -> a , videoView : String -> Maybe String -> Maybe String -> Maybe String -> List a -> a - , audioView : String -> String -> List a -> a + , audioView : String -> Maybe String -> List a -> a , noteView : String -> Maybe String -> Maybe String -> List a -> a , yeetView : String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> List a -> a } @@ -394,11 +394,13 @@ textHtml = |> List.filterMap identity ) , audioView = - \text src _ -> + \src text _ -> htmlTextTag "audio" - [ ( "src", src ) - , ( "text", text ) - ] + ([ Just ( "src", src ) + , Maybe.map (\s -> ( "text", s )) text + ] + |> List.filterMap identity + ) , noteView = \id show text _ -> htmlTextTag "note" @@ -442,8 +444,8 @@ htmlF hf = |> Markdown.Html.withOptionalAttribute "width" |> Markdown.Html.withOptionalAttribute "height" , Markdown.Html.tag "audio" hf.audioView - |> Markdown.Html.withAttribute "text" |> Markdown.Html.withAttribute "src" + |> Markdown.Html.withOptionalAttribute "text" , Markdown.Html.tag "note" hf.noteView |> Markdown.Html.withAttribute "id" |> Markdown.Html.withOptionalAttribute "show" @@ -542,14 +544,14 @@ imageView fui text url mbwidth renderedChildren = { src = furl, description = text } -audioView : FileUrlInfo -> String -> String -> List (Element a) -> Element a -audioView fui text url renderedChildren = - htmlAudioView (fileUrl fui url) text +audioView : FileUrlInfo -> String -> Maybe String -> List (Element a) -> Element a +audioView fui url mbtext renderedChildren = + htmlAudioView (fileUrl fui url) mbtext -htmlAudioView : String -> String -> Element a -htmlAudioView url text = - E.html (Html.audio [ HA.controls True, HA.src url ] [ Html.text text ]) +htmlAudioView : String -> Maybe String -> Element a +htmlAudioView url mbtext = + E.html (Html.audio [ HA.controls True, HA.src url ] [ Html.text (Maybe.withDefault "" mbtext) ]) audioNoteView : FileUrlInfo -> Data.ZkNote -> Element a @@ -561,7 +563,7 @@ audioNoteView fui zkn = E.column [ EBd.width 1, E.spacing 5, E.padding 5 ] [ link ("/note/" ++ zkNoteIdToString zkn.id) [ E.text zkn.title ] , E.row [ E.spacing 20 ] - [ htmlAudioView fileurl zkn.title + [ htmlAudioView fileurl (Just zkn.title) , if fui.tauri || List.filter (\i -> i == DataUtil.sysids.publicid) zkn.sysids /= [] then link ("https://29a.ch/timestretch/#a=" ++ fui.location ++ "/file/" ++ zkNoteIdToString zkn.id) diff --git a/elm/src/MdGui.elm b/elm/src/MdGui.elm index e781522a..c6278f47 100644 --- a/elm/src/MdGui.elm +++ b/elm/src/MdGui.elm @@ -939,7 +939,7 @@ guiHtmlElement tag attribs = "audio" -> case Toop.T2 (findAttrib "src" attribs) (findAttrib "text" attribs) of - Toop.T2 (Just src) (Just text) -> + Toop.T2 (Just src) mbtext -> row <| E.column coltrib [ EI.text [] @@ -950,7 +950,7 @@ guiHtmlElement tag attribs = } , EI.text [] { onChange = AudioText - , text = text + , text = Maybe.withDefault "" mbtext , placeholder = Nothing , label = EI.labelLeft [] (E.text "text") } diff --git a/elm/src/MdInlineXform.elm b/elm/src/MdInlineXform.elm index 046b62d1..818a4796 100644 --- a/elm/src/MdInlineXform.elm +++ b/elm/src/MdInlineXform.elm @@ -139,7 +139,44 @@ transforms inline = ( mbtext, Just noteid, show ) -> [ ( "none", inline ) , ( "link", MB.Link ("/note/" ++ noteid) Nothing [ MB.Text (Maybe.withDefault "" mbtext) ] ) - , ( "panel" + , ( "md image", MB.Image ("/file/" ++ noteid) mbtext [] ) + , ( "zkn image" + , MB.HtmlInline + (MB.HtmlElement "image" + (List.filterMap identity + [ Just { name = "url", value = "/file/" ++ noteid } + , mbtext + |> Maybe.map (\s -> { name = "text", value = s }) + ] + ) + [] + ) + ) + , ( "zkn video" + , MB.HtmlInline + (MB.HtmlElement "video" + (List.filterMap identity + [ Just { name = "src", value = "/file/" ++ noteid } + , mbtext + |> Maybe.map (\s -> { name = "text", value = s }) + ] + ) + [] + ) + ) + , ( "zkn audio" + , MB.HtmlInline + (MB.HtmlElement "audio" + (List.filterMap identity + [ Just { name = "src", value = "/file/" ++ noteid } + , mbtext + |> Maybe.map (\s -> { name = "text", value = s }) + ] + ) + [] + ) + ) + , ( "zkn panel" , MB.HtmlInline (MB.HtmlElement "panel" [ { name = "noteid", value = noteid } ] @@ -261,7 +298,7 @@ transforms inline = ) , Just ( "md image", MB.Image url mbt inlines ) , Just - ( "html image" + ( "zkn image" , MB.HtmlInline (MB.HtmlElement "image" (List.filterMap identity @@ -278,7 +315,7 @@ transforms inline = Image src mbt inlines -> [ ( "none", inline ) , ( "link", MB.Link src mbt inlines ) - , ( "html image" + , ( "zkn image" , MB.HtmlInline (MB.HtmlElement "image" (List.filterMap identity