macros.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #[macro_export]
  2. macro_rules! inline_attribute {
  3. (
  4. $key: ident,
  5. $value: ty
  6. ) => {
  7. pub fn $key(value: $value) -> Self {
  8. Self {
  9. key: RichTextAttributeKey::$key,
  10. value: value.into(),
  11. scope: AttributeScope::Inline,
  12. }
  13. }
  14. };
  15. }
  16. #[macro_export]
  17. macro_rules! block_attribute {
  18. (
  19. $key: ident,
  20. $value: ty
  21. ) => {
  22. pub fn $key(value: $value) -> Self {
  23. Self {
  24. key: RichTextAttributeKey::$key,
  25. value: value.into(),
  26. scope: AttributeScope::Block,
  27. }
  28. }
  29. };
  30. }
  31. #[macro_export]
  32. macro_rules! list_attribute {
  33. (
  34. $key: ident,
  35. $value: expr
  36. ) => {
  37. pub fn $key(b: bool) -> Self {
  38. let value = match b {
  39. true => $value,
  40. false => "",
  41. };
  42. RichTextAttribute::List(value)
  43. }
  44. };
  45. }
  46. #[macro_export]
  47. macro_rules! ignore_attribute {
  48. (
  49. $key: ident,
  50. $value: ident
  51. ) => {
  52. pub fn $key(value: $value) -> Self {
  53. Self {
  54. key: RichTextAttributeKey::$key,
  55. value: value.into(),
  56. scope: AttributeScope::Ignore,
  57. }
  58. }
  59. };
  60. }