Skip to content

Commit

Permalink
Bugfix: Markdown tables with less than 3 columns were not formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Mar 15, 2024
1 parent ab4946a commit b27a486
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ $externalLanguageRules = Replace[
{ 1 }
];

$$mdRow = Except[ "\n" ].. ~~ Repeated[ ("|" ~~ Except[ "\n" ]..), { 2, Infinity } ] ~~ ("\n"|EndOfString);
$$mdRow1 = WhitespaceCharacter... ~~ "|" ~~ Except[ "\n" ].. ~~ "|" ~~ WhitespaceCharacter... ~~ ("\n"|EndOfString);
$$mdRow2 = Except[ "\n" ].. ~~ Repeated[ ("|" ~~ Except[ "\n" ]..), { 2, Infinity } ] ~~ ("\n"|EndOfString);
$$mdRow = $$mdRow1 | $$mdRow2;
$$mdTable = $$mdRow ~~ $$mdRow ..;

$chatGeneratedCellTag = "ChatGeneratedCell";
Expand Down Expand Up @@ -320,10 +322,7 @@ makeTableCell // beginDefinition;

makeTableCell[ table_String ] := Flatten @ {
$tinyLineBreak,
Map[
makeTableCell0 @ StringRiffle[ #1, "\n" ] &,
SplitBy[ StringSplit[ table, "\n" ], StringCount[ #1, "|" ] & ]
],
makeTableCell0 @ table,
$tinyLineBreak
};

Expand All @@ -344,7 +343,7 @@ makeTableCell0[ { a_List, { b__String? delimiterItemQ }, c__ } ] :=
"TextTableForm"
];

makeTableCell0[ items_List? MatrixQ ] :=
makeTableCell0[ items_List ] :=
Cell[ BoxData @ ToBoxes @ textTableForm @ items, "TextTableForm" ];

makeTableCell0 // endDefinition;
Expand Down

0 comments on commit b27a486

Please sign in to comment.