diff --git a/Cargo.lock b/Cargo.lock index bb05bc1..1e320f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,16 +8,50 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "backtrace" +version = "0.3.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bumpalo" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cc" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crc32fast" version = "1.2.0" @@ -57,6 +91,48 @@ version = "0.1.0" dependencies = [ "docx-core 0.1.0", "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "js-sys" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -64,6 +140,11 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "log" version = "0.4.8" @@ -72,6 +153,20 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "memchr" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "nom" +version = "4.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "output_vt100" version = "0.1.2" @@ -96,6 +191,14 @@ dependencies = [ "output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "1.0.6" @@ -104,6 +207,14 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "1.0.2" @@ -112,6 +223,21 @@ dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "sourcefile" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "1.0.7" @@ -122,6 +248,17 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "synstructure" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thiserror" version = "1.0.5" @@ -140,11 +277,26 @@ dependencies = [ "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wasm-bindgen" version = "0.2.53" @@ -168,6 +320,18 @@ dependencies = [ "wasm-bindgen-shared 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.53" @@ -194,6 +358,64 @@ name = "wasm-bindgen-shared" version = "0.2.53" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wasm-bindgen-test" +version = "0.2.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.2.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-webidl" +version = "0.2.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "web-sys" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", + "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "weedle" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.3.8" @@ -229,27 +451,54 @@ dependencies = [ [metadata] "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" +"checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum ctor 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" +"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" +"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +"checksum js-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)" = "a60f6ca5eb7ae3014e3ab34e3189a1560267245216e19f76a021a4c669817e62" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" "checksum output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +"checksum scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c" +"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum thiserror 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f9fb62ff737e573b1e677459bea6fd023cd5d6e868c3242d3cdf3ef2f0554824" "checksum thiserror-impl 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "24069c0ba08aab54289d6a25f5036d94afc61e1538bbc42ae5501df141c9027d" +"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "4c29d57d5c3b3bc53bbe35c5a4f4a0df994d870b7d3cb0ad1c2065e21822ae41" "checksum wasm-bindgen-backend 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "aa2868fa93e5bf36a9364d1277a0f97392748a8217d9aa0ec3f1cdbdf7ad1a60" +"checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c" "checksum wasm-bindgen-macro 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "41e80594782a241bf3d92ee5d1247b8fb496250a8a2ff1e136942d433fbbce14" "checksum wasm-bindgen-macro-support 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "74b9950355b1d92ca09de0984bdd4de7edda5e8af12daf0c052a0a075e8c9157" "checksum wasm-bindgen-shared 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "7493fe67ad99672ef3de3e6ba513fb03db276358c8cc9588ce5a008c6e48ad68" +"checksum wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1" +"checksum wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5" +"checksum wasm-bindgen-webidl 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)" = "8272d9a8831be66b30908996b71b3eaf9b83de050f89e4dc34826a19980eb59d" +"checksum web-sys 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0232f38e5c66384edaedaa726ae2d6313e3ed3ae860693c497a3193af3e161ce" +"checksum weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/docx-core/src/documents/elements/comment.rs b/docx-core/src/documents/elements/comment.rs index 98c5f9e..8d23ca3 100644 --- a/docx-core/src/documents/elements/comment.rs +++ b/docx-core/src/documents/elements/comment.rs @@ -3,10 +3,10 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Comment { - id: String, - author: String, - date: String, - paragraph: Paragraph, + pub id: String, + pub author: String, + pub date: String, + pub paragraph: Paragraph, } impl Default for Comment { diff --git a/docx-core/src/documents/elements/level.rs b/docx-core/src/documents/elements/level.rs index fcb238c..f3b3c9e 100644 --- a/docx-core/src/documents/elements/level.rs +++ b/docx-core/src/documents/elements/level.rs @@ -9,7 +9,7 @@ pub struct Level { format: NumberFormat, text: LevelText, jc: LevelJc, - paragraph_property: ParagraphProperty, + pub paragraph_property: ParagraphProperty, } impl Level { diff --git a/docx-core/src/documents/elements/paragraph.rs b/docx-core/src/documents/elements/paragraph.rs index 93002c3..5498615 100644 --- a/docx-core/src/documents/elements/paragraph.rs +++ b/docx-core/src/documents/elements/paragraph.rs @@ -5,8 +5,8 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Paragraph { - pub(crate) children: Vec, - property: ParagraphProperty, + pub children: Vec, + pub property: ParagraphProperty, attrs: Vec<(String, String)>, } @@ -183,9 +183,7 @@ mod tests { #[test] fn test_comment() { let b = Paragraph::new() - .add_comment_start( - Comment::new("1234-5678"), // .paragraph(Paragraph::new().add_run(Run::new().add_text("Comment"))), - ) + .add_comment_start(Comment::new("1234-5678")) .add_run(Run::new().add_text("Hello")) .add_comment_end("1234-5678") .build(); diff --git a/docx-core/src/documents/elements/run.rs b/docx-core/src/documents/elements/run.rs index 38d8277..5184602 100644 --- a/docx-core/src/documents/elements/run.rs +++ b/docx-core/src/documents/elements/run.rs @@ -5,8 +5,8 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Run { - run_property: RunProperty, - children: Vec, + pub run_property: RunProperty, + pub children: Vec, } impl Default for Run { diff --git a/docx-core/src/documents/elements/table.rs b/docx-core/src/documents/elements/table.rs index 54cded0..c072a8a 100644 --- a/docx-core/src/documents/elements/table.rs +++ b/docx-core/src/documents/elements/table.rs @@ -4,7 +4,7 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Table { - pub(crate) rows: Vec, + pub rows: Vec, property: TableProperty, grid: Vec, } diff --git a/docx-core/src/documents/elements/table_cell.rs b/docx-core/src/documents/elements/table_cell.rs index 534d5ba..f53b94d 100644 --- a/docx-core/src/documents/elements/table_cell.rs +++ b/docx-core/src/documents/elements/table_cell.rs @@ -5,8 +5,8 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct TableCell { - pub(crate) contents: Vec, - property: TableCellProperty, + pub contents: Vec, + pub property: TableCellProperty, } #[derive(Debug, Clone)] diff --git a/docx-core/src/documents/elements/table_row.rs b/docx-core/src/documents/elements/table_row.rs index b3dff7f..9369dca 100644 --- a/docx-core/src/documents/elements/table_row.rs +++ b/docx-core/src/documents/elements/table_row.rs @@ -4,7 +4,7 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct TableRow { - pub(crate) cells: Vec, + pub cells: Vec, property: TableRowProperty, } diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index 0c6a02d..f108d59 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -35,12 +35,12 @@ pub struct Docx { rels: Rels, document_rels: DocumentRels, doc_props: DocProps, - styles: Styles, - document: Document, - comments: Comments, - numberings: Numberings, - settings: Settings, - font_table: FontTable, + pub styles: Styles, + pub document: Document, + pub comments: Comments, + pub numberings: Numberings, + pub settings: Settings, + pub font_table: FontTable, } impl Default for Docx { diff --git a/docx-core/src/types/special_indent_type.rs b/docx-core/src/types/special_indent_type.rs index 60c0675..7e7ccae 100644 --- a/docx-core/src/types/special_indent_type.rs +++ b/docx-core/src/types/special_indent_type.rs @@ -1,7 +1,16 @@ -// INFO: wasm-bindgen allow c-style enum for now +use wasm_bindgen::prelude::*; + +// INFO: wasm-bindgen only allow c-style enum for now // Please convert typescript type to following type. #[derive(Copy, Clone, Debug)] pub enum SpecialIndentType { FirstLine(usize), Hanging(usize), } + +#[wasm_bindgen] +#[derive(Copy, Clone, Debug)] +pub enum SpecialIndentKind { + FirstLine, + Hanging, +} diff --git a/docx-wasm/Cargo.toml b/docx-wasm/Cargo.toml index 1c629b3..e555f32 100644 --- a/docx-wasm/Cargo.toml +++ b/docx-wasm/Cargo.toml @@ -12,3 +12,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2.50" docx-core = { path = "../docx-core" } + +[dev-dependencies] +wasm-bindgen-test = "0.2" \ No newline at end of file diff --git a/docx-wasm/index.js b/docx-wasm/index.js index e122e3d..39e70c9 100644 --- a/docx-wasm/index.js +++ b/docx-wasm/index.js @@ -6,10 +6,18 @@ const rust = import("./pkg"); rust .then(m => { - const p = m - .createParagraph() - .add_run(m.createRun().add_text("Hello World!!")); - let docx = m.createDocx().add_paragraph(p); + const p = m.createParagraph().add_run( + m + .createRun() + .add_text("Hello World!!") + .bold() + ); + const t = m + .createTable() + .add_row( + m.createTableRow().add_cell(m.createTableCell().add_paragraph(p)) + ); + let docx = m.createDocx().add_table(t); saveAs(new Blob([docx.build()]), "example.docx"); docx.free(); }) diff --git a/docx-wasm/src/adaptors/mod.rs b/docx-wasm/src/adaptors/mod.rs new file mode 100644 index 0000000..b6641cf --- /dev/null +++ b/docx-wasm/src/adaptors/mod.rs @@ -0,0 +1,3 @@ +mod special_indent; + +pub use special_indent::*; diff --git a/docx-wasm/src/adaptors/special_indent.rs b/docx-wasm/src/adaptors/special_indent.rs new file mode 100644 index 0000000..dbeb817 --- /dev/null +++ b/docx-wasm/src/adaptors/special_indent.rs @@ -0,0 +1,24 @@ +use docx_core; + +pub fn create_special_indent( + special_indent_kind: Option, + special_indent_size: Option, +) -> Option { + if let Some(kind) = special_indent_kind { + let size = if special_indent_size.is_some() { + special_indent_size.unwrap() + } else { + 0 + }; + match kind { + docx_core::SpecialIndentKind::FirstLine => { + Some(docx_core::SpecialIndentType::FirstLine(size)) + } + docx_core::SpecialIndentKind::Hanging => { + Some(docx_core::SpecialIndentType::Hanging(size)) + } + } + } else { + None + } +} diff --git a/docx-wasm/src/comment.rs b/docx-wasm/src/comment.rs new file mode 100644 index 0000000..a39e305 --- /dev/null +++ b/docx-wasm/src/comment.rs @@ -0,0 +1,40 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Comment(docx_core::Comment); + +#[wasm_bindgen(js_name = createComment)] +pub fn create_comment(id: String) -> Comment { + Comment(docx_core::Comment::new(id)) +} + +impl Comment { + pub fn take(self) -> docx_core::Comment { + self.0 + } +} + +#[wasm_bindgen] +impl Comment { + pub fn author(mut self, author: String) -> Comment { + self.0.author = author.into(); + self + } + + pub fn date(mut self, date: String) -> Comment { + self.0.date = date.into(); + self + } + + pub fn paragraph(mut self, p: Paragraph) -> Comment { + self.0.paragraph = p.take(); + self + } + + pub fn id(&self) -> String { + self.0.id.clone() + } +} diff --git a/docx-wasm/src/delete.rs b/docx-wasm/src/delete.rs new file mode 100644 index 0000000..b80d1c7 --- /dev/null +++ b/docx-wasm/src/delete.rs @@ -0,0 +1,18 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Delete(docx_core::Delete); + +#[wasm_bindgen(js_name = createDelete)] +pub fn create_delete() -> Delete { + Delete(docx_core::Delete::new()) +} + +impl Delete { + pub fn take(self) -> docx_core::Delete { + self.0 + } +} diff --git a/docx-wasm/src/docx.rs b/docx-wasm/src/docx.rs new file mode 100644 index 0000000..cd00018 --- /dev/null +++ b/docx-wasm/src/docx.rs @@ -0,0 +1,41 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Docx(docx_core::Docx); + +#[wasm_bindgen] +#[allow(non_snake_case)] +pub fn createDocx() -> Docx { + Docx(docx_core::Docx::new()) +} + +#[wasm_bindgen] +impl Docx { + pub fn add_paragraph(mut self, p: Paragraph) -> Self { + self.0 = self.0.add_paragraph(p.take()); + self + } + + pub fn add_table(mut self, t: Table) -> Docx { + self.0.document = self.0.document.add_table(t.take()); + self + } + + pub fn add_numbering(mut self, num: Numbering) -> Docx { + self.0.numberings = self.0.numberings.add_numbering(num.take()); + self + } + + pub fn build(&mut self) -> Result, JsValue> { + let buf = Vec::new(); + let mut cur = std::io::Cursor::new(buf); + let res = self.0.build().pack(&mut cur); + if res.is_err() { + return Err(format!("{:?}", res).into()); + } + Ok(cur.into_inner()) + } +} diff --git a/docx-wasm/src/insert.rs b/docx-wasm/src/insert.rs new file mode 100644 index 0000000..aa2a149 --- /dev/null +++ b/docx-wasm/src/insert.rs @@ -0,0 +1,18 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Insert(docx_core::Insert); + +#[wasm_bindgen(js_name = createInsert)] +pub fn create_insert() -> Insert { + Insert(docx_core::Insert::new()) +} + +impl Insert { + pub fn take(self) -> docx_core::Insert { + self.0 + } +} diff --git a/docx-wasm/src/level.rs b/docx-wasm/src/level.rs new file mode 100644 index 0000000..82cfca5 --- /dev/null +++ b/docx-wasm/src/level.rs @@ -0,0 +1,36 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Level(docx_core::Level); + +#[wasm_bindgen(js_name = createLevel)] +pub fn create_level(id: usize, start: usize, format: &str, text: &str, jc: &str) -> Level { + let start = docx_core::Start::new(start); + let format = docx_core::NumberFormat::new(format); + let text = docx_core::LevelText::new(text); + let jc = docx_core::LevelJc::new(jc); + Level(docx_core::Level::new(id, start, format, text, jc)) +} + +impl Level { + pub fn take(self) -> docx_core::Level { + self.0 + } +} + +#[wasm_bindgen] +impl Level { + pub fn indent( + mut self, + left: usize, + special_indent_kind: Option, + special_indent_size: Option, + ) -> Self { + let special_indent = create_special_indent(special_indent_kind, special_indent_size); + self.0.paragraph_property = self.0.paragraph_property.indent(left, special_indent); + self + } +} diff --git a/docx-wasm/src/lib.rs b/docx-wasm/src/lib.rs index 0885659..f2194d0 100644 --- a/docx-wasm/src/lib.rs +++ b/docx-wasm/src/lib.rs @@ -1,63 +1,26 @@ -use docx_core; -use wasm_bindgen::prelude::*; +mod adaptors; +mod comment; +mod delete; +mod docx; +mod insert; +mod level; +mod numbering; +mod paragraph; +mod run; +mod table; +mod table_cell; +mod table_row; -#[wasm_bindgen] -#[derive(Debug)] -pub struct Docx(docx_core::Docx); - -#[wasm_bindgen(js_name = createDocx)] -pub fn create_docx() -> Docx { - Docx(docx_core::Docx::new()) -} - -#[wasm_bindgen] -impl Docx { - pub fn add_paragraph(mut self, p: Paragraph) -> Self { - self.0 = self.0.add_paragraph(p.0); - self - } - - pub fn build(&mut self) -> Result, JsValue> { - let buf = Vec::new(); - let mut cur = std::io::Cursor::new(buf); - let res = self.0.build().pack(&mut cur); - if res.is_err() { - return Err(format!("{:?}", res).into()); - } - Ok(cur.into_inner()) - } -} - -#[wasm_bindgen] -#[derive(Debug)] -pub struct Paragraph(docx_core::Paragraph); - -#[wasm_bindgen(js_name = createParagraph)] -pub fn create_paragraph() -> Paragraph { - Paragraph(docx_core::Paragraph::new()) -} - -#[wasm_bindgen] -impl Paragraph { - pub fn add_run(mut self, run: Run) -> Self { - self.0 = self.0.add_run(run.0); - self - } -} - -#[wasm_bindgen] -#[derive(Debug)] -pub struct Run(docx_core::Run); - -#[wasm_bindgen(js_name = createRun)] -pub fn create_run() -> Run { - Run(docx_core::Run::new()) -} - -#[wasm_bindgen] -impl Run { - pub fn add_text(mut self, text: &str) -> Self { - self.0 = self.0.add_text(text); - self - } -} +pub use adaptors::*; +pub use comment::*; +pub use delete::*; +pub use docx::*; +pub use docx_core; +pub use insert::*; +pub use level::*; +pub use numbering::*; +pub use paragraph::*; +pub use run::*; +pub use table::*; +pub use table_cell::*; +pub use table_row::*; diff --git a/docx-wasm/src/numbering.rs b/docx-wasm/src/numbering.rs new file mode 100644 index 0000000..911b1b5 --- /dev/null +++ b/docx-wasm/src/numbering.rs @@ -0,0 +1,26 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Numbering(docx_core::Numbering); + +#[wasm_bindgen(js_name = createNumbering)] +pub fn create_numbering(id: usize) -> Numbering { + Numbering(docx_core::Numbering::new(id)) +} + +impl Numbering { + pub fn take(self) -> docx_core::Numbering { + self.0 + } +} + +#[wasm_bindgen] +impl Numbering { + pub fn add_level(mut self, level: Level) -> Self { + self.0 = self.0.add_level(level.take()); + self + } +} diff --git a/docx-wasm/src/paragraph.rs b/docx-wasm/src/paragraph.rs new file mode 100644 index 0000000..efdc17e --- /dev/null +++ b/docx-wasm/src/paragraph.rs @@ -0,0 +1,100 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Paragraph(docx_core::Paragraph); + +#[wasm_bindgen(js_name = createParagraph)] +pub fn create_paragraph() -> Paragraph { + Paragraph(docx_core::Paragraph::new()) +} + +#[wasm_bindgen] +impl Paragraph { + pub fn add_run(mut self, run: Run) -> Paragraph { + self.0 = self.0.add_run(run.take()); + self + } + + pub fn add_insert(mut self, i: Insert) -> Paragraph { + self.0 + .children + .push(docx_core::ParagraphChild::Insert(i.take())); + self + } + + pub fn add_delete(mut self, d: Delete) -> Paragraph { + self.0 + .children + .push(docx_core::ParagraphChild::Delete(d.take())); + self + } + + pub fn add_bookmark_start(mut self, id: &str, name: &str) -> Paragraph { + self.0 + .children + .push(docx_core::ParagraphChild::BookmarkStart( + docx_core::BookmarkStart::new(id, name), + )); + self + } + + pub fn add_bookmark_end(mut self, id: &str) -> Paragraph { + self.0.children.push(docx_core::ParagraphChild::BookmarkEnd( + docx_core::BookmarkEnd::new(id), + )); + self + } + + pub fn add_comment_start(mut self, comment: Comment) -> Paragraph { + self.0 + .children + .push(docx_core::ParagraphChild::CommentStart( + docx_core::CommentRangeStart::new(comment.take()), + )); + self + } + + pub fn add_comment_end(mut self, id: &str) -> Paragraph { + self.0.children.push(docx_core::ParagraphChild::CommentEnd( + docx_core::CommentRangeEnd::new(id), + )); + self + } + + pub fn align(mut self, alignment_type: docx_core::AlignmentType) -> Paragraph { + self.0.property = self.0.property.align(alignment_type); + self + } + + pub fn style(mut self, style_id: &str) -> Paragraph { + self.0.property = self.0.property.style(style_id); + self + } + + pub fn indent( + mut self, + left: usize, + special_indent_kind: Option, + special_indent_size: Option, + ) -> Paragraph { + let special_indent = create_special_indent(special_indent_kind, special_indent_size); + self.0.property = self.0.property.indent(left, special_indent); + self + } + + pub fn numbering(mut self, id: usize, level: usize) -> Self { + let id = docx_core::NumberingId::new(id); + let level = docx_core::IndentLevel::new(level); + self.0.property = self.0.property.numbering(id, level); + self + } +} + +impl Paragraph { + pub fn take(self) -> docx_core::Paragraph { + self.0 + } +} diff --git a/docx-wasm/src/run.rs b/docx-wasm/src/run.rs new file mode 100644 index 0000000..ec0c0ad --- /dev/null +++ b/docx-wasm/src/run.rs @@ -0,0 +1,79 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Run(docx_core::Run); + +#[wasm_bindgen(js_name = createRun)] +pub fn create_run() -> Run { + Run(docx_core::Run::new()) +} + +#[wasm_bindgen] +impl Run { + pub fn add_text(mut self, text: &str) -> Self { + self.0 = self.0.add_text(text); + self + } + + pub fn add_delete_text(mut self, text: &str) -> Run { + self.0 + .children + .push(docx_core::RunChild::Text(docx_core::Text::new(text))); + self + } + + pub fn add_tab(mut self) -> Run { + self.0 + .children + .push(docx_core::RunChild::Tab(docx_core::Tab::new())); + self + } + + pub fn add_break(mut self, break_type: docx_core::BreakType) -> Run { + self.0 + .children + .push(docx_core::RunChild::Break(docx_core::Break::new( + break_type, + ))); + self + } + + pub fn size(mut self, size: usize) -> Run { + self.0.run_property = self.0.run_property.size(size); + self + } + + pub fn color(mut self, color: &str) -> Run { + self.0.run_property = self.0.run_property.color(color); + self + } + + pub fn highlight(mut self, color: &str) -> Run { + self.0.run_property = self.0.run_property.highlight(color); + self + } + + pub fn bold(mut self) -> Run { + self.0.run_property = self.0.run_property.bold(); + self + } + + pub fn italic(mut self) -> Run { + self.0.run_property = self.0.run_property.italic(); + self + } + + pub fn underline(mut self, line_type: &str) -> Run { + self.0.run_property = self.0.run_property.underline(line_type); + self + } +} + +impl Run { + pub fn take(self) -> docx_core::Run { + self.0 + } +} diff --git a/docx-wasm/src/table.rs b/docx-wasm/src/table.rs new file mode 100644 index 0000000..c531bb3 --- /dev/null +++ b/docx-wasm/src/table.rs @@ -0,0 +1,26 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct Table(docx_core::Table); + +#[wasm_bindgen(js_name = createTable)] +pub fn create_table() -> Table { + Table(docx_core::Table::new(vec![])) +} + +impl Table { + pub fn take(self) -> docx_core::Table { + self.0 + } +} + +#[wasm_bindgen] +impl Table { + pub fn add_row(mut self, row: TableRow) -> Table { + self.0.rows.push(row.take()); + self + } +} diff --git a/docx-wasm/src/table_cell.rs b/docx-wasm/src/table_cell.rs new file mode 100644 index 0000000..b0b9ad6 --- /dev/null +++ b/docx-wasm/src/table_cell.rs @@ -0,0 +1,38 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct TableCell(docx_core::TableCell); + +#[wasm_bindgen(js_name = createTableCell)] +pub fn create_table_cell() -> TableCell { + TableCell(docx_core::TableCell::new()) +} + +impl TableCell { + pub fn take(self) -> docx_core::TableCell { + self.0 + } +} + +#[wasm_bindgen] +impl TableCell { + pub fn add_paragraph(mut self, p: Paragraph) -> TableCell { + self.0 + .contents + .push(docx_core::TableCellContent::Paragraph(p.take())); + self + } + + pub fn vertical_merge(mut self, t: docx_core::VMergeType) -> TableCell { + self.0.property = self.0.property.vertical_merge(t); + self + } + + pub fn grid_span(mut self, v: usize) -> TableCell { + self.0.property = self.0.property.grid_span(v); + self + } +} diff --git a/docx-wasm/src/table_row.rs b/docx-wasm/src/table_row.rs new file mode 100644 index 0000000..a3abc27 --- /dev/null +++ b/docx-wasm/src/table_row.rs @@ -0,0 +1,26 @@ +use super::*; +use docx_core; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +#[derive(Debug)] +pub struct TableRow(docx_core::TableRow); + +#[wasm_bindgen(js_name = createTableRow)] +pub fn create_table_row() -> TableRow { + TableRow(docx_core::TableRow::new(vec![])) +} + +impl TableRow { + pub fn take(self) -> docx_core::TableRow { + self.0 + } +} + +#[wasm_bindgen] +impl TableRow { + pub fn add_cell(mut self, cell: TableCell) -> TableRow { + self.0.cells.push(cell.take()); + self + } +}