diff --git a/PacletInfo.wl b/PacletInfo.wl index 6fdb9a7e..d0067bec 100644 --- a/PacletInfo.wl +++ b/PacletInfo.wl @@ -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", diff --git a/Source/Chatbook/Formatting.wl b/Source/Chatbook/Formatting.wl index 8668b644..738e8645 100644 --- a/Source/Chatbook/Formatting.wl +++ b/Source/Chatbook/Formatting.wl @@ -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 + ], "" ] ]; @@ -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*) @@ -462,7 +493,7 @@ makeTableCell // beginDefinition; makeTableCell[ table_String ] := Flatten @ { "\n", - makeTableCell0 @ StringTrim @ table + Riffle[ makeTableCell0 /@ StringSplit[ StringTrim @ table, "\n\n" ], "\n" ] }; makeTableCell // endDefinition;