@@ -8,32 +8,32 @@ The StringBinder allows you to replace keywords in plain text with ReactNode ele
88
99## Usage
1010### Keywords
11- A keyword in plain text must start with ` $ ` and contain only ` A-Za-z ` with out any spaces.
11+ A keyword in plain text must start & close with ` $ ` and contain only ` A-Za-z ` with out any spaces (min len = 1) .
1212
1313``` jsx
1414
15- // keyword is $keyword
16- const success = ` This is a $keyword.` ;
15+ // keyword is $keyword$
16+ const success = ` This is a $keyword$ .` ;
1717
1818// just not handled
1919const fail = ` This is not a $1keyword` ;
2020
21- // keyword is $key
21+ // just not handled
2222const watch = ` This is not a $key_word` ;
2323
2424// multiply keys: $flowers, $crons
25- const multiple = " $flowers and $crowns." ;
25+ const multiple = " $flowers$ and $crowns$ ." ;
2626```
2727### Binds
28- Bind object keys must be same as keywords but with out ` $ `
28+ Keys of bindable ` ReactNode ` | ` string ` must be same as keywords but without ` $ `
2929
3030``` jsx
3131import StringBinderInstance from " @rejchev/react-string-binder" ;
3232
33- const text = " This is a simple $example " ;
33+ const text = " This is a simple $nl$ " ;
3434
3535StringBinderInstance .bind (text, {
36- example : < hr / >
36+ nl : < hr / >
3737})
3838
3939```
@@ -44,13 +44,57 @@ StringBinderInstance.bind(text, {
4444
4545import StringBinderInstance from " @rejchev/react-string-binder" ;
4646
47- const text =
48- " The spring sun warms the awakening nature. " +
49- " Birds chirp joyfully in the tree $crowns, $flowers stretch towards the heavenly surface. " +
50- " The air is filled with freshness and the aroma of the first flowers."
51-
52- const element = StringBinderInstance .bind (text, {
53- crowns: < a href= {' https://en.wikipedia.org/wiki/Crown_(botany)' } target= {' _blank' }> crowns< / a> ,
54- flowers: < a href= {' https://en.wikipedia.org/wiki/Flower' } target= {' _blank' }> flowers< / a>
55- })
47+ function App () {
48+
49+ const text =
50+ " The spring sun warms the awakening nature. $n$" +
51+ " Birds chirp joyfully in the tree $crowns$, $flowers$ stretch towards the heavenly surface. $n$" +
52+ " The air is filled with freshness and the aroma of the first flowers."
53+
54+ const unknownKeys =
55+ // Test variant <br/>
56+ " Test $variant$ $n$" +
57+
58+ // Test another_variant <br/>
59+ " Test another_$variant$ $n$" +
60+
61+ // Test third_variant_variant
62+ " Test third_$variant$_variant"
63+
64+ const oneMore =
65+ // Test <a href="//yandex.ru" target="_blank">flowers</a>flowers <br/>
66+ " Test $flowers$flowers $n$" +
67+
68+ // Test <a href="//yandex.ru" target="_blank">flowers</a>flowers <br/>
69+ " Test $flowers$flowers$ $n$" +
70+
71+ // Test <a href="//yandex.ru" target="_blank">flowers</a><a href="//yandex.ru" target="_blank">flowers</a> <br/>
72+ " Test $flowers$$flowers$ $n$"
73+
74+ return (
75+ <>
76+ < p className= " read-the-docs" >
77+ {StringBinderInstance .bind (text, {
78+ crowns: < a href= {' //google.com' } target= {' _blank' }> crowns< / a> ,
79+ flowers: < a href= {' //yandex.ru' } target= {' _blank' }> flowers< / a> ,
80+ n: < br/ > ,
81+ })}
82+ < / p>
83+ < p className= " read-the-docs" >
84+ {StringBinderInstance .bind (unknownKeys, {
85+ crowns: < a href= {' //google.com' } target= {' _blank' }> crowns< / a> ,
86+ flowers: < a href= {' //yandex.ru' } target= {' _blank' }> flowers< / a> ,
87+ n: < br/ > ,
88+ })}
89+ < / p>
90+ < p className= " read-the-docs" >
91+ {StringBinderInstance .bind (oneMore, {
92+ crowns: < a href= {' //google.com' } target= {' _blank' }> crowns< / a> ,
93+ flowers: < a href= {' //yandex.ru' } target= {' _blank' }> flowers< / a> ,
94+ n: < br/ > ,
95+ })}
96+ < / p>
97+ < / >
98+ )
99+ }
56100```
0 commit comments