Refactoring rendering tests

This commit is contained in:
Vincent Prouillet 2022-02-25 17:13:29 +01:00
parent dde3531fd9
commit 40d7208493
81 changed files with 2203 additions and 3846 deletions

383
Cargo.lock generated
View file

@ -25,15 +25,14 @@ dependencies = [
[[package]]
name = "ammonia"
version = "3.1.3"
version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b74b175af97d1aecc1add0878b1cbfcbf3bd4c22d7713eeb6d597da23e29bc0d"
checksum = "ea9f21d23d82bae9d33c21080572af1fa749788e68234b5d8fa5e39d3e0783ed"
dependencies = [
"html5ever",
"lazy_static",
"maplit",
"markup5ever_rcdom",
"matches",
"tendril",
"url",
]
@ -55,9 +54,9 @@ checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e"
[[package]]
name = "anyhow"
version = "1.0.53"
version = "1.0.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
checksum = "159bb86af3a200e19a068f4224eae4c8bb2d0fa054c7e5d1cacd5cef95e684cd"
[[package]]
name = "arrayvec"
@ -97,9 +96,9 @@ dependencies = [
[[package]]
name = "autocfg"
version = "1.0.1"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
@ -142,9 +141,9 @@ dependencies = [
[[package]]
name = "block-buffer"
version = "0.10.0"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95"
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [
"generic-array 0.14.5",
]
@ -224,9 +223,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cc"
version = "1.0.72"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
dependencies = [
"jobserver",
]
@ -305,9 +304,9 @@ dependencies = [
[[package]]
name = "clap"
version = "3.0.13"
version = "3.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e"
checksum = "5177fac1ab67102d8989464efd043c6ff44191b1557ec1ddd489b4f7e1447e77"
dependencies = [
"atty",
"bitflags",
@ -322,18 +321,18 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "3.0.5"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4dabb7e2f006497e1da045feaa512acf0686f76b68d94925da2d9422dcb521"
checksum = "23eec4dd324308f49d8bf86a2732078c34d57955fec1e1d865554fc37c15d420"
dependencies = [
"clap 3.0.13",
"clap 3.1.2",
]
[[package]]
name = "clap_derive"
version = "3.0.12"
version = "3.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fd2078197a22f338bd4fbf7d6387eb6f0d6a3c69e6cbc09f5c93e97321fd92a"
checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e"
dependencies = [
"heck 0.4.0",
"proc-macro-error",
@ -370,10 +369,23 @@ dependencies = [
]
[[package]]
name = "core-foundation"
version = "0.9.2"
name = "console"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3"
checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31"
dependencies = [
"encode_unicode",
"libc",
"once_cell",
"terminal_size",
"winapi 0.3.9",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
dependencies = [
"core-foundation-sys",
"libc",
@ -396,9 +408,9 @@ dependencies = [
[[package]]
name = "crc32fast"
version = "1.3.1"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
]
@ -426,9 +438,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.6"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -439,9 +451,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.6"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
@ -449,11 +461,12 @@ dependencies = [
[[package]]
name = "crypto-common"
version = "0.1.1"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0"
checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
dependencies = [
"generic-array 0.14.5",
"typenum",
]
[[package]]
@ -488,15 +501,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "deflate"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f95bf05dffba6e6cce8dfbb30def788154949ccd9aed761b472119c21e01c70"
dependencies = [
"adler32",
]
[[package]]
name = "deflate"
version = "1.0.0"
@ -529,13 +533,12 @@ dependencies = [
[[package]]
name = "digest"
version = "0.10.1"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer 0.10.0",
"block-buffer 0.10.2",
"crypto-common",
"generic-array 0.14.5",
]
[[package]]
@ -569,6 +572,12 @@ dependencies = [
"strum_macros",
]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "encoding"
version = "0.2.33"
@ -656,7 +665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4badb9489a465cb2c555af1f00f0bfd8cecd6fc12ac11da9d5b40c5dd5f0200"
dependencies = [
"bit_field",
"deflate 1.0.0",
"deflate",
"flume",
"half",
"inflate",
@ -701,14 +710,14 @@ dependencies = [
"cfg-if 1.0.0",
"crc32fast",
"libc",
"miniz_oxide",
"miniz_oxide 0.4.4",
]
[[package]]
name = "flume"
version = "0.10.10"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d04dafd11240188e146b6f6476a898004cace3be31d4ec5e08e216bf4947ac0"
checksum = "0b279436a715a9de95dcd26b151db590a71961cc06e54918b24fe0dd5b7d3fc4"
dependencies = [
"futures-core",
"futures-sink",
@ -796,9 +805,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futf"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843"
dependencies = [
"mac",
"new_debug_unreachable",
@ -806,42 +815,42 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b"
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-io"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-sink"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508"
checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
[[package]]
name = "futures-task"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72"
checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
[[package]]
name = "futures-util"
version = "0.3.19"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [
"futures-core",
"futures-io",
@ -893,9 +902,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
@ -1047,9 +1056,9 @@ dependencies = [
[[package]]
name = "httparse"
version = "1.5.1"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503"
checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4"
[[package]]
name = "httpdate"
@ -1065,9 +1074,9 @@ checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
[[package]]
name = "hyper"
version = "0.14.16"
version = "0.14.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55"
checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd"
dependencies = [
"bytes 1.1.0",
"futures-channel",
@ -1078,7 +1087,7 @@ dependencies = [
"http-body",
"httparse",
"httpdate",
"itoa 0.4.8",
"itoa 1.0.1",
"pin-project-lite",
"socket2",
"tokio",
@ -1144,16 +1153,16 @@ dependencies = [
[[package]]
name = "image"
version = "0.24.0"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94ac3d41f882c624a82d7945952032388488681f45f9d4077999a6c85688d61"
checksum = "db207d030ae38f1eb6f240d5a1c1c88ff422aa005d10f8c6c6fc5e75286ab30e"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"exr",
"gif",
"jpeg-decoder 0.2.1",
"jpeg-decoder 0.2.2",
"num-iter",
"num-rational",
"num-traits",
@ -1213,6 +1222,20 @@ dependencies = [
"libc",
]
[[package]]
name = "insta"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c0c443f6dceb3a1cb7607c87501aa91e4b9c976044f725c2a74ca2152c91a4"
dependencies = [
"console",
"once_cell",
"serde",
"serde_json",
"serde_yaml",
"similar",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -1281,9 +1304,9 @@ checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
[[package]]
name = "jpeg-decoder"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbcf0244f6597be39ab8d9203f574cafb529ae8c698afa2182f7b3c3205a4a9c"
checksum = "105fb082d64e2100074587f59a74231f771750c664af903f1f9f76c9dedfc6f1"
dependencies = [
"rayon",
]
@ -1349,9 +1372,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.116"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]]
name = "library"
@ -1609,9 +1632,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.3"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
@ -1638,6 +1661,15 @@ dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.6.23"
@ -1659,9 +1691,9 @@ dependencies = [
[[package]]
name = "mio"
version = "0.7.14"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
dependencies = [
"libc",
"log",
@ -1715,7 +1747,7 @@ dependencies = [
"httparse",
"lazy_static",
"log",
"rand 0.8.4",
"rand 0.8.5",
"regex",
"serde_json",
"serde_urlencoded",
@ -1727,7 +1759,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958"
dependencies = [
"getrandom 0.2.4",
"getrandom 0.2.5",
]
[[package]]
@ -1871,9 +1903,9 @@ dependencies = [
[[package]]
name = "ntapi"
version = "0.3.6"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
dependencies = [
"winapi 0.3.9",
]
@ -1984,9 +2016,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "open"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "176ee4b630d174d2da8241336763bb459281dddc0f4d87f72c3b1efc9a6109b7"
checksum = "5a82915836ef43159bb6a3c64d884c42329ccd0b8afdca737cf1e3dd701709dc"
dependencies = [
"pathdiff",
"winapi 0.3.9",
@ -2042,7 +2074,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
"parking_lot_core 0.8.5",
]
[[package]]
name = "parking_lot"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core 0.9.1",
]
[[package]]
@ -2059,6 +2101,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "parking_lot_core"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
]
[[package]]
name = "parse-zoneinfo"
version = "0.3.0"
@ -2184,7 +2239,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
dependencies = [
"phf_shared 0.10.0",
"rand 0.8.4",
"rand 0.8.5",
]
[[package]]
@ -2260,15 +2315,14 @@ dependencies = [
[[package]]
name = "png"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c845088517daa61e8a57eee40309347cea13f273694d1385c553e7a57127763b"
checksum = "8e8f1882177b17c98ec33a51f5910ecbf4db92ca0def706781a1f8d0c661f393"
dependencies = [
"bitflags",
"crc32fast",
"deflate 0.9.1",
"encoding",
"miniz_oxide",
"deflate",
"miniz_oxide 0.5.1",
]
[[package]]
@ -2352,20 +2406,19 @@ dependencies = [
"libc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc 0.2.0",
"rand_hc",
"rand_pcg",
]
[[package]]
name = "rand"
version = "0.8.4"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.3",
"rand_hc 0.3.1",
]
[[package]]
@ -2403,7 +2456,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom 0.2.4",
"getrandom 0.2.5",
]
[[package]]
@ -2415,15 +2468,6 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_hc"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [
"rand_core 0.6.3",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
@ -2492,9 +2536,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "relative-path"
version = "1.6.0"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73d4caf086b102ab49d0525b721594a555ab55c6556086bbe52a430ad26c3bd7"
checksum = "a49a831dc1e13c9392b660b162333d4cb0033bbbdfe6a1687177e59e89037c86"
[[package]]
name = "remove_dir_all"
@ -2512,6 +2556,7 @@ dependencies = [
"config",
"errors",
"front_matter",
"insta",
"libs",
"link_checker",
"pest",
@ -2598,9 +2643,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.20.2"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84"
checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921"
dependencies = [
"log",
"ring",
@ -2704,9 +2749,9 @@ dependencies = [
[[package]]
name = "security-framework"
version = "2.6.0"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fed7948b6c68acbb6e20c334f55ad635dc0f75506963de4464289fbd3b051ac"
checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc"
dependencies = [
"bitflags",
"core-foundation",
@ -2717,9 +2762,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "2.6.0"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a57321bf8bc2362081b2599912d2961fe899c0efadf1b4b2f8d48b3e253bb96c"
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
dependencies = [
"core-foundation-sys",
"libc",
@ -2747,9 +2792,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.78"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
"indexmap",
"itoa 1.0.1",
@ -2795,13 +2840,13 @@ dependencies = [
[[package]]
name = "sha2"
version = "0.10.1"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.1",
"digest 0.10.3",
]
[[package]]
@ -2813,6 +2858,12 @@ dependencies = [
"libc",
]
[[package]]
name = "similar"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3"
[[package]]
name = "siphasher"
version = "0.3.9"
@ -2901,14 +2952,14 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "string_cache"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
checksum = "33994d0838dc2d152d17a62adf608a869b5e846b65b389af7f3dbc1de45c5b26"
dependencies = [
"lazy_static",
"new_debug_unreachable",
"parking_lot",
"phf_shared 0.8.0",
"parking_lot 0.11.2",
"phf_shared 0.10.0",
"precomputed-hash",
"serde",
]
@ -3066,7 +3117,7 @@ dependencies = [
"percent-encoding",
"pest",
"pest_derive",
"rand 0.8.4",
"rand 0.8.5",
"regex",
"serde",
"serde_json",
@ -3084,10 +3135,20 @@ dependencies = [
]
[[package]]
name = "test-case"
version = "1.2.1"
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cad0a06f9a61e94355aa3b3dc92d85ab9c83406722b1ca5e918d4297c12c23"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "test-case"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9e5f048404b43e8ae66dce036163515b6057024cf58c6377be501f250bd3c6a"
dependencies = [
"cfg-if 1.0.0",
"proc-macro2",
@ -3204,19 +3265,20 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.16.1"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"bytes 1.1.0",
"libc",
"memchr",
"mio 0.7.14",
"mio 0.8.0",
"num_cpus",
"once_cell",
"parking_lot",
"parking_lot 0.12.0",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi 0.3.9",
]
@ -3284,9 +3346,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]]
name = "tracing"
version = "0.1.29"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
@ -3295,9 +3357,9 @@ dependencies = [
[[package]]
name = "tracing-core"
version = "0.1.21"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23"
dependencies = [
"lazy_static",
]
@ -3423,9 +3485,9 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-width"
@ -3678,6 +3740,49 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
[[package]]
name = "winreg"
version = "0.7.0"
@ -3698,9 +3803,9 @@ dependencies = [
[[package]]
name = "ws"
version = "0.9.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51a2c47b5798ccc774ffb93ff536aec7c4275d722fd9c740c83cdd1af1f2d94"
checksum = "25fe90c75f236a0a00247d5900226aea4f2d7b05ccc34da9e7a8880ff59b5848"
dependencies = [
"byteorder",
"bytes 0.4.12",
@ -3777,7 +3882,7 @@ name = "zola"
version = "0.16.0"
dependencies = [
"atty",
"clap 3.0.13",
"clap 3.1.2",
"clap_complete",
"ctrlc",
"errors",

View file

@ -204,13 +204,8 @@ impl Taxonomy {
// Check for taxon-specific template, or use generic as fallback.
let specific_template = format!("{}/single.html", self.kind.name);
let template = if let Some(template) =
check_template_fallbacks(&specific_template, tera, &config.theme)
{
template
} else {
"taxonomy_single.html"
};
let template = check_template_fallbacks(&specific_template, tera, &config.theme)
.unwrap_or("taxonomy_single.html");
render_template(template, tera, context, &config.theme).map_err(|e| {
Error::chain(format!("Failed to render single term {} page.", self.kind.name), e)

View file

@ -18,4 +18,4 @@ libs = { path = "../libs" }
[dev-dependencies]
templates = { path = "../templates" }
insta = "1.12.0"

View file

@ -481,10 +481,10 @@ mod tests {
fn can_handle_multiple_shortcodes() {
let (_, shortcodes) = parse_for_shortcodes(
r#"
{{ youtube(id="ub36ffWAqgQ") }}
{{ youtube(id="ub36ffWAqgQ_hey_") }}
{{ youtube(id="ub36ffWAqgQ", autoplay=true) }}
{{ vimeo(id="210073083") }}
{{ streamable(id="c0ic") }}
{{ vimeo(id="210073083#hello", n_a_me="hello") }}
{{ streamable(id="c0ic", n1=true) }}
{{ gist(url="https://gist.github.com/Keats/32d26f699dcc13ebd41b") }}"#,
)
.unwrap();

View file

@ -1,56 +0,0 @@
use std::collections::HashMap;
use libs::tera::Tera;
use config::Config;
use front_matter::InsertAnchor;
use rendering::{render_content, RenderContext};
macro_rules! colored_html_line {
( $s:expr ) => {{
let mut result = "<span>".to_string();
result.push_str($s);
result.push_str("\n</span>");
result
}};
}
macro_rules! colored_html {
( $($s:expr),* $(,)* ) => {{
let mut result = "<pre style=\"background-color:#2b303b;color:#c0c5ce;\"><code>".to_string();
$(
result.push_str(colored_html_line!($s).as_str());
)*
result.push_str("</code></pre>\n");
result
}};
}
#[test]
fn hide_lines_simple() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hide_lines=2
foo
bar
baz
bat
```
"#,
&context,
)
.unwrap();
assert_eq!(res.body, colored_html!("foo", "baz", "bat"));
}

View file

@ -1,515 +0,0 @@
use std::collections::HashMap;
use libs::tera::Tera;
use config::Config;
use front_matter::InsertAnchor;
use rendering::{render_content, RenderContext};
macro_rules! colored_html_line {
( @no $s:expr ) => {{
let mut result = "<span>".to_string();
result.push_str($s);
result.push_str("\n</span>");
result
}};
( @hl $s:expr ) => {{
let mut result = "<mark style=\"background-color:#65737e30;\">".to_string();
result.push_str("<span>");
result.push_str($s);
result.push_str("\n</span>");
result.push_str("</mark>");
result
}};
}
macro_rules! colored_html {
( $(@$kind:tt $s:expr),* $(,)* ) => {{
let mut result = "<pre style=\"background-color:#2b303b;color:#c0c5ce;\"><code>".to_string();
$(
result.push_str(colored_html_line!(@$kind $s).as_str());
)*
result.push_str("</code></pre>\n");
result
}};
}
#[test]
fn hl_lines_simple() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@hl "bar",
@no "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_in_middle() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=2-3
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_all() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=1-4
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@hl "baz",
)
);
}
#[test]
fn hl_lines_start_from_one() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=1-3
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_start_from_zero() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=0-3
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_end() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=3-4
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@no "bar",
@hl "bar",
@hl "baz",
)
);
}
#[test]
fn hl_lines_end_out_of_bounds() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=3-4294967295
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@no "bar",
@hl "bar",
@hl "baz",
)
);
}
#[test]
fn hl_lines_overlap() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=2-3 1-2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_multiple() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=2-3,hl_lines=1-2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_extra_spaces() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
``` hl_lines = 2 - 3 1 - 2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_int_and_range() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=1 3-4
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@hl "foo",
@no "bar",
@hl "bar",
@hl "baz",
)
);
}
#[test]
fn hl_lines_single_line_range() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=2-2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@hl "bar",
@no "bar",
@no "baz",
)
);
}
#[test]
fn hl_lines_reverse_range() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```hl_lines=3-2
foo
bar
bar
baz
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
colored_html!(
@no "foo",
@hl "bar",
@hl "bar",
@no "baz",
)
);
}

View file

@ -1,97 +0,0 @@
use std::collections::HashMap;
use libs::tera::Tera;
use config::Config;
use front_matter::InsertAnchor;
use rendering::{render_content, RenderContext};
#[test]
fn can_add_line_numbers() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```linenos
foo
bar
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre data-linenos style=\"background-color:#2b303b;color:#c0c5ce;\"><code><table><tbody><tr><td>1</td><td><span>foo\n</span></td></tr><tr><td>2</td><td><span>bar\n</span></td></tr></tbody></table></code></pre>\n"
);
}
#[test]
fn can_add_line_numbers_with_linenostart() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```linenos, linenostart=40
foo
bar
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre data-linenos style=\"background-color:#2b303b;color:#c0c5ce;\"><code><table><tbody><tr><td>40</td><td><span>foo\n</span></td></tr><tr><td>41</td><td><span>bar\n</span></td></tr></tbody></table></code></pre>\n"
);
}
#[test]
fn can_add_line_numbers_with_highlight() {
let tera_ctx = Tera::default();
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
```linenos, hl_lines=2
foo
bar
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre data-linenos style=\"background-color:#2b303b;color:#c0c5ce;\"><code><table><tbody><tr><td>1</td><td><span>foo\n</span></td></tr><tr><td><mark style=\"background-color:#65737e30;\">2</mark></td><td><mark style=\"background-color:#65737e30;\"><span>bar\n</span></mark></td></tr></tbody></table></code></pre>\n"
);
}

View file

@ -1,271 +0,0 @@
use std::collections::HashMap;
use config::Config;
use front_matter::InsertAnchor;
use rendering::{render_content, RenderContext};
use templates::ZOLA_TERA;
#[test]
fn can_render_shortcode_in_codeblock() {
let permalinks_ctx = HashMap::new();
let config = Config::default_for_test();
let mut context = RenderContext::new(
&ZOLA_TERA,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&ZOLA_TERA);
context.set_shortcode_definitions(&shortcode_def);
// simple case
let res = render_content(
r#"
```
{{ youtube(id="dQw4w9WgXcQ") }}
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre><code>&lt;div &gt;\n &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;\n&lt;&#x2F;div&gt;\n\n</code></pre>\n"
);
// mixed with other contents
let res = render_content(
r#"
```
<div id="custom-attr">
{{ youtube(id="dQw4w9WgXcQ") }}
</div>
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre><code>&lt;div id=&quot;custom-attr&quot;&gt;\n&lt;div &gt;\n &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;\n&lt;&#x2F;div&gt;\n\n&lt;&#x2F;div&gt;\n</code></pre>\n"
);
// mixed content with syntax and line numbers
let res = render_content(
r#"
```html,linenos
<div id="custom-attr">
{{ youtube(id="dQw4w9WgXcQ") }}
</div>
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre data-linenos data-lang=\"html\" class=\"language-html \"><code class=\"language-html\" data-lang=\"html\"><table><tbody><tr><td>1</td><td>&lt;div id=&quot;custom-attr&quot;&gt;\n</td></tr><tr><td>2</td><td>&lt;div &gt;\n</td></tr><tr><td>3</td><td> &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;\n</td></tr><tr><td>4</td><td>&lt;&#x2F;div&gt;\n</td></tr><tr><td>5</td><td>\n</td></tr><tr><td>6</td><td>&lt;&#x2F;div&gt;\n</td></tr></tbody></table></code></pre>\n"
);
}
#[test]
fn can_render_multiple_shortcodes_in_codeblock() {
let permalinks_ctx = HashMap::new();
let config = Config::default_for_test();
let mut context = RenderContext::new(
&ZOLA_TERA,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&ZOLA_TERA);
context.set_shortcode_definitions(&shortcode_def);
// simple case
let res = render_content(
r#"
```
{{ youtube(id="dQw4w9WgXcQ") }}
{{ gist(url="https://gist.github.com/Keats/e5fb6aad409f28721c0ba14161644c57", class="gist") }}
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre><code>&lt;div &gt;\n &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;\n&lt;&#x2F;div&gt;\n\n&lt;div class=&quot;gist&quot;&gt;\n &lt;script src=&quot;https:&amp;#x2F;&amp;#x2F;gist.github.com&amp;#x2F;Keats&amp;#x2F;e5fb6aad409f28721c0ba14161644c57.js&quot;&gt;&lt;&#x2F;script&gt;\n&lt;&#x2F;div&gt;\n\n</code></pre>\n"
);
// mixed with other contents
let res = render_content(
r#"
```
text 1
{{ youtube(id="dQw4w9WgXcQ") }}
text 2
{{ gist(url="https://gist.github.com/Keats/e5fb6aad409f28721c0ba14161644c57", class="gist") }}
text 3
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre><code>text 1\n&lt;div &gt;\n &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;\n&lt;&#x2F;div&gt;\n\ntext 2\n&lt;div class=&quot;gist&quot;&gt;\n &lt;script src=&quot;https:&amp;#x2F;&amp;#x2F;gist.github.com&amp;#x2F;Keats&amp;#x2F;e5fb6aad409f28721c0ba14161644c57.js&quot;&gt;&lt;&#x2F;script&gt;\n&lt;&#x2F;div&gt;\n\ntext 3\n</code></pre>\n"
);
// mixed content with syntax and line numbers
let res = render_content(
r#"
```html,linenos
<span>text 1</span>
{{ youtube(id="dQw4w9WgXcQ") }}
<span>text 2</span>
{{ gist(url="https://gist.github.com/Keats/e5fb6aad409f28721c0ba14161644c57", class="gist") }}
<span>text 3</span>
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
r#"<pre data-linenos data-lang="html" class="language-html "><code class="language-html" data-lang="html"><table><tbody><tr><td>1</td><td>&lt;span&gt;text 1&lt;&#x2F;span&gt;
</td></tr><tr><td>2</td><td>&lt;div &gt;
</td></tr><tr><td>3</td><td> &lt;iframe src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;&#x2F;iframe&gt;
</td></tr><tr><td>4</td><td>&lt;&#x2F;div&gt;
</td></tr><tr><td>5</td><td>
</td></tr><tr><td>6</td><td>&lt;span&gt;text 2&lt;&#x2F;span&gt;
</td></tr><tr><td>7</td><td>&lt;div class=&quot;gist&quot;&gt;
</td></tr><tr><td>8</td><td> &lt;script src=&quot;https:&amp;#x2F;&amp;#x2F;gist.github.com&amp;#x2F;Keats&amp;#x2F;e5fb6aad409f28721c0ba14161644c57.js&quot;&gt;&lt;&#x2F;script&gt;
</td></tr><tr><td>9</td><td>&lt;&#x2F;div&gt;
</td></tr><tr><td>10</td><td>
</td></tr><tr><td>11</td><td>&lt;span&gt;text 3&lt;&#x2F;span&gt;
</td></tr></tbody></table></code></pre>
"#
);
}
#[test]
fn is_highlighting_linenos_still_working() {
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let mut context = RenderContext::new(
&ZOLA_TERA,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&ZOLA_TERA);
context.set_shortcode_definitions(&shortcode_def);
// single shortcode mixed with syntax and line numbers
let res = render_content(
r#"
```html,linenos
<div id="custom-attr">
{{ youtube(id="dQw4w9WgXcQ") }}
</div>
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
"<pre data-linenos data-lang=\"html\" style=\"background-color:#2b303b;color:#c0c5ce;\" class=\"language-html \"><code class=\"language-html\" data-lang=\"html\"><table><tbody><tr><td>1</td><td><span>&lt;</span><span style=\"color:#bf616a;\">div </span><span style=\"color:#8fa1b3;\">id</span><span>=&quot;</span><span style=\"color:#a3be8c;\">custom-attr</span><span>&quot;&gt;\n</span></td></tr><tr><td>2</td><td><span>&lt;</span><span style=\"color:#bf616a;\">div </span><span>&gt;\n</span></td></tr><tr><td>3</td><td><span> &lt;</span><span style=\"color:#bf616a;\">iframe </span><span style=\"color:#d08770;\">src</span><span>=&quot;</span><span style=\"color:#a3be8c;\">https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ</span><span>&quot; </span><span style=\"color:#d08770;\">webkitallowfullscreen mozallowfullscreen allowfullscreen</span><span>&gt;&lt;/</span><span style=\"color:#bf616a;\">iframe</span><span>&gt;\n</span></td></tr><tr><td>4</td><td><span>&lt;/</span><span style=\"color:#bf616a;\">div</span><span>&gt;\n</span></td></tr><tr><td>5</td><td><span>\n</span></td></tr><tr><td>6</td><td><span>&lt;/</span><span style=\"color:#bf616a;\">div</span><span>&gt;\n</span></td></tr></tbody></table></code></pre>\n"
);
// multiple shortcode mixed with syntax and line numbers
let res = render_content(
r#"
```html,linenos
<span>text 1</span>
{{ youtube(id="dQw4w9WgXcQ") }}
<span>text 2</span>
{{ gist(url="https://gist.github.com/Keats/e5fb6aad409f28721c0ba14161644c57", class="gist") }}
<span>text 3</span>
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
r#"<pre data-linenos data-lang="html" style="background-color:#2b303b;color:#c0c5ce;" class="language-html "><code class="language-html" data-lang="html"><table><tbody><tr><td>1</td><td><span>&lt;</span><span style="color:#bf616a;">span</span><span>&gt;text 1&lt;/</span><span style="color:#bf616a;">span</span><span>&gt;
</span></td></tr><tr><td>2</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span>&gt;
</span></td></tr><tr><td>3</td><td><span> &lt;</span><span style="color:#bf616a;">iframe </span><span style="color:#d08770;">src</span><span>=&quot;</span><span style="color:#a3be8c;">https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ</span><span>&quot; </span><span style="color:#d08770;">webkitallowfullscreen mozallowfullscreen allowfullscreen</span><span>&gt;&lt;/</span><span style="color:#bf616a;">iframe</span><span>&gt;
</span></td></tr><tr><td>4</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>5</td><td><span>
</span></td></tr><tr><td>6</td><td><span>&lt;</span><span style="color:#bf616a;">span</span><span>&gt;text 2&lt;/</span><span style="color:#bf616a;">span</span><span>&gt;
</span></td></tr><tr><td>7</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span style="color:#d08770;">class</span><span>=&quot;</span><span style="color:#a3be8c;">gist</span><span>&quot;&gt;
</span></td></tr><tr><td>8</td><td><span> &lt;</span><span style="color:#bf616a;">script </span><span style="color:#d08770;">src</span><span>=&quot;</span><span style="color:#a3be8c;">https:</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">gist.github.com</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">Keats</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">e5fb6aad409f28721c0ba14161644c57.js</span><span>&quot;&gt;&lt;/</span><span style="color:#bf616a;">script</span><span>&gt;
</span></td></tr><tr><td>9</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>10</td><td><span>
</span></td></tr><tr><td>11</td><td><span>&lt;</span><span style="color:#bf616a;">span</span><span>&gt;text 3&lt;/</span><span style="color:#bf616a;">span</span><span>&gt;
</span></td></tr></tbody></table></code></pre>
"#
);
}
#[test]
fn codeblock_shortcode_mix_all_stars() {
let permalinks_ctx = HashMap::new();
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let mut context = RenderContext::new(
&ZOLA_TERA,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&ZOLA_TERA);
context.set_shortcode_definitions(&shortcode_def);
// single shortcode mixed with syntax and line numbers
let res = render_content(
r#"
```html,linenos
<a href="javascript:void(0);">{{/* before(texts="1") */}}</a>
Normally people would not write something & like <> this
<div id="custom-attr">
An inline {{ youtube(id="dQw4w9WgXcQ", autoplay=true, class="youtube") }} shortcode
</div>
Plain text in-between
{%/* quote(author="Vincent") */%}
A quote
{%/* end */%}
{{ gist(url="https://gist.github.com/Keats/e5fb6aad409f28721c0ba14161644c57", class="gist") }}
{# A Tera comment, you should see it #}
<!-- end text goes here -->
```
"#,
&context,
)
.unwrap();
assert_eq!(
res.body,
r#"<pre data-linenos data-lang="html" style="background-color:#2b303b;color:#c0c5ce;" class="language-html "><code class="language-html" data-lang="html"><table><tbody><tr><td>1</td><td><span>&lt;</span><span style="color:#bf616a;">a </span><span style="color:#d08770;">href</span><span>=&quot;</span><span style="color:#a3be8c;">javascript:void(0);</span><span>&quot;&gt;{{ before(texts=&quot;1&quot;) }}&lt;/</span><span style="color:#bf616a;">a</span><span>&gt;
</span></td></tr><tr><td>2</td><td><span>Normally people would not write something &amp; like </span><span style="background-color:#bf616a;color:#2b303b;">&lt;&gt;</span><span> this
</span></td></tr><tr><td>3</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span style="color:#8fa1b3;">id</span><span>=&quot;</span><span style="color:#a3be8c;">custom-attr</span><span>&quot;&gt;
</span></td></tr><tr><td>4</td><td><span>An inline &lt;</span><span style="color:#bf616a;">div </span><span style="color:#d08770;">class</span><span>=&quot;</span><span style="color:#a3be8c;">youtube</span><span>&quot;&gt;
</span></td></tr><tr><td>5</td><td><span> &lt;</span><span style="color:#bf616a;">iframe </span><span style="color:#d08770;">src</span><span>=&quot;</span><span style="color:#a3be8c;">https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?autoplay=1</span><span>&quot; </span><span style="color:#d08770;">webkitallowfullscreen mozallowfullscreen allowfullscreen</span><span>&gt;&lt;/</span><span style="color:#bf616a;">iframe</span><span>&gt;
</span></td></tr><tr><td>6</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>7</td><td><span> shortcode
</span></td></tr><tr><td>8</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>9</td><td><span>Plain text in-between
</span></td></tr><tr><td>10</td><td><span>{% quote(author=&quot;Vincent&quot;) %}
</span></td></tr><tr><td>11</td><td><span>A quote
</span></td></tr><tr><td>12</td><td><span>{% end %}
</span></td></tr><tr><td>13</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span style="color:#d08770;">class</span><span>=&quot;</span><span style="color:#a3be8c;">gist</span><span>&quot;&gt;
</span></td></tr><tr><td>14</td><td><span> &lt;</span><span style="color:#bf616a;">script </span><span style="color:#d08770;">src</span><span>=&quot;</span><span style="color:#a3be8c;">https:</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">gist.github.com</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">Keats</span><span style="color:#8fa1b3;">&amp;#x</span><span style="color:#d08770;">2F;</span><span style="color:#a3be8c;">e5fb6aad409f28721c0ba14161644c57.js</span><span>&quot;&gt;&lt;/</span><span style="color:#bf616a;">script</span><span>&gt;
</span></td></tr><tr><td>15</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>16</td><td><span>
</span></td></tr><tr><td>17</td><td><span>{# A Tera comment, you should see it #}
</span></td></tr><tr><td>18</td><td><span style="color:#65737e;">&lt;!-- end text goes here --&gt;
</span></td></tr></tbody></table></code></pre>
"#
);
}

View file

@ -0,0 +1,337 @@
use config::Config;
mod common;
fn render_codeblock(content: &str, highlight_code: bool) -> String {
let mut config = Config::default_for_test();
config.markdown.highlight_code = highlight_code;
common::render_with_config(content, config).unwrap().body
}
#[test]
fn does_nothing_with_highlighting_disabled() {
let body = render_codeblock(
r#"
```
foo
bar
```
"#,
false,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_hide_lines() {
let body = render_codeblock(
r#"
```hide_lines=2
foo
bar
baz
bat
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_single_line() {
let body = render_codeblock(
r#"
```hl_lines=2
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_line_range() {
let body = render_codeblock(
r#"
```hl_lines=2-3
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_all_lines() {
let body = render_codeblock(
r#"
```hl_lines=1-4
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_zero_start_same_as_one() {
let body = render_codeblock(
r#"
```hl_lines=0-3
foo
bar
bar
baz
```
"#,
true,
);
let body2 = render_codeblock(
r#"
```hl_lines=1-3
foo
bar
bar
baz
```
"#,
true,
);
assert_eq!(body, body2);
}
#[test]
fn can_highlight_at_end() {
let body = render_codeblock(
r#"
```hl_lines=3-4
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_out_of_bounds() {
let body = render_codeblock(
r#"
```hl_lines=3-4567898765
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_ranges_overlap() {
let body = render_codeblock(
r#"
```hl_lines=2-3 1-2
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_weird_fence_tokens() {
let body = render_codeblock(
r#"
```hl_lines=2-3, hl_lines = 1 - 2
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_mix_line_ranges() {
let body = render_codeblock(
r#"
```hl_lines=1 3-4
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_single_line_range() {
let body = render_codeblock(
r#"
```hl_lines=2-2
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_reversed_range() {
let body = render_codeblock(
r#"
```hl_lines=3-2
foo
bar
bar
baz
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_add_line_numbers() {
let body = render_codeblock(
r#"
```linenos
foo
bar
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_add_line_numbers_with_lineno_start() {
let body = render_codeblock(
r#"
```linenos, linenostart=40
foo
bar
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_add_line_numbers_with_highlight() {
let body = render_codeblock(
r#"
```linenos, hl_lines=2
foo
bar
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_render_shortcode_in_codeblock() {
let body = render_codeblock(
r#"
```html,linenos
<div id="custom-attr">
{{ out_put_id(id="dQw4w9WgXcQ") }}
</div>
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_render_multiple_shortcodes_in_codeblock() {
let body = render_codeblock(
r#"
```linenos
text1
{{ out_put_id(id="first") }}
text2
{{ out_put_id(id="second") }}
text3
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_render_completely_mixed_codeblock() {
let body = render_codeblock(
r#"
```html,linenos
<a href="javascript:void(0);">{{/* before(texts="1") */}}</a>
Normally people would not write something & like <> this
<div id="custom-attr">
An inline {{ out_put_id(id="dQw4w9WgXcQ") }} shortcode
</div>
Plain text in-between
{%/* quote(author="Vincent") */%}
A quote
{%/* end */%}
{# A Tera comment, you should see it #}
<!-- end text goes here -->
```
"#,
true,
);
insta::assert_snapshot!(body);
}
#[test]
fn can_highlight_unknown_lang() {
let body = render_codeblock(
r#"
```rustscript
foo
bar
```
"#,
true,
);
insta::assert_snapshot!(body);
}

View file

@ -0,0 +1,89 @@
#![allow(dead_code)]
use std::collections::HashMap;
use std::path::PathBuf;
use libs::tera::Tera;
use config::Config;
use errors::Result;
use front_matter::InsertAnchor;
use rendering::{render_content, RenderContext, Rendered};
use templates::ZOLA_TERA;
fn configurable_render(
content: &str,
config: Config,
insert_anchor: InsertAnchor,
) -> Result<Rendered> {
let mut tera = Tera::default();
tera.extend(&ZOLA_TERA).unwrap();
// out_put_id looks like a markdown string
tera.add_raw_template("shortcodes/out_put_id.html", "{{id}}").unwrap();
tera.add_raw_template(
"shortcodes/image.html",
"<img src='https://placekitten.com/200/300' alt='{{alt}}'></img>",
)
.unwrap();
tera.add_raw_template("shortcodes/split_lines.html", r#"{{ body | split(pat="\n") }}"#)
.unwrap();
tera.add_raw_template("shortcodes/ex1.html", "1").unwrap();
tera.add_raw_template("shortcodes/ex2.html", "2").unwrap();
tera.add_raw_template("shortcodes/ex3.html", "3").unwrap();
tera.add_raw_template("shortcodes/with_tabs.html", "<div>\n\tHello World!\n </div>")
.unwrap();
tera.add_raw_template(
"shortcodes/web_component.html",
"<bc-authorizer-example><code>{{ body | safe}}</code></bc-authorizer-example>",
)
.unwrap();
tera.add_raw_template("shortcodes/render_md.html", "<div>{{ body | markdown | safe}}</div>")
.unwrap();
tera.add_raw_template("shortcodes/a.html", "<p>a: {{ nth }}</p>").unwrap();
tera.add_raw_template("shortcodes/b.html", "<p>b: {{ nth }}</p>").unwrap();
tera.add_raw_template("shortcodes/quote.html", "<quote>{{body}}</quote>").unwrap();
tera.add_raw_template("shortcodes/pre.html", "<pre>{{body}}</pre>").unwrap();
tera.add_raw_template("shortcodes/four_spaces.html", " no highlight\n or there").unwrap();
tera.add_raw_template("shortcodes/i18n.html", "{{lang}}").unwrap();
tera.add_raw_template(
"shortcodes/book.md",
"![Book cover in {{ lang }}](cover.{{ lang }}.png)",
)
.unwrap();
tera.add_raw_template("shortcodes/md_passthrough.md", "{{body}}").unwrap();
let mut permalinks = HashMap::new();
permalinks.insert("pages/about.md".to_owned(), "https://getzola.org/about/".to_owned());
tera.register_filter(
"markdown",
templates::filters::MarkdownFilter::new(PathBuf::new(), config.clone(), permalinks.clone())
.unwrap(),
);
let mut context = RenderContext::new(
&tera,
&config,
&config.default_language,
"",
&permalinks,
insert_anchor,
);
let shortcode_def = utils::templates::get_shortcodes(&tera);
context.set_shortcode_definitions(&shortcode_def);
context.set_current_page_path("my_page.md");
render_content(content, &context)
}
pub fn render(content: &str) -> Result<Rendered> {
configurable_render(content, Config::default_for_test(), InsertAnchor::None)
}
pub fn render_with_config(content: &str, config: Config) -> Result<Rendered> {
configurable_render(content, config, InsertAnchor::None)
}
pub fn render_with_insert_anchor(content: &str, insert_anchor: InsertAnchor) -> Result<Rendered> {
configurable_render(content, Config::default_for_test(), insert_anchor)
}

View file

@ -1,18 +0,0 @@
#![allow(dead_code)]
pub struct ShortCode {
pub name: &'static str,
pub output: &'static str,
pub is_md: bool,
}
impl ShortCode {
pub const fn new(name: &'static str, output: &'static str, is_md: bool) -> ShortCode {
ShortCode { name, output, is_md }
}
/// Return filename for shortcode
pub fn filename(&self) -> String {
format!("{}.{}", self.name, if self.is_md { "md" } else { "html" })
}
}

View file

@ -1,343 +0,0 @@
mod common;
use common::ShortCode;
use libs::tera;
const COMPLETE_PAGE: &str = r#"
<!-- Adapted from https://markdown-it.github.io/ -->
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
## Horizontal Rules
___
---
***
## Emphasis
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
~~Strikethrough~~
## Blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
## Lists
Unordered
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
Ordered
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
1. You can use sequential numbers...
1. ...or keep all the numbers as `1.`
Start numbering with offset:
57. foo
1. bar
## Code
Inline `code`
Indented code
// Some comments
line 1 of code
line 2 of code
line 3 of code
Block code "fences"
```
Sample text here...
```
Syntax highlighting
``` js
var foo = function (bar) {
return bar++;
};
console.log(foo(5));
```
## Shortcodes
{% quote(author="John Doe") %}
This is a test quote!
1900-01-01
{% end %}
## Tables
| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
Right aligned columns
| Option | Description |
| ------:| -----------:|
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |
## Links
[link text](http://duckduckgo.com)
[link with title](http://duckduckgo.com/)
## Images
![Minion](https://octodex.github.com/images/minion.png)
![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")
Like links, Images also have a footnote style syntax
![Alt text][id]
With a reference later in the document defining the URL location:
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
### Footnotes
Footnote 1 link[^first].
Footnote 2 link[^second].
Duplicated footnote reference[^second].
[^first]: Footnote **can have markup**
and multiple paragraphs.
[^second]: Footnote text."#;
#[test]
fn complete_page() {
let config = config::Config::default_for_test();
let mut tera = tera::Tera::default();
let shortcodes: Vec<ShortCode> = vec![ShortCode::new(
"quote",
r"<blockquote>
{{ body }} <br>
-- {{ author}}
</blockquote>",
false,
)];
let mut permalinks = std::collections::HashMap::new();
permalinks.insert("".to_string(), "".to_string());
// Add all shortcodes
for ShortCode { name, is_md, output } in shortcodes.into_iter() {
tera.add_raw_template(
&format!("shortcodes/{}.{}", name, if is_md { "md" } else { "html" }),
&output,
)
.unwrap();
}
let mut context = rendering::RenderContext::new(
&tera,
&config,
&config.default_language,
"",
&permalinks,
front_matter::InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&tera);
context.set_shortcode_definitions(&shortcode_def);
let rendered = rendering::render_content(COMPLETE_PAGE, &context);
assert!(rendered.is_ok(), "Rendering failed");
let rendered = rendered.unwrap();
let asserted_internal_links: Vec<(String, Option<String>)> = vec![];
let asserted_external_links: Vec<String> =
vec!["http://duckduckgo.com".to_string(), "http://duckduckgo.com/".to_string()];
assert_eq!(rendered.internal_links, asserted_internal_links, "Internal links unequal");
assert_eq!(rendered.external_links, asserted_external_links, "External links unequal");
assert_eq!(
rendered.body,
r##"<!-- Adapted from https://markdown-it.github.io/ -->
<h1 id="h1-heading">h1 Heading</h1>
<h2 id="h2-heading">h2 Heading</h2>
<h3 id="h3-heading">h3 Heading</h3>
<h4 id="h4-heading">h4 Heading</h4>
<h5 id="h5-heading">h5 Heading</h5>
<h6 id="h6-heading">h6 Heading</h6>
<h2 id="horizontal-rules">Horizontal Rules</h2>
<hr />
<hr />
<hr />
<h2 id="emphasis">Emphasis</h2>
<p><strong>This is bold text</strong></p>
<p><strong>This is bold text</strong></p>
<p><em>This is italic text</em></p>
<p><em>This is italic text</em></p>
<p><del>Strikethrough</del></p>
<h2 id="blockquotes">Blockquotes</h2>
<blockquote>
<p>Blockquotes can also be nested...</p>
<blockquote>
<p>...by using additional greater-than signs right next to each other...</p>
<blockquote>
<p>...or with spaces between arrows.</p>
</blockquote>
</blockquote>
</blockquote>
<h2 id="lists">Lists</h2>
<p>Unordered</p>
<ul>
<li>Create a list by starting a line with <code>+</code>, <code>-</code>, or <code>*</code></li>
<li>Sub-lists are made by indenting 2 spaces:
<ul>
<li>Marker character change forces new list start:
<ul>
<li>Ac tristique libero volutpat at</li>
</ul>
<ul>
<li>Facilisis in pretium nisl aliquet</li>
</ul>
<ul>
<li>Nulla volutpat aliquam velit</li>
</ul>
</li>
</ul>
</li>
<li>Very easy!</li>
</ul>
<p>Ordered</p>
<ol>
<li>
<p>Lorem ipsum dolor sit amet</p>
</li>
<li>
<p>Consectetur adipiscing elit</p>
</li>
<li>
<p>Integer molestie lorem at massa</p>
</li>
<li>
<p>You can use sequential numbers...</p>
</li>
<li>
<p>...or keep all the numbers as <code>1.</code></p>
</li>
</ol>
<p>Start numbering with offset:</p>
<ol start="57">
<li>foo</li>
<li>bar</li>
</ol>
<h2 id="code">Code</h2>
<p>Inline <code>code</code></p>
<p>Indented code</p>
<pre><code>&#x2F;&#x2F; Some comments
line 1 of code
line 2 of code
line 3 of code
</code></pre>
<p>Block code &quot;fences&quot;</p>
<pre><code>Sample text here...
</code></pre>
<p>Syntax highlighting</p>
<pre data-lang="js" class="language-js "><code class="language-js" data-lang="js">var foo = function (bar) {
return bar++;
};
console.log(foo(5));
</code></pre>
<h2 id="shortcodes">Shortcodes</h2>
<blockquote>
This is a test quote!
1900-01-01 <br>
-- John Doe
</blockquote><h2 id="tables">Tables</h2>
<table><thead><tr><th>Option</th><th>Description</th></tr></thead><tbody>
<tr><td>data</td><td>path to data files to supply the data that will be passed into templates.</td></tr>
<tr><td>engine</td><td>engine to be used for processing templates. Handlebars is the default.</td></tr>
<tr><td>ext</td><td>extension to be used for dest files.</td></tr>
</tbody></table>
<p>Right aligned columns</p>
<table><thead><tr><th align="right">Option</th><th align="right">Description</th></tr></thead><tbody>
<tr><td align="right">data</td><td align="right">path to data files to supply the data that will be passed into templates.</td></tr>
<tr><td align="right">engine</td><td align="right">engine to be used for processing templates. Handlebars is the default.</td></tr>
<tr><td align="right">ext</td><td align="right">extension to be used for dest files.</td></tr>
</tbody></table>
<h2 id="links">Links</h2>
<p><a href="http://duckduckgo.com">link text</a></p>
<p><a href="http://duckduckgo.com/">link with title</a></p>
<h2 id="images">Images</h2>
<p><img src="https://octodex.github.com/images/minion.png" alt="Minion" />
<img src="https://octodex.github.com/images/stormtroopocat.jpg" alt="Stormtroopocat" title="The Stormtroopocat" /></p>
<p>Like links, Images also have a footnote style syntax</p>
<p><img src="https://octodex.github.com/images/dojocat.jpg" alt="Alt text" title="The Dojocat" /></p>
<p>With a reference later in the document defining the URL location:</p>
<h3 id="footnotes">Footnotes</h3>
<p>Footnote 1 link<sup class="footnote-reference"><a href="#first">1</a></sup>.</p>
<p>Footnote 2 link<sup class="footnote-reference"><a href="#second">2</a></sup>.</p>
<p>Duplicated footnote reference<sup class="footnote-reference"><a href="#second">2</a></sup>.</p>
<div class="footnote-definition" id="first"><sup class="footnote-definition-label">1</sup>
<p>Footnote <strong>can have markup</strong>
and multiple paragraphs.</p>
</div>
<div class="footnote-definition" id="second"><sup class="footnote-definition-label">2</sup>
<p>Footnote text.</p>
</div>
"##
);
}

View file

@ -1,63 +1,55 @@
use std::collections::HashMap;
use errors::Result;
use rendering::Rendered;
mod common;
use libs::tera;
fn render_content(content: &str, permalinks: HashMap<String, String>) -> Result<Rendered> {
let config = config::Config::default_for_test();
let tera = tera::Tera::default();
let mut context = rendering::RenderContext::new(
&tera,
&config,
&config.default_language,
"http://mypage.com",
&permalinks,
front_matter::InsertAnchor::None,
);
context.set_current_page_path("mine.md");
rendering::render_content(content, &context)
}
#[test]
fn can_detect_links() {
// no links
let rendered = render_content("Hello World!", HashMap::new()).unwrap();
let rendered = common::render("Hello World!").unwrap();
assert_eq!(rendered.internal_links.len(), 0);
assert_eq!(rendered.external_links.len(), 0);
// external
let rendered = render_content("[abc](https://google.com/)", HashMap::new()).unwrap();
let rendered = common::render("[abc](https://google.com/)").unwrap();
assert_eq!(rendered.internal_links.len(), 0);
assert_eq!(rendered.external_links.len(), 1);
assert_eq!(rendered.external_links[0], "https://google.com/");
// internal
let mut permalinks = HashMap::new();
permalinks.insert("def/123.md".to_owned(), "https://xyz.com/def/123".to_owned());
let rendered = render_content("[abc](@/def/123.md)", permalinks).unwrap();
assert_eq!(rendered.internal_links.len(), 1);
assert_eq!(rendered.internal_links[0], ("def/123.md".to_owned(), None));
let rendered = common::render("[abc](@/pages/about.md)").unwrap();
assert_eq!(rendered.internal_links, vec![("pages/about.md".to_owned(), None)]);
assert_eq!(rendered.external_links.len(), 0);
// internal with anchors
let mut permalinks = HashMap::new();
permalinks.insert("def/123.md".to_owned(), "https://xyz.com/def/123".to_owned());
let rendered = render_content("[abc](@/def/123.md#hello)", permalinks).unwrap();
assert_eq!(rendered.internal_links.len(), 1);
assert_eq!(rendered.internal_links[0], ("def/123.md".to_owned(), Some("hello".to_owned())));
let rendered = common::render("[abc](@/pages/about.md#hello)").unwrap();
assert_eq!(rendered.internal_links[0], ("pages/about.md".to_owned(), Some("hello".to_owned())));
assert_eq!(rendered.external_links.len(), 0);
// internal link referring to self
let rendered = render_content("[abc](#hello)", HashMap::new()).unwrap();
let rendered = common::render("[abc](#hello)").unwrap();
assert_eq!(rendered.internal_links.len(), 1);
assert_eq!(rendered.internal_links[0], ("mine.md".to_owned(), Some("hello".to_owned())));
assert_eq!(rendered.internal_links[0], ("my_page.md".to_owned(), Some("hello".to_owned())));
assert_eq!(rendered.external_links.len(), 0);
// Not pointing to anything so that's an error
let res = render_content("[abc](@/def/123.md)", HashMap::new());
// Mixed with various protocols
let rendered = common::render(
"
[a link](http://google.com)
[a link](http://google.fr)
Email: [foo@bar.baz](mailto:foo@bar.baz)
Email: <foo@bar.baz>",
)
.unwrap();
assert_eq!(rendered.internal_links.len(), 0);
assert_eq!(
rendered.external_links,
&["http://google.com".to_owned(), "http://google.fr".to_owned()]
);
// Not pointing to anything known so that's an error
let res = common::render("[abc](@/def/123.md)");
assert!(res.is_err());
// Empty link is an error as well
let res = common::render("[abc]()");
assert!(res.is_err());
assert_eq!(res.unwrap_err().to_string(), "There is a link that is missing a URL");
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,313 @@
use config::Config;
mod common;
#[test]
fn can_render_simple_text_with_shortcodes() {
let body = common::render(
r#"
hello {{ out_put_id(id="shortcode-id") }}
{% quote() %}
A quote
{% end %}
{{ out_put_id(id="shortcode-id2") }}
{{ out_put_id(id="shortcode-id3") }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_grab_lang_in_html_shortcodes() {
let body = common::render(
r#"
hello in {{ i18n() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_grab_lang_in_md_shortcodes() {
let body = common::render(
r#"
{{ book() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_render_body_shortcode_and_paragraph_after() {
let body = common::render(
r#"
{% quote() %}
This is a quote
{% end %}
Here is another paragraph.
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_render_two_body_shortcode_and_paragraph_after_with_line_break_between() {
let body = common::render(
r#"
{% quote() %}
This is a quote
{% end %}
{% quote() %}
This is a quote
{% end %}
Here is another paragraph.
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn doesnt_render_ignored_shortcodes() {
let body = common::render(
r#"
{{/* youtube(id="w7Ft2ymGmfc") */}}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/Keats/gutenberg/issues/522
#[test]
fn doesnt_try_to_highlight_content_from_shortcode() {
let body = common::render(
r#"
{{ four_spaces() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_emit_newlines_and_whitespace_with_shortcode() {
let body = common::render(
r#"
{% pre() %}
Hello
Zola
!
{% end %}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_passthrough_markdown_from_shortcode() {
let body = common::render(
r#"
Hello
{% md_passthrough() %}
# Passing through
*to* **the** document
{% end %}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/getzola/zola/issues/1172
#[test]
fn doesnt_escape_html_shortcodes() {
let body = common::render(
r#"
{{ image(alt="something") }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn errors_on_unknown_shortcodes() {
let body = common::render(
r#"
{{ unknown() }}
"#,
);
assert!(body.is_err());
}
// https://github.com/getzola/zola/issues/1172
#[test]
fn can_render_commented_out_shortcodes() {
let body = common::render(
r#"
<!-- {{ image(alt="something") }} -->
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn invocation_count_increments_in_shortcode() {
let body = common::render(
r#"
{{ a() }}
{{ b() }}
{{ a() }}
{{ b() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/getzola/zola/issues/1689
#[test]
fn html_shortcode_regression() {
let inputs = vec![
r#"{{ ex2(page="") }} {{ ex1(page="") }} {{ ex3(page="std") }}"#,
r#"<p>{{ ex2(page="") }} {{ ex1(page="") }} {{ ex3(page="std") }}</p>"#, // in html
r#"<p>\n{{ ex2(page='') }}\n</p>"#, // with newlines
r#"<span>{{ ex2(page='') }}</span>\n**The Book** {{ ex2(page='') }}"#,
r#"a.{{ ex2(page="") }} b.{{ ex1(page="") }} c.{{ ex3(page="std") }}"#,
];
for input in inputs {
let body = common::render(input).unwrap().body;
insta::assert_snapshot!(body);
}
}
#[test]
fn can_split_shortcode_body_lines() {
let body = common::render(
r#"
{% split_lines() %}
multi
ple
lines
{% end %}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_render_shortcodes_with_tabs() {
// This can cause problems mostly because the 4 spaces sometimes used for tabs also are used
// to indicate code-blocks
let body = common::render(
r#"
{{ with_tabs() }} {{ with_tabs() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/getzola/zola/issues/1355
#[test]
fn can_render_list_with_shortcode() {
let body = common::render(
r#"
* a
* b
{{ with_tabs() }}
* c
{{ with_tabs() }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/getzola/zola/issues/1655
#[test]
fn shortcodes_do_not_generate_paragraphs() {
let body = common::render(
r#"
{% web_component() %}
some code;
more code;
other code here;
{% end %}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
#[test]
fn can_render_markdown_in_shortcodes() {
let mut config = Config::default_for_test();
config.markdown.highlight_code = true;
let body = common::render_with_config(
r#"
{% render_md() %}
```
some code;
```
{% end %}
"#,
config,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}
// https://github.com/getzola/zola/issues/1600
#[test]
fn can_use_shortcodes_in_quotes() {
let body = common::render(
r#"
> test quote
> {{ image(alt="a quote") }}
"#,
)
.unwrap()
.body;
insta::assert_snapshot!(body);
}

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 227
expression: body
---
<pre data-linenos style="background-color:#2b303b;color:#c0c5ce;"><code><table><tbody><tr><td>1</td><td><span>foo
</span></td></tr><tr><td>2</td><td><span>bar
</span></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 253
expression: body
---
<pre data-linenos style="background-color:#2b303b;color:#c0c5ce;"><code><table><tbody><tr><td>1</td><td><span>foo
</span></td></tr><tr><td><mark style="background-color:#65737e30;">2</mark></td><td><mark style="background-color:#65737e30;"><span>bar
</span></mark></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 240
expression: body
---
<pre data-linenos style="background-color:#2b303b;color:#c0c5ce;"><code><table><tbody><tr><td>40</td><td><span>foo
</span></td></tr><tr><td>41</td><td><span>bar
</span></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 36
expression: res.body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><span>baz
</span><span>bat
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 83
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><mark style="background-color:#65737e30;"><span>foo
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>baz
</span></mark></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 124
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><span>bar
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>baz
</span></mark></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 68
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>baz
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 184
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><mark style="background-color:#65737e30;"><span>foo
</span></mark><span>bar
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>baz
</span></mark></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 139
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><span>bar
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>baz
</span></mark></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 154
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><mark style="background-color:#65737e30;"><span>foo
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>baz
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 214
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>baz
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 53
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>bar
</span><span>baz
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 199
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>foo
</span><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>bar
</span><span>baz
</span></code></pre>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 323
expression: body
---
<pre data-lang="rustscript" style="background-color:#2b303b;color:#c0c5ce;" class="language-rustscript "><code class="language-rustscript" data-lang="rustscript"><span>foo
</span><span>bar
</span></code></pre>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 169
expression: body
---
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><mark style="background-color:#65737e30;"><span>foo
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><mark style="background-color:#65737e30;"><span>bar
</span></mark><span>baz
</span></code></pre>

View file

@ -0,0 +1,19 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 310
expression: body
---
<pre data-linenos data-lang="html" style="background-color:#2b303b;color:#c0c5ce;" class="language-html "><code class="language-html" data-lang="html"><table><tbody><tr><td>1</td><td><span>&lt;</span><span style="color:#bf616a;">a </span><span style="color:#d08770;">href</span><span>=&quot;</span><span style="color:#a3be8c;">javascript:void(0);</span><span>&quot;&gt;{{ before(texts=&quot;1&quot;) }}&lt;/</span><span style="color:#bf616a;">a</span><span>&gt;
</span></td></tr><tr><td>2</td><td><span>Normally people would not write something &amp; like </span><span style="background-color:#bf616a;color:#2b303b;">&lt;&gt;</span><span> this
</span></td></tr><tr><td>3</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span style="color:#8fa1b3;">id</span><span>=&quot;</span><span style="color:#a3be8c;">custom-attr</span><span>&quot;&gt;
</span></td></tr><tr><td>4</td><td><span>An inline dQw4w9WgXcQ shortcode
</span></td></tr><tr><td>5</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr><tr><td>6</td><td><span>Plain text in-between
</span></td></tr><tr><td>7</td><td><span>{% quote(author=&quot;Vincent&quot;) %}
</span></td></tr><tr><td>8</td><td><span>A quote
</span></td></tr><tr><td>9</td><td><span>{% end %}
</span></td></tr><tr><td>10</td><td><span>{# A Tera comment, you should see it #}
</span></td></tr><tr><td>11</td><td><span style="color:#65737e;">&lt;!-- end text goes here --&gt;
</span></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,13 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 288
expression: body
---
<pre data-linenos style="background-color:#2b303b;color:#c0c5ce;"><code><table><tbody><tr><td>1</td><td><span>text1
</span></td></tr><tr><td>2</td><td><span>first
</span></td></tr><tr><td>3</td><td><span>text2
</span></td></tr><tr><td>4</td><td><span>second
</span></td></tr><tr><td>5</td><td><span>text3
</span></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 272
expression: body
---
<pre data-linenos data-lang="html" style="background-color:#2b303b;color:#c0c5ce;" class="language-html "><code class="language-html" data-lang="html"><table><tbody><tr><td>1</td><td><span>&lt;</span><span style="color:#bf616a;">div </span><span style="color:#8fa1b3;">id</span><span>=&quot;</span><span style="color:#a3be8c;">custom-attr</span><span>&quot;&gt;
</span></td></tr><tr><td>2</td><td><span>dQw4w9WgXcQ
</span></td></tr><tr><td>3</td><td><span>&lt;/</span><span style="color:#bf616a;">div</span><span>&gt;
</span></td></tr></tbody></table></code></pre>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/codeblocks.rs
assertion_line: 336
expression: body
---
<pre><code>foo
bar
</code></pre>

View file

@ -0,0 +1,131 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 358
expression: body
---
<!-- Adapted from https://markdown-it.github.io/ -->
<h1 id="h1-heading">h1 Heading</h1>
<h2 id="h2-heading">h2 Heading</h2>
<h3 id="h3-heading">h3 Heading</h3>
<h4 id="h4-heading">h4 Heading</h4>
<h5 id="h5-heading">h5 Heading</h5>
<h6 id="h6-heading">h6 Heading</h6>
<h2 id="horizontal-rules">Horizontal Rules</h2>
<hr />
<hr />
<hr />
<h2 id="emphasis">Emphasis</h2>
<p><strong>This is bold text</strong></p>
<p><strong>This is bold text</strong></p>
<p><em>This is italic text</em></p>
<p><em>This is italic text</em></p>
<p><del>Strikethrough</del></p>
<h2 id="blockquotes">Blockquotes</h2>
<blockquote>
<p>Blockquotes can also be nested...</p>
<blockquote>
<p>...by using additional greater-than signs right next to each other...</p>
<blockquote>
<p>...or with spaces between arrows.</p>
</blockquote>
</blockquote>
</blockquote>
<h2 id="lists">Lists</h2>
<p>Unordered</p>
<ul>
<li>Create a list by starting a line with <code>+</code>, <code>-</code>, or <code>*</code></li>
<li>Sub-lists are made by indenting 2 spaces:
<ul>
<li>Marker character change forces new list start:
<ul>
<li>Ac tristique libero volutpat at</li>
</ul>
<ul>
<li>Facilisis in pretium nisl aliquet</li>
</ul>
<ul>
<li>Nulla volutpat aliquam velit</li>
</ul>
</li>
</ul>
</li>
<li>Very easy!</li>
</ul>
<p>Ordered</p>
<ol>
<li>
<p>Lorem ipsum dolor sit amet</p>
</li>
<li>
<p>Consectetur adipiscing elit</p>
</li>
<li>
<p>Integer molestie lorem at massa</p>
</li>
<li>
<p>You can use sequential numbers...</p>
</li>
<li>
<p>...or keep all the numbers as <code>1.</code></p>
</li>
</ol>
<p>Start numbering with offset:</p>
<ol start="57">
<li>foo</li>
<li>bar</li>
</ol>
<h2 id="code">Code</h2>
<p>Inline <code>code</code></p>
<p>Indented code</p>
<pre><code>&#x2F;&#x2F; Some comments
line 1 of code
line 2 of code
line 3 of code
</code></pre>
<p>Block code &quot;fences&quot;</p>
<pre><code>Sample text here...
</code></pre>
<p>Syntax highlighting</p>
<pre data-lang="js" class="language-js "><code class="language-js" data-lang="js">var foo = function (bar) {
return bar++;
};
console.log(foo(5));
</code></pre>
<h2 id="shortcodes">Shortcodes</h2>
<h2 id="tables">Tables</h2>
<table><thead><tr><th>Option</th><th>Description</th></tr></thead><tbody>
<tr><td>data</td><td>path to data files to supply the data that will be passed into templates.</td></tr>
<tr><td>engine</td><td>engine to be used for processing templates. Handlebars is the default.</td></tr>
<tr><td>ext</td><td>extension to be used for dest files.</td></tr>
</tbody></table>
<p>Right aligned columns</p>
<table><thead><tr><th align="right">Option</th><th align="right">Description</th></tr></thead><tbody>
<tr><td align="right">data</td><td align="right">path to data files to supply the data that will be passed into templates.</td></tr>
<tr><td align="right">engine</td><td align="right">engine to be used for processing templates. Handlebars is the default.</td></tr>
<tr><td align="right">ext</td><td align="right">extension to be used for dest files.</td></tr>
</tbody></table>
<h2 id="links">Links</h2>
<p><a href="http://duckduckgo.com">link text</a></p>
<p><a href="http://duckduckgo.com/" title="Duck duck go">link with title</a></p>
<h2 id="images">Images</h2>
<p><img src="https://octodex.github.com/images/minion.png" alt="Minion" />
<img src="https://octodex.github.com/images/stormtroopocat.jpg" alt="Stormtroopocat" title="The Stormtroopocat" /></p>
<p>Like links, Images also have a footnote style syntax</p>
<p><img src="https://octodex.github.com/images/dojocat.jpg" alt="Alt text" title="The Dojocat" /></p>
<p>With a reference later in the document defining the URL location:</p>
<h2 id="smileys">Smileys</h2>
<p>Like :smile:, :cry:</p>
<h3 id="footnotes">Footnotes</h3>
<p>Footnote 1 link<sup class="footnote-reference"><a href="#first">1</a></sup>.</p>
<p>Footnote 2 link<sup class="footnote-reference"><a href="#second">2</a></sup>.</p>
<p>Duplicated footnote reference<sup class="footnote-reference"><a href="#second">2</a></sup>.</p>
<div class="footnote-definition" id="first"><sup class="footnote-definition-label">1</sup>
<p>Footnote <strong>can have markup</strong>
and multiple paragraphs.</p>
</div>
<div class="footnote-definition" id="second"><sup class="footnote-definition-label">2</sup>
<p>Footnote text.</p>
</div>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 127
expression: body
---
<h1 id="hello">Hello (in en)</h1>

View file

@ -0,0 +1,26 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 89
expression: body
---
<h1 id="Hello">Hello</h1>
<h1 id="Hello-1">Hello</h1>
<h1 id="L'écologie_et_vous">L'écologie et vous</h1>
<h1 id="hello">Hello</h1>
<h1 id="hello">Hello</h1>
<h1 id="Something_else">Hello</h1>
<h1 id="Workaround_for_literal_{#…}">Workaround for literal {#…}</h1>
<h1 id="Auto_{#matic}">Auto {#<em>matic</em>}</h1>
<h1 id=""></h1>
<h1 id="-1"></h1>
<h1 id="About"><a href="https://getzola.org/about/">About</a></h1>
<h1 id="Rust"><a href="https://rust-lang.org" title="Rust homepage">Rust</a></h1>
<h1 id="hi"><code>hi</code></h1>
<h1 id="hi-1"><em>hi</em></h1>
<h1 id="hi-2"><strong>hi</strong></h1>
<h1 id="text__there">text <sup class="footnote-reference"><a href="#1">1</a></sup> there</h1>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p>footnote</p>
</div>

View file

@ -0,0 +1,26 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 84
expression: body
---
<h1 id="hello-1">Hello</h1>
<h1 id="hello-2">Hello</h1>
<h1 id="l-ecologie-et-vous">L'écologie et vous</h1>
<h1 id="hello">Hello</h1>
<h1 id="hello">Hello</h1>
<h1 id="Something_else">Hello</h1>
<h1 id="workaround-for-literal">Workaround for literal {#…}</h1>
<h1 id="auto-matic">Auto {#<em>matic</em>}</h1>
<h1 id=""></h1>
<h1 id="-1"></h1>
<h1 id="about"><a href="https://getzola.org/about/">About</a></h1>
<h1 id="rust"><a href="https://rust-lang.org" title="Rust homepage">Rust</a></h1>
<h1 id="hi"><code>hi</code></h1>
<h1 id="hi-1"><em>hi</em></h1>
<h1 id="hi-2"><strong>hi</strong></h1>
<h1 id="text-there">text <sup class="footnote-reference"><a href="#1">1</a></sup> there</h1>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p>footnote</p>
</div>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 108
expression: body
---
<h1 id="hello">Hello<a class="zola-anchor" href="#hello" aria-label="Anchor link for: hello">🔗</a></h1>
<h1 id="world">World<a class="zola-anchor" href="#world" aria-label="Anchor link for: world">🔗</a></h1>
<h1 id="hello-1">Hello!<a class="zola-anchor" href="#hello-1" aria-label="Anchor link for: hello-1">🔗</a></h1>
<h2 id="rust"><a href="https://rust-lang.org">Rust</a><a class="zola-anchor" href="#rust" aria-label="Anchor link for: rust">🔗</a></h2>
<h1 id="hello-2">Hello*_()<a class="zola-anchor" href="#hello-2" aria-label="Anchor link for: hello-2">🔗</a></h1>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 105
expression: body
---
<h1 id="hello"><a class="zola-anchor" href="#hello" aria-label="Anchor link for: hello">🔗</a>Hello</h1>
<h1 id="world"><a class="zola-anchor" href="#world" aria-label="Anchor link for: world">🔗</a>World</h1>
<h1 id="hello-1"><a class="zola-anchor" href="#hello-1" aria-label="Anchor link for: hello-1">🔗</a>Hello!</h1>
<h2 id="rust"><a class="zola-anchor" href="#rust" aria-label="Anchor link for: rust">🔗</a><a href="https://rust-lang.org">Rust</a></h2>
<h1 id="hello-2"><a class="zola-anchor" href="#hello-2" aria-label="Anchor link for: hello-2">🔗</a>Hello*_()</h1>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 43
expression: body
---
<p><a href="https://getzola.org/about/">rel link</a>
<a href="https://getzola.org/about/#cv">rel link with anchor</a>
<a href="https://getzola.org/about/">abs link</a></p>

View file

@ -0,0 +1,15 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 29
expression: body
---
<p>Hello world</p>
<h1 id="hello-world">Hello world</h1>
<p>Hello <em>world</em>
Hello
world
Non rendered emoji :smile:
<a href="image.jpg">a link</a>
<img src="image.jpg" alt="alt text" /></p>
<h1>some html</h1>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 149
expression: body
---
<p><a rel="noopener" target="_blank" href="https://google.com">https://google.com</a></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 155
expression: body
---
<p><a rel="nofollow" href="https://google.com">https://google.com</a></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 161
expression: body
---
<p><a rel="noreferrer" href="https://google.com">https://google.com</a></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 168
expression: body
---
<p><a rel="noopener nofollow noreferrer" target="_blank" href="https://google.com">https://google.com</a></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 144
expression: body
---
<p><a href="https://google.com">https://google.com</a></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 135
expression: body
---
<p>This is “it”…</p>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/markdown.rs
assertion_line: 194
expression: body
---
<p><a href="xmpp:foo@bar.tld">foo@bar.tld</a></p>
<p><a href="tel:+11234567890">(123) 456-7890</a></p>
<p><a href="about:blank">blank page</a></p>

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 161
expression: body
---
<pre>Hello
Zola
!</pre>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 75
expression: body
---
<p>hello in en</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 63
expression: body
---
<p><img src="cover.en.png" alt="Book cover in en" /></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 50
expression: body
---
<p>hello in en</p>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 184
expression: body
---
<p>Hello</p>
<h1 id="passing-through">Passing through</h1>
<p><em>to</em> <strong>the</strong> document</p>

View file

@ -0,0 +1,9 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 76
expression: body
---
<quote>This is a quote</quote>
<p>Here is another paragraph.</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 222
expression: body
---
<!-- <img src='https://placekitten.com/200/300' alt='something'></img> -->

View file

@ -0,0 +1,18 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 343
expression: body
---
<ul>
<li>a</li>
<li>b
<div>
Hello World!
</div></li>
<li>c
<div>
Hello World!
</div></li>
</ul>

View file

@ -0,0 +1,9 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 371
expression: body
---
<div><pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>some code;
</span></code></pre>
</div>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 326
expression: body
---
<p><div>
Hello World!
</div> <div>
Hello World!
</div></p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 52
expression: body
---
<p>hello shortcode-id</p>
<quote>A quote</quote>shortcode-id2shortcode-id3

View file

@ -0,0 +1,9 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 92
expression: body
---
<quote>This is a quote</quote><quote>This is a quote</quote>
<p>Here is another paragraph.</p>

View file

@ -0,0 +1,7 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 312
expression: body
---
[multi, ple, lines]

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 385
expression: body
---
<blockquote>
<p>test quote
<img src='https://placekitten.com/200/300' alt='a quote'></img></p>
</blockquote>

View file

@ -0,0 +1,7 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 198
expression: body
---
<img src='https://placekitten.com/200/300' alt='something'></img>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 104
expression: body
---
<p>{{ youtube(id=&quot;w7Ft2ymGmfc&quot;) }}</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 140
expression: body
---
no highlight
or there

View file

@ -0,0 +1,7 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 293
expression: body
---
<p>2 1 3</p>

View file

@ -0,0 +1,7 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 293
expression: body
---
<p>\n2\n</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 293
expression: body
---
<p><span>2</span>\n<strong>The Book</strong> 2</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 293
expression: body
---
<p>a.2 b.1 c.3</p>

View file

@ -0,0 +1,8 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 293
expression: body
---
<p>2 1 3</p>

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 254
expression: body
---
<p><p>a: 1</p>
<p>b: 1</p>
<p>a: 2</p>
<p>b: 2</p></p>

View file

@ -0,0 +1,11 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 274
expression: body
---
<p>ttest1</p>
<p>123</p>
<p>ttest2</p>
<p>123</p>

View file

@ -0,0 +1,10 @@
---
source: components/rendering/tests/shortcodes.rs
assertion_line: 362
expression: body
---
<bc-authorizer-example><code>some code;
more code;
other code here;</code></bc-authorizer-example>

View file

@ -0,0 +1,13 @@
---
source: components/rendering/tests/summary.rs
assertion_line: 24
expression: body
---
<p>Hello world!</p>
<h1 id="introduction">Introduction</h1>
<ul>
<li>first</li>
<li>second</li>
</ul>

View file

@ -0,0 +1,12 @@
---
source: components/rendering/tests/summary.rs
assertion_line: 41
expression: body
---
<p><p>a: 1</p> <p>a: 2</p>
<div><h1 id="hello-world">Hello world</h1>
</div></p>
<pre><code>some code;
</code></pre>

View file

@ -1,502 +0,0 @@
mod common;
use common::ShortCode;
use libs::tera;
use std::path::PathBuf;
use templates::ZOLA_TERA;
macro_rules! test_scenario {
($in_str:literal, $out_str:literal, [$($shortcodes:ident),*]) => {
let config = config::Config::default_for_test();
#[allow(unused_mut)]
let mut tera = tera::Tera::default();
tera.extend(&ZOLA_TERA).unwrap();
$(
let ShortCode { name, is_md, output } = $shortcodes;
tera.add_raw_template(
&format!("shortcodes/{}.{}", name, if is_md { "md" } else { "html" }),
&output,
).unwrap();
)*
let mut permalinks = std::collections::HashMap::new();
permalinks.insert("".to_string(), "".to_string());
tera.register_filter(
"markdown",
templates::filters::MarkdownFilter::new(
PathBuf::new(),
config.clone(),
permalinks.clone(),
).unwrap()
);
let mut context = rendering::RenderContext::new(
&tera,
&config,
&config.default_language,
"",
&permalinks,
front_matter::InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&tera);
context.set_shortcode_definitions(&shortcode_def);
let rendered = rendering::render_content($in_str, &context);
println!("{:?}", rendered);
assert!(rendered.is_ok());
let rendered = rendered.unwrap();
assert_eq!(rendered.body, $out_str.to_string());
}
}
#[test]
fn plain_text() {
// Test basic formation of text and paragraphs tags
// - Plain sentences (Long and broken up)
// - Multiple paragraphs
test_scenario!("Hello World!", "<p>Hello World!</p>\n", []);
test_scenario!("Hello\nWorld!", "<p>Hello\nWorld!</p>\n", []);
test_scenario!("Hello\n\nWorld!", "<p>Hello</p>\n<p>World!</p>\n", []);
test_scenario!("Hello\n\nWorld\n\n!", "<p>Hello</p>\n<p>World</p>\n<p>!</p>\n", []);
}
#[test]
fn header() {
// Test basic header ids
// - Plain headers
// - Headers with text
test_scenario!("# Header1", "<h1 id=\"header1\">Header1</h1>\n", []);
test_scenario!(
"## A longer string of text!",
"<h2 id=\"a-longer-string-of-text\">A longer string of text!</h2>\n",
[]
);
test_scenario!(
"# Header1\nHello World!",
"<h1 id=\"header1\">Header1</h1>\n<p>Hello World!</p>\n",
[]
);
test_scenario!(
"# Header1\n\nHello World!",
"<h1 id=\"header1\">Header1</h1>\n<p>Hello World!</p>\n",
[]
);
}
#[test]
fn code_block() {
test_scenario!("```\nWow Code!\n```", "<pre><code>Wow Code!\n</code></pre>\n", []);
test_scenario!(" Wow Code!", "<pre><code>Wow Code!</code></pre>\n", []);
}
const MD_SIMPLE: ShortCode = ShortCode::new("simple", "Hello World!", true);
const HTML_SIMPLE: ShortCode = ShortCode::new("simple", "Hello World!", false);
#[test]
fn simple_shortcodes() {
// Test both MD & HTML plain text shortcodes
test_scenario!("{{ simple() }}", "<p>Hello World!</p>\n", [MD_SIMPLE]);
test_scenario!("hey {{ simple() }}", "<p>hey Hello World!</p>\n", [HTML_SIMPLE]);
}
const MD_LINK: ShortCode = ShortCode::new("link", "[Link...](/)", true);
const HTML_LINK: ShortCode = ShortCode::new("link", "<a href=\"/\">Link...</a>", false);
#[test]
fn md_inline_shortcodes() {
// Test both MD & HTML inline shortcodes
test_scenario!(
"A read more link: {{ link() }}",
"<p>A read more link: <a href=\"/\">Link...</a></p>\n",
[MD_LINK]
);
test_scenario!(
"A read more link: {{ link() }}",
"<p>A read more link: <a href=\"/\">Link...</a></p>\n",
[HTML_LINK]
);
}
const HTML_DIV: ShortCode = ShortCode::new("dived", "<div>Hello World!</div>", false);
#[test]
fn html_div_shortcodes() {
// Test the behaviour of HTML div-ed shortcodes
test_scenario!("{{ dived() }}", "<div>Hello World!</div>", [HTML_DIV]);
test_scenario!(
"{{ dived() }} {{ dived() }}",
"<p><div>Hello World!</div> <div>Hello World!</div></p>\n",
[HTML_DIV]
);
test_scenario!(
"{{ dived() }}\n{{ dived() }}",
"<p><div>Hello World!</div>\n<div>Hello World!</div></p>\n",
[HTML_DIV]
);
test_scenario!(
"{{ dived() }}\n\n{{ dived() }}",
"<div>Hello World!</div><div>Hello World!</div>",
[HTML_DIV]
);
}
const HTML_TABS_MULTILINE: ShortCode =
ShortCode::new("multiline", "<div>\n\tHello World!\n</div>", false);
const HTML_SPACES_MULTILINE: ShortCode =
ShortCode::new("multiline", "<div>\n Hello World!\n</div>", false);
#[test]
fn html_tabs_multiline_shortcodes() {
// Test the behaviour multiline HTML shortcodes
// This can cause problems mostly because the 4 spaces sometimes used for tabs also are used
// to indicate code-blocks
test_scenario!("{{ multiline() }}", "<div>\n\tHello World!\n</div>", [HTML_TABS_MULTILINE]);
test_scenario!(
"{{ multiline() }} {{ multiline() }}",
"<p><div>\n\tHello World!\n</div> <div>\n\tHello World!\n</div></p>\n",
[HTML_TABS_MULTILINE]
);
test_scenario!(
"{{ multiline() }}\n{{ multiline() }}",
"<p><div>\n\tHello World!\n</div>\n<div>\n\tHello World!\n</div></p>\n",
[HTML_TABS_MULTILINE]
);
test_scenario!(
"{{ multiline() }}\n\n{{ multiline() }}",
"<div>\n\tHello World!\n</div><div>\n\tHello World!\n</div>",
[HTML_TABS_MULTILINE]
);
}
#[test]
fn html_spaces_multiline_shortcodes() {
// Test the behaviour multiline HTML shortcodes
// This can cause problems mostly because the 4 spaces sometimes used for tabs also are used
// to indicate code-blocks
test_scenario!("{{ multiline() }}", "<div>\n Hello World!\n</div>", [HTML_SPACES_MULTILINE]);
test_scenario!(
"{{ multiline() }} {{ multiline() }}",
"<p><div>\n Hello World!\n</div> <div>\n Hello World!\n</div></p>\n",
[HTML_SPACES_MULTILINE]
);
test_scenario!(
"{{ multiline() }}\n{{ multiline() }}",
"<p><div>\n Hello World!\n</div>\n<div>\n Hello World!\n</div></p>\n",
[HTML_SPACES_MULTILINE]
);
// a single \n would keep it in the same paragraph as above
// 2 \n would result in different paragraphs and basically ignoring the 2 \n
test_scenario!(
"{{ multiline() }}\n\n{{ multiline() }}",
"<div>\n Hello World!\n</div><div>\n Hello World!\n</div>",
[HTML_SPACES_MULTILINE]
);
}
// Related to Issue of recursive shortcodes
// const MD_OUTER: ShortCode = ShortCode::new("outer", "Hello {{ inner() }}!", true);
// const MD_INNER: ShortCode = ShortCode::new("inner", "World", true);
//
// const HTML_OUTER: ShortCode = ShortCode::new("outer", "Hello {{ inner() }}!", false);
// const HTML_INNER: ShortCode = ShortCode::new("inner", "World", false);
//
// const MD_REUSER: ShortCode = ShortCode::new("reuser", "{{ reuser() }}", true);
// const MD_REFBACK: ShortCode = ShortCode::new("refback", "{{ leveledreuser() }}", true);
// const MD_LEVELED_REUSER: ShortCode = ShortCode::new("leveledreuser", "{{ refback() }}", true);
//
// const HTML_REUSER: ShortCode = ShortCode::new("reuser", "{{ reuser() }}", false);
// const HTML_REFBACK: ShortCode = ShortCode::new("refback", "{{ leveledreuser() }}", false);
// const HTML_LEVELED_REUSER: ShortCode = ShortCode::new("leveledreuser", "{{ refback() }}", false);
//
// #[test]
// fn md_recursive_shortcodes() {
// // Test recursive shortcodes in a MD context.
// // This should always work, unless a shortcode is reused
//
// test_scenario!("{{ outer() }}", "<p>Hello World!</p>\n", [MD_OUTER, MD_INNER]);
// test_scenario!("{{ outer() }}", "<p>Hello World!</p>\n", [MD_INNER, MD_OUTER]);
// }
//
// #[test]
// fn html_recursive_shortcodes() {
// // Test recursive shortcodes in a HTML context.
// // One can add HTML shortcodes within html shortcodes, unless a shortcode is reused
//
// test_scenario!("{{ outer() }}", "<p>Hello {{ inner() }}!</p>", [HTML_OUTER, HTML_INNER]);
// test_scenario!("{{ outer() }}", "<p>Hello {{ inner() }}!</p>", [HTML_INNER, HTML_OUTER]);
// }
//
// #[test]
// fn shortcodes_recursion_stop() {
// // Test whether recursion stops if a shortcode is reused.
//
// test_scenario_fail!("{{ reuser() }}", [MD_REUSER]);
// test_scenario_fail!("{{ leveledreuser() }}", [MD_LEVELED_REUSER, MD_REFBACK]);
//
// test_scenario_fail!("{{ reuser() }}", [HTML_REUSER]);
// test_scenario_fail!("{{ leveledreuser() }}", [HTML_LEVELED_REUSER, HTML_REFBACK]);
//
// test_scenario_fail!("{{ leveledreuser() }}", [HTML_LEVELED_REUSER, MD_REFBACK]);
// test_scenario_fail!("{{ leveledreuser() }}", [MD_LEVELED_REUSER, HTML_REFBACK]);
// }
//
// #[test]
// fn html_in_md_recursive_shortcodes() {
// // Test whether we can properly add HTML shortcodes in MD shortcodes
//
// test_scenario!("{{ outer() }}", "<p>Hello World!</p>\n", [HTML_INNER, MD_OUTER]);
// test_scenario!("{{ outer() }}", "<p>Hello World!</p>\n", [MD_OUTER, HTML_INNER]);
// }
//
// #[test]
// fn md_in_html_recursive_shortcodes() {
// // Test whether we can not add MD shortcodes in HTML shortcodes
//
// test_scenario!("{{ outer() }}", "<p>Hello {{ inner() }}!</p>", [HTML_OUTER, MD_INNER]);
// test_scenario!("{{ outer() }}", "<p>Hello {{ inner() }}!</p>", [MD_INNER, HTML_OUTER]);
// }
const MD_BODY_SHORTCODE: ShortCode = ShortCode::new("bdy", "*{{ body }}*", true);
const HTML_BODY_SHORTCODE: ShortCode = ShortCode::new("bdy", "<span>{{ body }}</span>", false);
#[test]
fn md_body_shortcodes() {
// Test basic MD body shortcodes
test_scenario!("abc {% bdy() %}def{% end %}", "<p>abc <em>def</em></p>\n", [MD_BODY_SHORTCODE]);
test_scenario!(
"abc\n\n{% bdy() %}def{% end %}",
"<p>abc</p>\n<p><em>def</em></p>\n",
[MD_BODY_SHORTCODE]
);
}
#[test]
fn html_body_shortcodes() {
// Test basic HTML body shortcodes
test_scenario!(
"abc {% bdy() %}def{% end %}",
"<p>abc <span>def</span></p>\n",
[HTML_BODY_SHORTCODE]
);
// Should it wrap the shortcode in a `<p>`?
test_scenario!(
"abc\n\n{% bdy() %}def{% end %}",
"<p>abc</p>\n<span>def</span>",
[HTML_BODY_SHORTCODE]
);
}
// Related to issue #515
// #[test]
// fn shortcode_in_md_body() {
// // Test whether we can properly insert a shortcode in a MD shortcode body
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><em>Wow! Hello World!</em></p>\n",
// [MD_BODY_SHORTCODE, MD_SIMPLE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><em>Wow! Hello World!</em></p>\n",
// [MD_SIMPLE, MD_BODY_SHORTCODE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><em>Wow! Hello World!</em></p>\n",
// [MD_BODY_SHORTCODE, HTML_SIMPLE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><em>Wow! Hello World!</em></p>\n",
// [HTML_SIMPLE, MD_BODY_SHORTCODE]
// );
// }
//
// #[test]
// fn shortcode_in_html_body() {
// // Test whether we can properly insert a shortcode in a HTML shortcode body
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><span>Wow! Hello World!</span></p>\n",
// [HTML_BODY_SHORTCODE, MD_SIMPLE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><span>Wow! Hello World!</span></p>\n",
// [MD_SIMPLE, HTML_BODY_SHORTCODE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><span>Wow! Hello World!</span></p>\n",
// [HTML_BODY_SHORTCODE, HTML_SIMPLE]
// );
//
// test_scenario!(
// "{% bdy() %}Wow! {{ simple() }}{% end %}",
// "<p><span>Wow! Hello World!</span></p>\n",
// [HTML_SIMPLE, HTML_BODY_SHORTCODE]
// );
// }
const MD_ARG_SHORTCODE: ShortCode = ShortCode::new(
"argeater",
"{{ s }}\n{{ b }}\n{{ f }}\n{{ i }}\n{{ array | join(sep=' // ') | safe }}",
true,
);
const HTML_ARG_SHORTCODE: ShortCode = ShortCode::new(
"argeater",
"{{ s }}\n{{ b }}\n{{ f }}\n{{ i }}\n{{ array | join(sep=' // ') | safe }}",
false,
);
#[test]
fn shortcode_arguments() {
// Test for properly inserting all shortcodes
test_scenario!(
"{{ argeater(s='Hello World!', b=true, f=3.1415, i=42, array=[1, 3, 3, 7]) }}",
"<p>Hello World!\ntrue\n3.1415\n42\n1 // 3 // 3 // 7</p>\n",
[MD_ARG_SHORTCODE]
);
test_scenario!(
"{{ argeater(s='Hello World!', b=true, f=3.1415, i=42, array=[1, 3, 3, 7]) }}",
"Hello World!\ntrue\n3.1415\n42\n1 // 3 // 3 // 7",
[HTML_ARG_SHORTCODE]
);
}
// const MD_BDY_OUTER: ShortCode = ShortCode::new("outer", "*{{ body }}*", true);
// const MD_BDY_INNER: ShortCode = ShortCode::new("inner", "**{{ body }}**", true);
// Originally from PR #1475
// #[test]
// fn body_in_body() {
// test_scenario!(
// "{% outer() %}\n\tTest text\n\t{% inner() %}\n\t\tHello World!\n\t{% end %}\n{% end %}",
// "<p><em>Test text <b>Hello World!</b></em></p>\n",
// [MD_BDY_OUTER, MD_BDY_INNER]
// );
// }
// https://github.com/getzola/zola/issues/1355
#[test]
fn list_with_shortcode() {
test_scenario!(
"* a\n* b\n\t{{ multiline() }}\n*c\n\t{{ multiline() }}\n",
"<ul>\n<li>a</li>\n<li>b\n<div>\n\tHello World!\n</div>\n*c\n<div>\n\tHello World!\n</div></li>\n</ul>\n",
[HTML_TABS_MULTILINE]
);
}
const WEB_COMPONENT_SHORTCODE: ShortCode = ShortCode::new(
"examplecode",
"<bc-authorizer-example>
<code>{{ body | safe}}</code>
</bc-authorizer-example>",
false,
);
// https://github.com/getzola/zola/issues/1655
#[test]
fn shortcodes_do_not_generate_paragraphs() {
test_scenario!(
r#"{% examplecode() %}
some code;
more code;
other code here;
{% end %}"#,
"<bc-authorizer-example>\n <code>some code;\nmore code;\n\nother code here;</code>\n</bc-authorizer-example>",
[WEB_COMPONENT_SHORTCODE]
);
}
const CODE_BLOCK_SHORTCODE: ShortCode = ShortCode::new(
"details",
r#"<details>
<summary>{{summary | markdown(inline=true) | safe}}</summary>
<div class="details-content">
{{ body | markdown | safe}}
</div>
</details>"#,
false,
);
// https://github.com/getzola/zola/issues/1601
#[test]
fn works_with_code_block_in_shortcode() {
test_scenario!(
r#"{% details(summary="hey") %}
```
some code
```
{% end %}"#,
"<details>\n<summary>hey</summary>\n<div class=\"details-content\">\n<pre><code>some code\n</code></pre>\n\n</div>\n</details>",
[CODE_BLOCK_SHORTCODE]
);
}
// https://github.com/getzola/zola/issues/1600
#[test]
fn shortcodes_work_in_quotes() {
test_scenario!(
"> test quote\n> {{ vimeo(id=\"124313553\") }}\n> test quote",
"<blockquote>\n<p>test quote\n<div >\n <iframe src=\"//player.vimeo.com/video/124313553\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>\n</div>\n\ntest quote</p>\n</blockquote>\n",
[]
);
}
const GOOGLE_SHORTCODE: ShortCode = ShortCode::new(
"google",
r#"<div>
<a href="https://google.com/search?q={{query}}">Google Search</a>
</div>"#,
false,
);
// https://github.com/getzola/zola/issues/1500
#[test]
fn can_handle_issue_1500() {
test_scenario!(
r#"foo {{ google(query="apple") }} bar."#,
"<p>foo <div>\n<a href=\"https://google.com/search?q=apple\">Google Search</a>\n</div> bar.</p>\n",
[GOOGLE_SHORTCODE]
);
}

View file

@ -1,119 +1,47 @@
mod common;
use common::ShortCode;
use libs::tera;
macro_rules! test_scenario_summary {
($in_str:literal, $summary:literal, [$($shortcodes:ident),*]) => {
let config = config::Config::default_for_test();
#[allow(unused_mut)]
let mut tera = tera::Tera::default();
// Add all shortcodes
$(
tera.add_raw_template(
&format!("shortcodes/{}", $shortcodes.filename()),
$shortcodes.output
).expect("Failed to add raw template");
)*
let permalinks = std::collections::HashMap::new();
let mut context = rendering::RenderContext::new(
&tera,
&config,
&config.default_language,
"",
&permalinks,
front_matter::InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&tera);
context.set_shortcode_definitions(&shortcode_def);
let rendered = rendering::render_content($in_str, &context);
assert!(rendered.is_ok());
let rendered = rendered.unwrap();
assert!(rendered.summary_len.is_some());
let summary_len = rendered.summary_len.unwrap();
assert_eq!(&rendered.body[..summary_len], $summary);
}
fn get_summary(content: &str) -> String {
let rendered = common::render(content).unwrap();
assert!(rendered.summary_len.is_some());
let summary_len = rendered.summary_len.unwrap();
rendered.body[..summary_len].to_owned()
}
#[test]
fn basic_summary() {
test_scenario_summary!("Hello World!\n<!-- more -->\nAnd others!", "<p>Hello World!</p>\n", []);
test_scenario_summary!(
"Hello World!\n\nWow!\n<!-- more -->\nAnd others!",
"<p>Hello World!</p>\n<p>Wow!</p>\n",
[]
let body = get_summary(
r#"
Hello world!
# Introduction
- first
- second
<!-- more -->
And some content after
"#,
);
insta::assert_snapshot!(body);
}
// https://zola.discourse.group/t/zola-12-issue-with-continue-reading/590/7
#[test]
fn summary_with_headers() {
test_scenario_summary!(
"# Hello World!\n<!-- more -->\nAnd others!",
"<h1 id=\"hello-world\">Hello World!</h1>\n",
[]
);
test_scenario_summary!(
"# Hello World!\n\nWow!\n<!-- more -->\nAnd others!",
"<h1 id=\"hello-world\">Hello World!</h1>\n<p>Wow!</p>\n",
[]
fn summary_with_shortcodes() {
let body = get_summary(
r#"
{{ a() }} {{ a() }}
{% render_md() %}
# Hello world
{% end %}
```
some code;
```
<!-- more -->
And some content after
"#,
);
insta::assert_snapshot!(body);
}
const MD_SIMPLE: ShortCode =
ShortCode::new("simple", "A lot of text to insert into the document", true);
const HTML_SIMPLE: ShortCode =
ShortCode::new("simple", "A lot of text to insert into the document", true);
#[test]
fn summary_with_md_shortcodes() {
test_scenario_summary!(
"{{ simple() }}\n<!-- more -->\nAnd others!",
"<p>A lot of text to insert into the document</p>\n",
[MD_SIMPLE]
);
test_scenario_summary!(
"{{ simple() }}\n\nWow!\n<!-- more -->\nAnd others!",
"<p>A lot of text to insert into the document</p>\n<p>Wow!</p>\n",
[MD_SIMPLE]
);
}
#[test]
fn summary_with_html_shortcodes() {
test_scenario_summary!(
"{{ simple() }}\n<!-- more -->\nAnd others!",
"<p>A lot of text to insert into the document</p>\n",
[HTML_SIMPLE]
);
test_scenario_summary!(
"{{ simple() }}\n\nWow!\n<!-- more -->\nAnd others!",
"<p>A lot of text to insert into the document</p>\n<p>Wow!</p>\n",
[HTML_SIMPLE]
);
}
// const INNER: ShortCode = ShortCode::new("inner", "World", false);
//
// const MD_RECURSIVE: ShortCode = ShortCode::new("outer", "Hello {{ inner() }}!", true);
// const HTML_RECURSIVE: ShortCode = ShortCode::new("outer", "Hello {{ inner() }}!", false);
//
// #[test]
// fn summary_with_recursive_shortcodes() {
// test_scenario_summary!(
// "{{ outer() }}\n<!-- more -->\nAnd others!",
// "<p>Hello World!</p>\n",
// [MD_RECURSIVE, INNER]
// );
//
// test_scenario_summary!(
// "{{ outer() }}\n<!-- more -->\nAnd others!",
// "<p>Hello World!</p>\n",
// [HTML_RECURSIVE, INNER]
// );
// }

View file

@ -1,112 +1,77 @@
mod common;
use libs::tera;
use rendering::Heading;
#[test]
fn can_make_simple_toc() {
let res = common::render(
r#"
# Heading 1
#[derive(PartialEq, Debug)]
struct HelperHeader {
title: String,
children: Vec<HelperHeader>,
}
## Heading 2
impl PartialEq<Heading> for HelperHeader {
fn eq(&self, other: &Heading) -> bool {
self.title == other.title && self.children == other.children
}
}
## Another Heading 2
macro_rules! hh {
($title:literal, [$($children:expr),*]) => {{
HelperHeader {
title: $title.to_string(),
children: vec![$($children),*],
}
}}
}
### Last one
"#,
)
.unwrap();
macro_rules! test_toc {
($in_str:literal, $toc:expr, [$($shortcodes:ident),*]) => {
let config = config::Config::default_for_test();
#[allow(unused_mut)]
let mut tera = tera::Tera::default();
// Add all shortcodes
$(
tera.add_raw_template(
&format!("shortcodes/{}", $shortcodes.filename()),
$shortcodes.output
).expect("Failed to add raw template");
)*
let permalinks = std::collections::HashMap::new();
let mut context = rendering::RenderContext::new(
&tera,
&config,
&config.default_language,
"",
&permalinks,
front_matter::InsertAnchor::None,
);
let shortcode_def = utils::templates::get_shortcodes(&tera);
context.set_shortcode_definitions(&shortcode_def);
let rendered = rendering::render_content($in_str, &context);
assert!(rendered.is_ok());
let rendered = rendered.unwrap();
let toc = rendered.toc.clone();
assert!($toc == toc);
}
let toc = res.toc;
assert_eq!(toc.len(), 1);
assert_eq!(toc[0].children.len(), 2);
assert_eq!(toc[0].children[1].children.len(), 1);
}
#[test]
fn basic_toc() {
test_toc!("Hello World!", <Vec<HelperHeader>>::new(), []);
test_toc!("# ABC\n## DEF", vec![hh!("ABC", [hh!("DEF", [])])], []);
fn can_ignore_tags_in_toc() {
let res = common::render(
r#"
## heading with `code`
## [anchor](https://duckduckgo.com/) in heading
## **bold** and *italics*
"#,
)
.unwrap();
let toc = res.toc;
assert_eq!(toc.len(), 3);
assert_eq!(toc[0].id, "heading-with-code");
assert_eq!(toc[0].title, "heading with code");
assert_eq!(toc[1].id, "anchor-in-heading");
assert_eq!(toc[1].title, "anchor in heading");
assert_eq!(toc[2].id, "bold-and-italics");
assert_eq!(toc[2].title, "bold and italics");
}
#[test]
fn all_layers() {
test_toc!(
"# A\n## B\n### C\n#### D\n##### E\n###### F\n",
vec![hh!("A", [hh!("B", [hh!("C", [hh!("D", [hh!("E", [hh!("F", [])])])])])])],
[]
);
}
fn can_make_toc_all_levels() {
let res = common::render(
r#"
# A
#[test]
fn multiple_on_layer() {
test_toc!(
"# A\n## B\n## C\n### D\n## E\n### F\n",
vec![hh!("A", [hh!("B", []), hh!("C", [hh!("D", [])]), hh!("E", [hh!("F", [])])])],
[]
);
}
## B1
// const MD_SIMPLE1: ShortCode = ShortCode::new("simple", "Hello World!", true);
// const MD_SIMPLE2: ShortCode = ShortCode::new("simple2", "Wow, much cool!", true);
//
// #[test]
// fn with_shortcode_titles() {
// test_toc!(
// "# {{ simple() }}\n## {{ simple2() }}\n### ABC\n#### {{ simple() }}\n",
// vec![hh!(
// "Hello World!",
// [hh!("Wow, much cool!", [hh!("ABC", [hh!("Hello World!", [])])])]
// )],
// [MD_SIMPLE1, MD_SIMPLE2]
// );
// }
//
// const MD_MULTILINE: ShortCode = ShortCode::new("multiline", "<div>\n Wow!\n</div>", false);
//
// #[test]
// fn with_multiline_shortcodes() {
// test_toc!(
// "# {{ multiline() }}\n{{ multiline() }}\n## {{ multiline()() }}\n",
// vec![hh!("Wow!", [hh!("Wow!", [])])],
// [MD_MULTILINE]
// );
// }
## B2
### C
#### D
##### E
###### F
"#,
)
.unwrap();
let toc = res.toc;
assert_eq!(toc.len(), 1);
assert_eq!(toc[0].children.len(), 2);
assert_eq!(toc[0].children[1].children.len(), 1);
assert_eq!(toc[0].children[1].children[0].children.len(), 1);
assert_eq!(toc[0].children[1].children[0].children[0].children.len(), 1);
}

View file

@ -51,14 +51,18 @@ pub fn check_internal_links_with_anchors(site: &Site) -> Result<()> {
// as well as any other sring containing "_index." which is now referenced as
// unsupported page path in the docs.
if md_path.contains("_index.") {
let section = library
.get_section(&full_path)
.expect(&format!("Couldn't find section {} in check_internal_links_with_anchors from page {:?}", md_path, page.strip_prefix(&site.base_path).unwrap()));
let section = library.get_section(&full_path).expect(&format!(
"Couldn't find section {} in check_internal_links_with_anchors from page {:?}",
md_path,
page.strip_prefix(&site.base_path).unwrap()
));
!section.has_anchor(anchor)
} else {
let page = library
.get_page(&full_path)
.expect(&format!("Couldn't find page {} in check_internal_links_with_anchors from page {:?}", md_path, page.strip_prefix(&site.base_path).unwrap()));
let page = library.get_page(&full_path).expect(&format!(
"Couldn't find page {} in check_internal_links_with_anchors from page {:?}",
md_path,
page.strip_prefix(&site.base_path).unwrap()
));
!(page.has_anchor(anchor) || page.has_anchor_id(anchor))
}

View file

@ -13,8 +13,9 @@ mod prompt;
fn main() {
let cli = Cli::parse();
let cli_dir: PathBuf =
cli.root.canonicalize().unwrap_or_else(|_| panic!("Could not find canonical path of root dir: {}", cli.root.display()));
let cli_dir: PathBuf = cli.root.canonicalize().unwrap_or_else(|_| {
panic!("Could not find canonical path of root dir: {}", cli.root.display())
});
let root_dir = cli_dir
.ancestors()