@@ -967,7 +967,7 @@ describe("Handlers", () => {
967967 ) ;
968968 const result = ctx . data . join ( "" ) ;
969969 const imageId = result . match (
970- / ^ # b o x \( f i g u r e \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " , a l t : " E x a m p l e \\ \\ I m a g e " \) \) , w i d t h : 1 0 0 % \) $ / ,
970+ / ^ # b o x \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " , a l t : " E x a m p l e \\ \\ I m a g e " \) \) $ / ,
971971 ) ?. [ 1 ] ;
972972 expect ( imageId ) . toBe ( "img-" + hash ( "https://example.com/image.png" ) ) ;
973973 expect ( ctx . assets . length ) . toBe ( 1 ) ;
@@ -987,7 +987,7 @@ describe("Handlers", () => {
987987 ) ;
988988 const result = ctx . data . join ( "" ) ;
989989 const imageId = result . match (
990- / ^ # b o x \( f i g u r e \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " \) \) , w i d t h : 1 0 0 % \) $ / ,
990+ / ^ # b o x \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " \) \) $ / ,
991991 ) ?. [ 1 ] ;
992992 expect ( imageId ) . toBe ( "img-" + hash ( "https://example.com/image.png" ) ) ;
993993 expect ( ctx . assets . length ) . toBe ( 1 ) ;
@@ -1082,7 +1082,7 @@ describe("Handlers", () => {
10821082 ) ;
10831083 const result = ctx . data . join ( "" ) ;
10841084 const imageId = result . match (
1085- / ^ # b o x \( f i g u r e \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " , a l t : " i m g \\ \\ " \) \) , w i d t h : 1 0 0 % \) $ / ,
1085+ / ^ # b o x \( i m a g e \( " ( i m g - [ 0 - 9 a - f ] { 16 } ) " , a l t : " i m g \\ \\ " \) \) $ / ,
10861086 ) ?. [ 1 ] ;
10871087 expect ( imageId ) . toBe ( "img-" + hash ( "https://example.com/ref1.png" ) ) ;
10881088 expect ( ctx . assets . length ) . toBe ( 1 ) ;
@@ -1217,6 +1217,141 @@ describe("Handlers", () => {
12171217 expect ( ctx . definitionById . size ) . toBe ( 0 ) ;
12181218 expect ( ctx . footnoteById . size ) . toBe ( 0 ) ;
12191219 } ) ;
1220+ describe ( "Figure" , ( ) => {
1221+ test ( "Figure without caption" , ( ) => {
1222+ const ctx = initContext ( ) ;
1223+ handlers . containerDirective (
1224+ {
1225+ type : "containerDirective" ,
1226+ name : "figure" ,
1227+ children : [
1228+ {
1229+ type : "paragraph" ,
1230+ children : [
1231+ {
1232+ type : "text" ,
1233+ value : "This is a figure caption." ,
1234+ } ,
1235+ ] ,
1236+ } ,
1237+ {
1238+ type : "paragraph" ,
1239+ children : [
1240+ {
1241+ type : "text" ,
1242+ value : "This is figure content." ,
1243+ } ,
1244+ ] ,
1245+ } ,
1246+ ] ,
1247+ } ,
1248+ ctx ,
1249+ ) ;
1250+ expect ( ctx . data . join ( "" ) ) . toBe ( `#figure()[
1251+ #par[#"This is a figure caption."]
1252+ #par[#"This is figure content."]
1253+ ]
1254+ ` ) ;
1255+ } ) ;
1256+ test ( "Figure with caption" , ( ) => {
1257+ const ctx = initContext ( ) ;
1258+ handlers . containerDirective (
1259+ {
1260+ type : "containerDirective" ,
1261+ name : "figure" ,
1262+ children : [
1263+ {
1264+ type : "paragraph" ,
1265+ children : [
1266+ {
1267+ type : "text" ,
1268+ value : "This is a figure caption." ,
1269+ } ,
1270+ ] ,
1271+ } ,
1272+ {
1273+ type : "paragraph" ,
1274+ children : [
1275+ {
1276+ type : "text" ,
1277+ value : "This is figure content." ,
1278+ } ,
1279+ ] ,
1280+ } ,
1281+ ] ,
1282+ attributes : {
1283+ caption : "Figure Caption Attribute" ,
1284+ } ,
1285+ } ,
1286+ ctx ,
1287+ ) ;
1288+ expect ( ctx . data . join ( "" ) )
1289+ . toBe ( `#figure(caption: "Figure Caption Attribute", )[
1290+ #par[#"This is a figure caption."]
1291+ #par[#"This is figure content."]
1292+ ]
1293+ ` ) ;
1294+ } ) ;
1295+ } ) ;
1296+ describe ( "unknown directive node" , ( ) => {
1297+ test ( "unknown container directive" , ( ) => {
1298+ const ctx = initContext ( ) ;
1299+ handlers . containerDirective (
1300+ {
1301+ type : "containerDirective" ,
1302+ name : "unknown" ,
1303+ children : [
1304+ {
1305+ type : "paragraph" ,
1306+ children : [
1307+ {
1308+ type : "text" ,
1309+ value : "Some content" ,
1310+ } ,
1311+ ] ,
1312+ } ,
1313+ ] ,
1314+ } ,
1315+ ctx ,
1316+ ) ;
1317+ expect ( ctx . data . join ( "" ) ) . toBe ( `#par[#"Some content"]
1318+ ` ) ;
1319+ } ) ;
1320+ test ( "unknown leaf directive" , ( ) => {
1321+ const ctx = initContext ( ) ;
1322+ handlers . leafDirective (
1323+ {
1324+ type : "leafDirective" ,
1325+ name : "unknownLeaf" ,
1326+ children : [
1327+ {
1328+ type : "text" ,
1329+ value : "Leaf content" ,
1330+ } ,
1331+ ] ,
1332+ } ,
1333+ ctx ,
1334+ ) ;
1335+ expect ( ctx . data . join ( "" ) ) . toBe ( `#"Leaf content"` ) ;
1336+ } ) ;
1337+ test ( "unknown text directive" , ( ) => {
1338+ const ctx = initContext ( ) ;
1339+ handlers . textDirective (
1340+ {
1341+ type : "textDirective" ,
1342+ name : "unknownText" ,
1343+ children : [
1344+ {
1345+ type : "text" ,
1346+ value : "Text content" ,
1347+ } ,
1348+ ] ,
1349+ } ,
1350+ ctx ,
1351+ ) ;
1352+ expect ( ctx . data . join ( "" ) ) . toBe ( `#"Text content"` ) ;
1353+ } ) ;
1354+ } ) ;
12201355} ) ;
12211356
12221357test ( "Compiler Integration Test" , ( ) => {
@@ -1366,7 +1501,7 @@ test("Compiler Integration Test", () => {
13661501
13671502#heading(level: 1, [#"Remark-typst"#"[^fn1]"#" Integration Test"#footnote(label("user-footnote: fn2"))#" Document"])
13681503#par[#"!["#"Undefined Image Reference"#"][img1]"]
1369- #par[#box(figure( image("{{hash}}", alt: "Defined Image Reference")), width: 100% )]
1504+ #par[#box(image("{{hash}}", alt: "Defined Image Reference"))]
13701505#par[#"["#"Undefined Link Reference"#"][link1]"]
13711506#par[#link("https://example.com/link2", [#"Defined Link Reference"])]
13721507
0 commit comments