Skip to content

Commit

Permalink
Merge pull request #1004 from WolframResearch/bugfix/misc-formatting-…
Browse files Browse the repository at this point in the history
…fixes

Bugfix: Render HTML entities correctly and fix formatting for adjacent tables
  • Loading branch information
rhennigan authored Dec 31, 2024
2 parents 3df6a12 + 8021688 commit 32f56cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PacletInfo.wl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PacletObject[ <|
"Name" -> "Wolfram/Chatbook",
"PublisherID" -> "Wolfram",
"Version" -> "2.0.8",
"Version" -> "2.0.9",
"WolframVersion" -> "14.1+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
Expand Down
35 changes: 33 additions & 2 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ reformatTextData[ string_String ] /; StringContainsQ[ string, $$mdEscapedCharact

reformatTextData[ string_String ] := joinAdjacentStrings @ Flatten[
makeResultCell /@ discardBadToolCalls @ DeleteCases[
Quiet[ StringSplit[ string, $textDataFormatRules, IgnoreCase -> True ], RegularExpression::maxrec ],
Quiet[
StringSplit[
importHTMLEntities @ string,
$textDataFormatRules,
IgnoreCase -> True
],
RegularExpression::maxrec
],
""
]
];
Expand All @@ -247,6 +254,30 @@ reformatTextData[ other_ ] := other;

reformatTextData // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*importHTMLEntities*)
importHTMLEntities // beginDefinition;

importHTMLEntities[ string_String ] := StringReplace[
string,
entity: ("&" ~~ Repeated[ Except[ "\n" ], { 1, 6 } ] ~~ ";") :> importHTMLEntity @ entity
];

importHTMLEntities // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsubsection::Closed:: *)
(*importHTMLEntity*)
importHTMLEntity // beginDefinition;

importHTMLEntity[ entity_String ] := importHTMLEntity[ entity ] =
With[ { str = Quiet @ ImportString[ ToLowerCase @ entity, "HTML" ] },
If[ StringQ @ str, str, entity ]
];

importHTMLEntity // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*discardBadToolCalls*)
Expand Down Expand Up @@ -462,7 +493,7 @@ makeTableCell // beginDefinition;

makeTableCell[ table_String ] := Flatten @ {
"\n",
makeTableCell0 @ StringTrim @ table
Riffle[ makeTableCell0 /@ StringSplit[ StringTrim @ table, "\n\n" ], "\n" ]
};

makeTableCell // endDefinition;
Expand Down

0 comments on commit 32f56cf

Please sign in to comment.