Skip to content

Commit

Permalink
Merge pull request #1014 from WolframResearch/bugfix/455056
Browse files Browse the repository at this point in the history
Links to expression URIs will open the expression in a new notebook
  • Loading branch information
rhennigan authored Jan 6, 2025
2 parents 2c1d4d0 + 15fc401 commit 4a37b0d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 11 deletions.
Binary file modified Assets/DisplayFunctions.wxf
Binary file not shown.
22 changes: 22 additions & 0 deletions Developer/Resources/Styles.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,28 @@ Cell[
]



(* ::Subsection::Closed:: *)
(*TextExpressionLink*)


Cell[
StyleData[ "TextExpressionLink" ],
TemplateBoxOptions -> {
DisplayFunction -> Function @ ButtonBox[
#1,
Appearance -> None,
BaseStyle -> { "Text", "Hyperlink" },
ButtonFunction :> CreateDocument @ BinaryDeserialize @ BaseDecode @ #2,
DefaultBaseStyle -> { },
Evaluator -> Automatic,
Method -> "Queued"
]
}
]



(* ::Section::Closed:: *)
(*Package Footer*)

Expand Down
20 changes: 19 additions & 1 deletion FrontEnd/Assets/Extensions/CoreExtensions.nb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Notebook[
Cell["Chatbook Core.nb Extensions", "Title"],
Cell[
StyleData["ChatStyleSheetInformation"],
TaggingRules -> <|"StyleSheetVersion" -> "2.0.8.3943617669"|>
TaggingRules -> <|"StyleSheetVersion" -> "2.0.15.3945149906"|>
],
Cell[
StyleData["NotebookAssistant`Text"],
Expand Down Expand Up @@ -14078,6 +14078,24 @@ Notebook[
]
])
}
],
Cell[
StyleData["TextExpressionLink"],
TemplateBoxOptions -> {
DisplayFunction ->
(Function[
ButtonBox[
#1,
Appearance -> None,
BaseStyle -> {"Text", "Hyperlink"},
ButtonFunction :>
CreateDocument[BinaryDeserialize[BaseDecode[#2]]],
DefaultBaseStyle -> { },
Evaluator -> Automatic,
Method -> "Queued"
]
])
}
]
},
StyleDefinitions -> "Default.nb"
Expand Down
20 changes: 19 additions & 1 deletion FrontEnd/StyleSheets/Chatbook.nb
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ Notebook[
],
Cell[
StyleData["ChatStyleSheetInformation"],
TaggingRules -> <|"StyleSheetVersion" -> "2.0.8.3943617669"|>
TaggingRules -> <|"StyleSheetVersion" -> "2.0.15.3945149906"|>
],
Cell[
StyleData["NotebookAssistant`Text"],
Expand Down Expand Up @@ -14957,6 +14957,24 @@ Notebook[
]
])
}
],
Cell[
StyleData["TextExpressionLink"],
TemplateBoxOptions -> {
DisplayFunction ->
(Function[
ButtonBox[
#1,
Appearance -> None,
BaseStyle -> {"Text", "Hyperlink"},
ButtonFunction :>
CreateDocument[BinaryDeserialize[BaseDecode[#2]]],
DefaultBaseStyle -> { },
Evaluator -> Automatic,
Method -> "Queued"
]
])
}
]
},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/StyleSheets/Wolfram/WorkspaceChat.nb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Notebook[
Cell[StyleData["CellExpression"], Selectable -> True],
Cell[
StyleData["WorkspaceChatStyleSheetInformation"],
TaggingRules -> <|"WorkspaceChatStyleSheetVersion" -> "2.0.8.3943617669"|>
TaggingRules -> <|"WorkspaceChatStyleSheetVersion" -> "2.0.15.3945149906"|>
],
Cell[
StyleData["AttachedCell"],
Expand Down
7 changes: 0 additions & 7 deletions Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -989,13 +989,6 @@ $useRasterizationCompatibility := Enclose[
]
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*expressionURIQ*)
expressionURIQ // beginDefinition;
expressionURIQ[ uri_String ] := KeyExistsQ[ $attachments, StringDelete[ uri, StartOfString ~~ __ ~~ "://" ] ];
expressionURIQ // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*graphicsURIQ*)
Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/CommonSymbols.wl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ BeginPackage[ "Wolfram`Chatbook`Common`" ];
`exportDataURI;
`expressionURIKey;
`expressionURIKeyQ;
`expressionURIQ;
`extractBodyChunks;
`fakeOpenerView;
`fastFileHash;
Expand Down
11 changes: 11 additions & 0 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,17 @@ $embeddedImageTemplate = "<div style=\"margin: -8px;\"><img src=\"`1`\" width=\"
(*hyperlink*)
hyperlink // beginDefinition;

hyperlink[ label_String, uri_String? expressionURIQ ] :=
If[ TrueQ @ $dynamicText,
StyleBox[ label, "Hyperlink" ],
With[ { b = BaseEncode @ BinarySerialize[ GetExpressionURI @ uri, PerformanceGoal -> "Size" ] },
Cell[
BoxData @ TemplateBox[ { ToBoxes @ label, b }, "TextExpressionLink" ],
Background -> None
]
]
];

hyperlink[ label_String | { label_String }, uri_String ] /; StringStartsQ[ uri, "paclet:" ] :=
Cell @ BoxData @ TemplateBox[
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Tools/ExpressionURIs.wl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ expressionURIKey // beginDefinition;

expressionURIKey[ str_String ] := expressionURIKey[ str ] = FixedPoint[
StringDelete @ {
StartOfString ~~ "![" ~~ __ ~~ "](",
StartOfString ~~ ("!["|"[") ~~ __ ~~ "](",
StartOfString ~~ LetterCharacter.. ~~ "://",
")"~~EndOfString
},
Expand Down

0 comments on commit 4a37b0d

Please sign in to comment.