Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links to expression URIs will open the expression in a new notebook #1014

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading