diff --git a/Source/Chatbook/Formatting.wl b/Source/Chatbook/Formatting.wl index e9af28cf..2a5d626a 100644 --- a/Source/Chatbook/Formatting.wl +++ b/Source/Chatbook/Formatting.wl @@ -301,7 +301,7 @@ makeResultCell0[ mathCell[ math_String ] ] := ] ]; -makeResultCell0[ imageCell[ alt_String, url_String ] ] := image[ alt, url ]; +makeResultCell0[ imageCell[ alt_, url_String ] ] := image[ alt, url ]; makeResultCell0[ hyperlinkCell[ label_String, url_String ] ] := hyperlink[ label, url ]; @@ -1283,7 +1283,13 @@ $stringFormatRules = { Cell @ BoxData @ TemplateBox[ { $freeformPromptBox, "paclet:guide/KnowledgeRepresentationAndAccess#203374175" }, "HyperlinkPaclet" - ] + ], + + StringExpression[ + "" + ] :> image[ None, uri ] }; (* ::**************************************************************************************************************:: *) @@ -2237,7 +2243,7 @@ image // beginDefinition; image[ str_String ] := First @ StringSplit[ str, "![" ~~ alt__ ~~ "](" ~~ url__ ~~ ")" :> image[ alt, url ] ]; -image[ alt_String, url_String ] := Enclose[ +image[ alt_, url_String ] := Enclose[ Module[ { keys, key }, keys = ConfirmMatch[ Keys @ $attachments, { ___String? StringQ }, "Keys" ]; key = SelectFirst[ keys, StringContainsQ[ url, #1, IgnoreCase -> True ] & ]; @@ -2335,12 +2341,12 @@ attachmentBoxes // endDefinition; (*markdownImageBoxes*) markdownImageBoxes // beginDefinition; -markdownImageBoxes[ "", url_String, expr_ ] := PaneBox[ +markdownImageBoxes[ ""|None, url_String, expr_ ] := PaneBox[ TagBox[ cachedBoxes @ expr, "MarkdownImage", AutoDelete -> True, - TaggingRules -> <| "CellToStringData" -> "![]("<>url<>")" |> + TaggingRules -> <| "CellToStringData" -> toMIBoxURI @ url |> ], ImageMargins -> { { 0, 0 }, { 10, 10 } } ]; @@ -2350,13 +2356,40 @@ markdownImageBoxes[ alt_String, url_String, expr_ ] := PaneBox[ TooltipBox[ cachedBoxes @ expr, ToString[ alt, InputForm ] ], "MarkdownImage", AutoDelete -> True, - TaggingRules -> <| "CellToStringData" -> "!["<>alt<>"]("<>url<>")" |> + TaggingRules -> <| "CellToStringData" -> "![" <> alt <> "](" <> url <> ")" |> ], ImageMargins -> { { 0, 0 }, { 10, 10 } } ]; markdownImageBoxes // endDefinition; +(* ::**************************************************************************************************************:: *) +(* ::Subsubsubsection::Closed:: *) +(*toMIBoxURI*) +toMIBoxURI // beginDefinition; + +toMIBoxURI[ uri_String ] := Enclose[ + Catch @ Module[ { expr }, + + expr = ConfirmMatch[ + catchAlways @ Quiet @ GetExpressionURI[ uri, HoldComplete ], + HoldComplete[ _ ] | _Failure, + "GetExpression" + ]; + + Replace[ + expr, + { + HoldComplete[ e_ ] :> ConfirmBy[ MakeExpressionURI @ Unevaluated @ e, StringQ, "URI" ], + _Failure :> If[ StringQ @ URLParse[ uri, "Scheme" ], uri, "expression://"<>uri ] + } + ] + ], + throwInternalFailure +]; + +toMIBoxURI // endDefinition; + (* ::**************************************************************************************************************:: *) (* ::Subsubsection::Closed:: *) (*importedImage*)