Skip to content

Commit

Permalink
Merge pull request #462 from WolframResearch/bugfix/cloud-box-data-ar…
Browse files Browse the repository at this point in the history
…guments

Bugfix: Cloud notebooks use two arguments for `BoxData`
  • Loading branch information
rhennigan authored Nov 22, 2023
2 parents 3f983d0 + 65d1b5c commit 61b3b68
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Source/Chatbook/ChatMessages.wl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $$validMessageResults = $$validMessageResult | { $$validMessageResult ... };

$$inlineModifierCell = Alternatives[
Cell[ _, "InlineModifierReference", ___ ],
Cell[ BoxData @ Cell[ _, "InlineModifierReference", ___ ], ___ ]
Cell[ BoxData[ Cell[ _, "InlineModifierReference", ___ ], ___ ], ___ ]
];

$$promptArgumentToken = Alternatives[ ">", "^", "^^" ];
Expand Down
10 changes: 5 additions & 5 deletions Source/Chatbook/Explode.wl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ explodeCell // beginDefinition;
explodeCell[ cellObject_CellObject ] := explodeCell @ NotebookRead @ cellObject;
explodeCell[ Cell[ content_, ___ ] ] := explodeCell @ content;
explodeCell[ string_String ] := Cell[ #, "Text" ] & /@ StringSplit[ string, Longest[ "\n".. ] ];
explodeCell[ (BoxData|TextData)[ textData_ ] ] := explodeCell @ Flatten @ List @ textData;
explodeCell[ (BoxData|TextData)[ textData_, ___ ] ] := explodeCell @ Flatten @ List @ textData;

explodeCell[ textData_List ] := Enclose[
Module[ { processed },
Expand All @@ -40,7 +40,7 @@ explodeCell // endDefinition;
(*$preprocessingRules*)
$preprocessingRules := $preprocessingRules = Dispatch @ {
(* Convert TextRefLink to plain hyperlink: *)
Cell @ BoxData @ TemplateBox[ { label_, uri_ }, "TextRefLink" ] :>
Cell @ BoxData[ TemplateBox[ { label_, uri_ }, "TextRefLink" ], ___ ] :>
Cell @ BoxData @ ButtonBox[
StyleBox[ label, "Text" ],
BaseStyle -> "Link",
Expand All @@ -61,20 +61,20 @@ $preprocessingRules := $preprocessingRules = Dispatch @ {
] :> cell,

(* Convert "ChatCodeInlineTemplate" to "InlineCode" cells: *)
Cell[ BoxData @ TemplateBox[ { boxes_ }, "ChatCodeInlineTemplate" ], "ChatCode"|"ChatCodeActive", ___ ] :>
Cell[ BoxData[ TemplateBox[ { boxes_ }, "ChatCodeInlineTemplate" ], "ChatCode"|"ChatCodeActive", ___ ], ___ ] :>
Cell[ BoxData @ boxes, "InlineCode" ],

(* Remove "ChatCode" styling from inputs: *)
Cell[ boxes_, "ChatCode", "Input", ___ ] :> Cell[ boxes, "Input" ],

(* Remove "ChatCodeBlock" styling: *)
Cell[ BoxData[ cell_Cell ], "ChatCodeBlock", ___ ] :> cell,
Cell[ BoxData[ cell_Cell, ___ ], "ChatCodeBlock", ___ ] :> cell,

(* Remove "ChatCodeBlockTemplate" template boxes: *)
TemplateBox[ { cell_Cell }, "ChatCodeBlockTemplate" ] :> cell,

(* Remove nested cells: *)
Cell @ BoxData[ cell_Cell ] :> cell,
Cell @ BoxData[ cell_Cell, ___ ] :> cell,

(* Remove extra style overrides from external language cells: *)
Cell[ content_, "ExternalLanguage", OrderlessPatternSequence[ System`CellEvaluationLanguage -> lang_, __ ] ] :>
Expand Down
8 changes: 4 additions & 4 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ copyCode // endDefinition;
(*stripMarkdownBoxes*)
stripMarkdownBoxes // beginDefinition;

stripMarkdownBoxes[ Cell[ BoxData @ TagBox[ TooltipBox[ boxes_, _String ], "MarkdownImage", ___ ], a___ ] ] :=
stripMarkdownBoxes[ Cell[ BoxData[ TagBox[ TooltipBox[ boxes_, _String ], "MarkdownImage", ___ ], ___ ], a___ ] ] :=
Cell[ BoxData @ boxes, a ];

stripMarkdownBoxes[ Cell[ BoxData @ TagBox[ boxes_, "MarkdownImage", ___ ], a___ ] ] :=
stripMarkdownBoxes[ Cell[ BoxData[ TagBox[ boxes_, "MarkdownImage", ___ ], a___ ], ___ ] ] :=
Cell[ BoxData @ boxes, a ];

stripMarkdownBoxes[ expr: _Cell|_String ] :=
Expand All @@ -486,9 +486,9 @@ stripMarkdownBoxes // endDefinition;
(*getCodeBlockContent*)
getCodeBlockContent // beginDefinition;
getCodeBlockContent[ cell_CellObject ] := getCodeBlockContent @ NotebookRead @ cell;
getCodeBlockContent[ Cell[ BoxData[ boxes_ ], ___, "ChatCodeBlock", ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ Cell[ BoxData[ boxes_, ___ ], ___, "ChatCodeBlock", ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ TemplateBox[ { boxes_ }, "ChatCodeBlockTemplate", ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ Cell[ BoxData[ boxes_ ] ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ Cell[ BoxData[ boxes_, ___ ] ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ DynamicModuleBox[ _, boxes_, ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ TagBox[ boxes_, _EventHandlerTag, ___ ] ] := getCodeBlockContent @ boxes;
getCodeBlockContent[ Cell[ boxes_, "ChatCode", "Input", ___ ] ] := Cell[ boxes, "Input" ];
Expand Down
25 changes: 14 additions & 11 deletions Source/Chatbook/Serialization.wl
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ fasterCellToString0 @ DynamicBox[ ToBoxes[ If[ $OperatingSystem === os_String, a

(* Checkboxes: *)
fasterCellToString0[ Cell[
BoxData @ TagBox[ grid_GridBox, "Grid", ___ ],
BoxData[ TagBox[ grid_GridBox, "Grid", ___ ], ___ ],
___,
CellTags -> { ___, "CheckboxCell", ___ },
___
Expand Down Expand Up @@ -997,12 +997,12 @@ fasterCellToString0[
TagBox[ _, "MarkdownImage", ___, TaggingRules -> KeyValuePattern[ "CellToStringData" -> string_String ], ___ ]
] := string;

fasterCellToString0[ BoxData[ boxes_List ] ] :=
fasterCellToString0[ BoxData[ boxes_List, ___ ] ] :=
With[ { strings = fasterCellToString0 /@ boxes },
StringRiffle[ strings, "\n" ] /; AllTrue[ strings, StringQ ]
];

fasterCellToString0[ BoxData[ boxes_ ] ] :=
fasterCellToString0[ BoxData[ boxes_, ___ ] ] :=
fasterCellToString0 @ boxes;

fasterCellToString0[ list_List ] :=
Expand Down Expand Up @@ -1032,11 +1032,14 @@ fasterCellToString0[ DynamicModuleBox[
_,
TagBox[
Cell[
BoxData @ TagBox[
_,
"MarkdownImage",
___,
TaggingRules -> Association @ OrderlessPatternSequence[ "CellToStringData" -> str_String, ___ ]
BoxData[
TagBox[
_,
"MarkdownImage",
___,
TaggingRules -> Association @ OrderlessPatternSequence[ "CellToStringData" -> str_String, ___ ]
],
___
],
__
],
Expand Down Expand Up @@ -1164,7 +1167,7 @@ stringToBoxes[ string_String ] :=
Quiet @ UsingFrontEnd @ MathLink`CallFrontEnd @ FrontEnd`UndocumentedTestFEParserPacket[ string, True ]
];

stringToBoxes[ string_, { BoxData[ boxes_ ], ___ } ] := boxes;
stringToBoxes[ string_, { BoxData[ boxes_, ___ ], ___ } ] := boxes;
stringToBoxes[ string_, other_ ] := string;

(* ::**************************************************************************************************************:: *)
Expand Down Expand Up @@ -1417,9 +1420,9 @@ makeUsageString // SetFallthroughError;

makeUsageString[ usage_List ] := StringRiffle[ Flatten[ makeUsageString /@ usage ], "\n" ];

makeUsageString[ Cell[ BoxData @ GridBox[ grid_List, ___ ], "Usage", ___ ] ] := makeUsageString0 /@ grid;
makeUsageString[ Cell[ BoxData[ GridBox[ grid_List, ___ ], ___ ], "Usage", ___ ] ] := makeUsageString0 /@ grid;

makeUsageString[ Cell[ BoxData @ GridBox @ { { cell_, _ } }, "ObjectNameGrid", ___ ] ] :=
makeUsageString[ Cell[ BoxData[ GridBox[ { { cell_, _ } }, ___ ], ___ ], "ObjectNameGrid", ___ ] ] :=
"# " <> cellToString @ cell <> "\n";

makeUsageString0 // SetFallthroughError;
Expand Down

0 comments on commit 61b3b68

Please sign in to comment.