diff --git a/Cargo.lock b/Cargo.lock index eac063a..d355fc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] name = "async-recursion" @@ -51,18 +51,18 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -74,7 +74,7 @@ dependencies = [ "attribute-derive-macro", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -90,7 +90,7 @@ dependencies = [ "proc-macro2", "quote", "quote-use", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -392,13 +392,13 @@ dependencies = [ [[package]] name = "derive-where" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d9b1fc2a6d7e19c89e706a3769e31ee862ac7a4c810c7c0ff3910e1a42a4ce" +checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -502,9 +502,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -517,9 +517,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -527,15 +527,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -544,38 +544,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -735,9 +735,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -750,7 +750,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -791,9 +791,9 @@ checksum = "71dd52191aae121e8611f1e8dc3e324dd0dd1dee1e6dd91d10ee07a3cfb4d9d8" [[package]] name = "inventory" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0508c56cfe9bfd5dfeb0c22ab9a6abfda2f27bdca422132e494266351ed8d83c" +checksum = "c8573b2b1fb643a372c73b23f4da5f888677feef3305146d68a539250a9bccc7" [[package]] name = "ipnet" @@ -940,7 +940,7 @@ dependencies = [ "quote", "rstml", "serde", - "syn 2.0.39", + "syn 2.0.43", "walkdir", ] @@ -962,7 +962,7 @@ dependencies = [ "quote", "rstml", "server_fn_macro", - "syn 2.0.39", + "syn 2.0.43", "tracing", "uuid", ] @@ -1012,9 +1012,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "line-wrap" @@ -1056,7 +1056,7 @@ dependencies = [ "manyhow-macros", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1159,9 +1159,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1236,7 +1236,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1278,7 +1278,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1317,9 +1317,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" dependencies = [ "unicode-ident", ] @@ -1332,7 +1332,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", "version_check", "yansi", ] @@ -1402,7 +1402,7 @@ checksum = "a7b5abe3fe82fdeeb93f44d66a7b444dedf2e4827defb0a8e69c437b2de2ef94" dependencies = [ "quote", "quote-use-macros", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1414,7 +1414,7 @@ dependencies = [ "derive-where", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1478,9 +1478,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ "base64", "bytes", @@ -1513,12 +1513,13 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.42" +version = "0.7.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" +checksum = "527a97cdfef66f65998b5f3b637c26f5a5ec09cc52a3f9932313ac645f4190f5" dependencies = [ "bitvec", "bytecheck", + "bytes", "hashbrown 0.12.3", "ptr_meta", "rend", @@ -1530,9 +1531,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.42" +version = "0.7.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2e06b915b5c230a17d7a736d1e2e63ee753c256a8614ef3f5147b13a4f5541d" +checksum = "b5c462a1328c8e67e4d6dbad1eb0355dd43e8ab432c6e227a43657f16ade5033" dependencies = [ "proc-macro2", "quote", @@ -1548,7 +1549,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.39", + "syn 2.0.43", "syn_derive", "thiserror", ] @@ -1556,7 +1557,7 @@ dependencies = [ [[package]] name = "rust-web-markdown" version = "0.2.0" -source = "git+https://github.com/rambip/rust-web-markdown/#a07868234f2d34999011c5ef53399312d23830da" +source = "git+https://github.com/rambip/rust-web-markdown/#fe1d029df23169f283a00530b77065d0299736bd" dependencies = [ "katex", "lazy_static", @@ -1579,9 +1580,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "safemem" @@ -1612,9 +1613,9 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "self_cell" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e388332cd64eb80cd595a00941baf513caffae8dce9cfd0467fc9c66397dade6" +checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" [[package]] name = "serde" @@ -1644,7 +1645,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1700,7 +1701,7 @@ dependencies = [ "serde_json", "serde_qs", "server_fn_macro_default", - "syn 2.0.39", + "syn 2.0.43", "thiserror", "xxhash-rust", ] @@ -1716,7 +1717,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.39", + "syn 2.0.43", "xxhash-rust", ] @@ -1727,7 +1728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7256ba61dfadb220598db418376e7bc2a34b96df36c4dc48f24ffe161810fc0b" dependencies = [ "server_fn_macro", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1761,16 +1762,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -1800,9 +1791,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", @@ -1818,7 +1809,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -1871,29 +1862,29 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -1911,9 +1902,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] @@ -1935,16 +1926,16 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", "libc", "mio", "pin-project-lite", - "socket2 0.5.5", + "socket2", "windows-sys", ] @@ -1996,7 +1987,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -2031,7 +2022,7 @@ checksum = "982ee4197351b5c9782847ef5ec1fdcaf50503fb19d68f9771adae314e72b492" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", ] [[package]] @@ -2160,7 +2151,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", "wasm-bindgen-shared", ] @@ -2194,7 +2185,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.43", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2344,9 +2335,9 @@ dependencies = [ [[package]] name = "xxhash-rust" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9828b178da53440fa9c766a3d2f73f7cf5d0ac1fe3980c1e5018d899fd19e07b" +checksum = "53be06678ed9e83edb1745eb72efc0bbcd7b5c3c35711a860906aed827a13d61" [[package]] name = "yaml-rust" diff --git a/examples/custom_component/index.html b/examples/custom_component/index.html index d25acbc..187fa14 100644 --- a/examples/custom_component/index.html +++ b/examples/custom_component/index.html @@ -1,6 +1,9 @@ + custom components in markdown + + diff --git a/examples/custom_component/markdown.css b/examples/custom_component/markdown.css new file mode 100644 index 0000000..bf80ab9 --- /dev/null +++ b/examples/custom_component/markdown.css @@ -0,0 +1,28 @@ + blockquote { + margin: 5px; border-left: 5px solid grey; + padding: 5px; + } + + blockquote p { + margin: 5px + } + + ul { + list-style-type:disc + } + + table { + border: 1px solid black; border-collapse: collapse + } + + td { + border: 1px solid grey; padding: 5px + } + + thead { + background-color: #eee; font-weight: bold; + } + +span.markdown-error { + background-color: red; +} diff --git a/examples/custom_component/src/main.rs b/examples/custom_component/src/main.rs index 9b7bcc3..5968b98 100644 --- a/examples/custom_component/src/main.rs +++ b/examples/custom_component/src/main.rs @@ -1,7 +1,13 @@ use leptos::*; use leptos_markdown::*; -use std::collections::BTreeMap; +// macro_rules! dbg { +// ($var:expr) => {{ +// let x = $var; +// leptos::logging::log!("{:?}", x); +// x +// }} +// } #[component] @@ -24,7 +30,7 @@ pub fn SimpleCounter(initial_value: i32) -> impl IntoView { "Value: " {value} "!" - }.into_any() + } } #[component] @@ -36,26 +42,11 @@ fn BlueBox(children: Children) -> impl IntoView { } } -static MARKDOWN: &'static str = r#" -# The source -```md +static MARKDOWN_SOURCE: &'static str = r#" ## Here is a counter: -## Here is a Box: - - -**I am in a blue box !** - - -``` - ---- - -# The result - -## Here is a counter: - + ## Here is a Box: @@ -66,27 +57,31 @@ static MARKDOWN: &'static str = r#" "#; #[component] -fn App( - ) -> impl IntoView { - let mut components = BTreeMap::new(); - - components.insert("Counter", Callback::new( - |props: MdComponentProps| view!{ - - }.into_view())); - - components.insert("box", Callback::new( - |props: MdComponentProps| view!{ - - {props.children} - - }.into_view() - )); +fn App() -> impl IntoView { + let mut components = CustomComponents::new(); + + components.register("Counter", + |props| Ok(view!{ + + }) + ); + + components.register("box", + |props| Ok(view!{ + {props.children} + }) + ); view!{ +

"The source"

+ +
+

"The result"

} } diff --git a/src/lib.rs b/src/lib.rs index 644d614..432bd2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,13 @@ use rust_web_markdown::{ render_markdown, ElementAttributes, HtmlElement, Context, - MdComponentProps as VMdComponentProps, - CowStr + CowStr, + MarkdownProps }; -pub type MdComponentProps = VMdComponentProps; +pub type MdComponentProps = rust_web_markdown::MdComponentProps; pub use rust_web_markdown::{ - LinkDescription, Options, + LinkDescription, Options, ComponentCreationError }; use web_sys::MouseEvent; @@ -38,33 +38,55 @@ pub struct MarkdownMouseEvent { // pub tag: pulldown_cmark::Tag<'a>, } + +/// component store. +/// It is called when therer is a `` inside the markdown source. +/// It is basically a hashmap but more efficient for a small number of items +pub struct CustomComponents(BTreeMap<&'static str, + Callback> +>); + +impl Default for CustomComponents { + fn default() -> Self { + Self (Default::default()) + } +} + +impl CustomComponents +{ + pub fn new() -> Self { + Self(Default::default()) + } + + /// register a new component. + /// The function `component` takes a context and props of type `MdComponentProps` + /// and returns html + pub fn register(&mut self, name: &'static str, component: F) + where F: Fn(MdComponentProps) -> Result + 'static, + I: IntoView + { + let closure = move |props| component(props).map(|x| x.into_view()); + self.0.insert(name, Callback::new(closure)); + } +} + + impl<'a> Context<'a, 'static> for &'a __MdProps { type View = View; - type HtmlCallback = Callback; - type Handler = Callback; - type Setter = WriteSignal; - type MouseEvent = MouseEvent; - fn props(self) -> rust_web_markdown::MarkdownProps<'a, 'static, Self> { - rust_web_markdown::MarkdownProps { - components: &self.components, - frontmatter: self.frontmatter.as_ref(), + fn props(self) -> rust_web_markdown::MarkdownProps<'a> { + MarkdownProps { hard_line_breaks: self.hard_line_breaks.get(), wikilinks: self.wikilinks.get(), parse_options: self.parse_options.as_ref(), - render_links: self.render_links.as_ref(), theme: self.theme.as_deref(), } } - fn set(self, setter: &WriteSignal, value: T) { - setter.set(value) - } - #[cfg(feature="debug")] fn send_debug_info(self, info: Vec) { let set_event_info = use_context::(); @@ -199,16 +221,6 @@ impl<'a> Context<'a, 'static> for &'a __MdProps { Callable::call(callback, input) } - fn call_html_callback(self, callback: &Self::HtmlCallback, input: T) -> Self::View { - Callable::call(callback, input).into_view() - } - - fn make_handler( - self, - f: F, - ) -> Self::Handler { - Callback::new(f) - } fn make_md_handler(self, position: Range, stop_propagation: bool) -> Self::Handler { match self.on_click { @@ -228,6 +240,31 @@ impl<'a> Context<'a, 'static> for &'a __MdProps { None => Callback::new(move |_| ()) } } + + fn set_frontmatter(self, frontmatter: String) { + if let Some(setter) = self.frontmatter { + setter.set(frontmatter) + } + } + + fn has_custom_links(self) -> bool { + self.render_links.is_some() + } + + fn render_links(self, link: LinkDescription) + -> Result { + Ok(Callable::call(&self.render_links.unwrap(), link)) + } + + fn has_custom_component(self, name: &str) -> bool { + self.components.0.get(name).is_some() + } + + fn render_custom_component(self, name: &str, input: MdComponentProps) + -> Result { + let f = self.components.0.get(name).unwrap(); + f(input) + } } @@ -268,7 +305,7 @@ pub fn __Md( parse_options: Option, #[prop(optional, into)] - components: BTreeMap<&'static str, Callback, leptos::View>>, + components: CustomComponents, #[prop(optional, into)] frontmatter: Option>