Compare commits
841 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
504bdb8e6c | ||
|
|
0b6f4fb7e6 | ||
|
|
8748254d5a | ||
|
|
7917565654 | ||
|
|
30b41b0d70 | ||
|
|
a421b6d83a | ||
|
|
a8665290a0 | ||
|
|
61af76927e | ||
|
|
2ffe3d5b8e | ||
|
|
03b5c42696 | ||
|
|
f9b812a58d | ||
|
|
16cd99aece | ||
|
|
368bed514e | ||
|
|
1492c40fc2 | ||
|
|
dafa73832e | ||
|
|
702a2cb180 | ||
|
|
89dbbc284b | ||
|
|
6023d015b6 | ||
|
|
ea2e61cfd9 | ||
|
|
bdcbd0069c | ||
|
|
859312b7d2 | ||
|
|
9de5ad0157 | ||
|
|
61df613cd2 | ||
|
|
b70d6ca9ca | ||
|
|
0e15676cb7 | ||
|
|
5f419a0d02 | ||
|
|
a0efe7dd26 | ||
|
|
21afb5adcd | ||
|
|
7d0d73cd51 | ||
|
|
e8a51345a8 | ||
|
|
f471774da9 | ||
|
|
0facccf009 | ||
|
|
835c8fec03 | ||
|
|
eea093acd4 | ||
|
|
b32bfb3e54 | ||
|
|
65f330baae | ||
|
|
b43a677744 | ||
|
|
4b69d6a150 | ||
|
|
4a3ee6c5ca | ||
|
|
69baeb6339 | ||
|
|
f7fe2b0cca | ||
|
|
f853550748 | ||
|
|
75fa8f788c | ||
|
|
7a86fdaba3 | ||
|
|
1566b22489 | ||
|
|
ed026f3587 | ||
|
|
6e8e4ce780 | ||
|
|
60b7d90ad2 | ||
|
|
da83465f19 | ||
|
|
7ae0b64d8e | ||
|
|
f8cbf7801d | ||
|
|
7fbd49c5ea | ||
|
|
8717e26f76 | ||
|
|
483d6c3d17 | ||
|
|
03fb52fb8e | ||
|
|
e574f0e65f | ||
|
|
e9b04c712d | ||
|
|
b4c7c8860c | ||
|
|
815c161b7e | ||
|
|
ecaaaeb049 | ||
|
|
647846762d | ||
|
|
655a15c722 | ||
|
|
6297b859dd | ||
|
|
19f05c68f8 | ||
|
|
5a12bd9cce | ||
|
|
e22b374bdd | ||
|
|
fe3749d499 | ||
|
|
85ef7f252d | ||
|
|
f16b563a82 | ||
|
|
8e22dd817e | ||
|
|
569f3c02cd | ||
|
|
e8c2099e4c | ||
|
|
1646fefd56 | ||
|
|
aad387802e | ||
|
|
034d0a2f50 | ||
|
|
d2c78304c6 | ||
|
|
247857a843 | ||
|
|
038ff3a40e | ||
|
|
6d8776332f | ||
|
|
4ea24b0297 | ||
|
|
12570ecb00 | ||
|
|
7b68aecbd7 | ||
|
|
7ce62a8a3d | ||
|
|
d8c3cf725d | ||
|
|
aecc531d84 | ||
|
|
f107779542 | ||
|
|
70bf17011c | ||
|
|
86ae19fe2a | ||
|
|
e8235c4c35 | ||
|
|
63b5cd3bfb | ||
|
|
12e851c127 | ||
|
|
20fa72b613 | ||
|
|
36bee8070a | ||
|
|
9a85612b8a | ||
|
|
2bc18f7d90 | ||
|
|
6f6428543d | ||
|
|
d03087c1b8 | ||
|
|
d2d47cf8ee | ||
|
|
7a0f4490de | ||
|
|
d2b3c9472a | ||
|
|
3a0b9a00a3 | ||
|
|
d5cf4ad9e5 | ||
|
|
2899b2f263 | ||
|
|
7475321e97 | ||
|
|
88a24d7bdd | ||
|
|
f798a51edc | ||
|
|
81edab38f3 | ||
|
|
039607a294 | ||
|
|
2f33522e6d | ||
|
|
76c54a713a | ||
|
|
dcebed2d42 | ||
|
|
dbf9afa8da | ||
|
|
f7f397b5f2 | ||
|
|
44f852ad42 | ||
|
|
e1be2f2130 | ||
|
|
8468607703 | ||
|
|
f981318142 | ||
|
|
e1d0d7b293 | ||
|
|
d118a0cf74 | ||
|
|
7cb1095465 | ||
|
|
595b885b9a | ||
|
|
b1c219bc1b | ||
|
|
852b2ac3b4 | ||
|
|
937cded2aa | ||
|
|
022d2453d2 | ||
|
|
e5a187cc24 | ||
|
|
83bb63321a | ||
|
|
cd5b5c9240 | ||
|
|
2096ec0d5d | ||
|
|
25d4311237 | ||
|
|
7e07c2fc81 | ||
|
|
5a8a618e6b | ||
|
|
f072fc99b9 | ||
|
|
54e881fc58 | ||
|
|
cd6a3ed724 | ||
|
|
5a00dde912 | ||
|
|
876d7b2f7b | ||
|
|
4b74ec0e54 | ||
|
|
a719e33332 | ||
|
|
86a727f097 | ||
|
|
2670780076 | ||
|
|
ebf9912269 | ||
|
|
11549ab64e | ||
|
|
d128146952 | ||
|
|
686abd8842 | ||
|
|
551aeed835 | ||
|
|
5b1a1a2bcf | ||
|
|
09d2474a9a | ||
|
|
5c00e5493c | ||
|
|
c343af8f5a | ||
|
|
4af7eb5b89 | ||
|
|
aa9a340144 | ||
|
|
35ae68ceee | ||
|
|
560fb4ece6 | ||
|
|
8eb494cd5b | ||
|
|
0766336a56 | ||
|
|
24352f4d1c | ||
|
|
adb0fee973 | ||
|
|
13a7113aa7 | ||
|
|
e882975726 | ||
|
|
12209fe923 | ||
|
|
8a63744198 | ||
|
|
5871f0c9b0 | ||
|
|
908f524c64 | ||
|
|
9fa0ee3def | ||
|
|
35e9450f74 | ||
|
|
6033ea5a98 | ||
|
|
6f24c3cb39 | ||
|
|
e975e49d3e | ||
|
|
c5cfe10fa6 | ||
|
|
7c988460f0 | ||
|
|
21f1892de0 | ||
|
|
b97344849d | ||
|
|
935d48d4cc | ||
|
|
73ba233f9e | ||
|
|
ff955d392b | ||
|
|
19fde31f67 | ||
|
|
b3f368ac37 | ||
|
|
c5efb401b4 | ||
|
|
f386e6ed91 | ||
|
|
55b323c063 | ||
|
|
6f286b52d8 | ||
|
|
4850673b96 | ||
|
|
353af537ba | ||
|
|
2367d86eb7 | ||
|
|
1aec46a57c | ||
|
|
f650fb7b3e | ||
|
|
568d6a6441 | ||
|
|
630e86cd31 | ||
|
|
0e3e229434 | ||
|
|
f41d1cbcb0 | ||
|
|
20b653086d | ||
|
|
ae4cf35de4 | ||
|
|
86fc9a9746 | ||
|
|
1b4626d9ca | ||
|
|
7528b34ba3 | ||
|
|
ebecde1768 | ||
|
|
2301de6466 | ||
|
|
f7efad2480 | ||
|
|
c23bd01495 | ||
|
|
7e5986237a | ||
|
|
1bf26c95e3 | ||
|
|
3888e67d02 | ||
|
|
54e17321b6 | ||
|
|
90f56cfe61 | ||
|
|
44e33ad6f3 | ||
|
|
65d4e0c225 | ||
|
|
d37a374d02 | ||
|
|
5bb5e5ff29 | ||
|
|
de1f84d2aa | ||
|
|
aa35c0169c | ||
|
|
b53727842a | ||
|
|
f88e3d2ed4 | ||
|
|
eefda62d99 | ||
|
|
592446f714 | ||
|
|
3275a07325 | ||
|
|
1c2b9eee26 | ||
|
|
3a5533447b | ||
|
|
2fcd2d1a79 | ||
|
|
07d878be35 | ||
|
|
7a75d7874b | ||
|
|
99c3044218 | ||
|
|
fec5fb54bb | ||
|
|
031051f1f9 | ||
|
|
d432c398cf | ||
|
|
8eb44c26d2 | ||
|
|
3a76a3e920 | ||
|
|
52e80e7af6 | ||
|
|
1eac6a63d9 | ||
|
|
6e379042a0 | ||
|
|
8367195315 | ||
|
|
7de954958d | ||
|
|
a161924a7f | ||
|
|
9568f3a960 | ||
|
|
fdb24fdf33 | ||
|
|
3c0f935e99 | ||
|
|
826f4ff762 | ||
|
|
ed926139b8 | ||
|
|
cb23bfe1a4 | ||
|
|
ab7d355fe4 | ||
|
|
87ccc182f1 | ||
|
|
ff21d7c985 | ||
|
|
b69797ef51 | ||
|
|
f1614fe81a | ||
|
|
d5c9116dc7 | ||
|
|
5aaff59f71 | ||
|
|
a20ed66400 | ||
|
|
6312c2f3e0 | ||
|
|
2e2bd7d6c5 | ||
|
|
dd7de8fe08 | ||
|
|
934039bcd4 | ||
|
|
98efe9543d | ||
|
|
b68c0031a7 | ||
|
|
a587899976 | ||
|
|
4528f2aa0e | ||
|
|
b2e6f498be | ||
|
|
d32179009d | ||
|
|
c815318972 | ||
|
|
7cbb52094d | ||
|
|
7c8dfb520f | ||
|
|
6395adddb6 | ||
|
|
01a63f895c | ||
|
|
5d2ba5b21e | ||
|
|
6e4c0c1498 | ||
|
|
dce6b4183a | ||
|
|
1bf36592ef | ||
|
|
24d9218d14 | ||
|
|
9ee6c96a3a | ||
|
|
507307308d | ||
|
|
14d4268cc3 | ||
|
|
aade4453e1 | ||
|
|
232a635c06 | ||
|
|
545cf13584 | ||
|
|
b7ef781fda | ||
|
|
3f18a446af | ||
|
|
391bb20de2 | ||
|
|
aafac7821c | ||
|
|
103aef6cd6 | ||
|
|
6282459905 | ||
|
|
293132e6a4 | ||
|
|
0e4b193d70 | ||
|
|
277e452a73 | ||
|
|
80e96933b0 | ||
|
|
1ab4f8ff6c | ||
|
|
9a67581ad9 | ||
|
|
9ef34dd853 | ||
|
|
b37c173e07 | ||
|
|
105ac545b3 | ||
|
|
ae3f9aa353 | ||
|
|
3e9fca8a0d | ||
|
|
1a45054b5d | ||
|
|
be56290257 | ||
|
|
64195e095b | ||
|
|
5a33b3473e | ||
|
|
df23dc09e8 | ||
|
|
2a3ac1e6d0 | ||
|
|
bad8cde186 | ||
|
|
d9adcc2016 | ||
|
|
7b59a069ef | ||
|
|
310a2e47b6 | ||
|
|
954e302467 | ||
|
|
abb77b7c5f | ||
|
|
aaac78f985 | ||
|
|
e959c9ed59 | ||
|
|
1965110df9 | ||
|
|
1300249555 | ||
|
|
05a4ee230c | ||
|
|
78411de398 | ||
|
|
e697815c0c | ||
|
|
fbd22779ee | ||
|
|
b13c57ea35 | ||
|
|
0b38f2a91c | ||
|
|
db36397e81 | ||
|
|
066fd597da | ||
|
|
e979d2b45b | ||
|
|
4fa9f0d645 | ||
|
|
fecf6c6161 | ||
|
|
7eecba583d | ||
|
|
9c6111da3e | ||
|
|
f10882d14d | ||
|
|
0ac9e13948 | ||
|
|
fb3ef974a3 | ||
|
|
65522e4569 | ||
|
|
ae8961d43c | ||
|
|
c131a8cad8 | ||
|
|
7ad8ef8d18 | ||
|
|
539520903f | ||
|
|
566300a598 | ||
|
|
b64bbee4b4 | ||
|
|
8c005466c6 | ||
|
|
d222e01466 | ||
|
|
d692f616ba | ||
|
|
656ebde58c | ||
|
|
4973f9674a | ||
|
|
9fe3bf9ec0 | ||
|
|
074794830f | ||
|
|
1f4fd9f115 | ||
|
|
82ac10c7a5 | ||
|
|
505b9047ba | ||
|
|
735123749e | ||
|
|
df3c8f51d5 | ||
|
|
6de159fa7d | ||
|
|
119b190585 | ||
|
|
14c0be59dd | ||
|
|
fd2ae92663 | ||
|
|
a57b16504f | ||
|
|
ee36c1b9f3 | ||
|
|
928ec8b325 | ||
|
|
3d720f2c81 | ||
|
|
040c60a9ba | ||
|
|
2e874957fb | ||
|
|
3ed94986ed | ||
|
|
32f7561e26 | ||
|
|
dbaaa195b5 | ||
|
|
7f01e9beaa | ||
|
|
2e95cf6b25 | ||
|
|
23314507db | ||
|
|
cfbff5402c | ||
|
|
6c6c625273 | ||
|
|
a66560a255 | ||
|
|
5ff5fc8f0f | ||
|
|
f001b5bb7c | ||
|
|
403b8fcfc7 | ||
|
|
456625ae4b | ||
|
|
5dd9163610 | ||
|
|
3953b3328a | ||
|
|
124be6c37a | ||
|
|
6fc474ac09 | ||
|
|
49ccad694e | ||
|
|
370fa5eb8d | ||
|
|
df61f140ca | ||
|
|
b80b16d03f | ||
|
|
97c75c306f | ||
|
|
30258c7e75 | ||
|
|
e66feb5a27 | ||
|
|
972f2c2d6d | ||
|
|
fcf46c1588 | ||
|
|
cd38ed01a4 | ||
|
|
5f965e6378 | ||
|
|
d20bce81f0 | ||
|
|
d9e2397f48 | ||
|
|
6fe35c34be | ||
|
|
05924c5813 | ||
|
|
b931d7f3af | ||
|
|
5b970eb2c8 | ||
|
|
52b5bf2361 | ||
|
|
8eee21baf0 | ||
|
|
e99656704f | ||
|
|
235e5b7ddf | ||
|
|
69e7992f3e | ||
|
|
29bfddc8d2 | ||
|
|
3fc8a897a1 | ||
|
|
451e377cac | ||
|
|
6379b3ccf1 | ||
|
|
456f27c85b | ||
|
|
c739649f20 | ||
|
|
3dceb21bd5 | ||
|
|
23331930cc | ||
|
|
da48f49a25 | ||
|
|
3775f26458 | ||
|
|
365d3278ff | ||
|
|
7cc9742530 | ||
|
|
0648a9cbea | ||
|
|
7766276abc | ||
|
|
19bc2dd0e2 | ||
|
|
6126260aae | ||
|
|
cdd0bc52e2 | ||
|
|
ccf3ee8e7d | ||
|
|
54147bbddb | ||
|
|
914fa2da0f | ||
|
|
d41b14bbff | ||
|
|
354d2167fb | ||
|
|
9eb7c671cd | ||
|
|
aee7708cd1 | ||
|
|
e3f946ecf8 | ||
|
|
c25b6be1f3 | ||
|
|
eff69079a6 | ||
|
|
8d8d4cd5d0 | ||
|
|
4bce1234af | ||
|
|
d892f0b39d | ||
|
|
831e949d91 | ||
|
|
d48b9c217b | ||
|
|
124a66aaa9 | ||
|
|
08eb6841fc | ||
|
|
e74ac9fda5 | ||
|
|
d4bbcc3acc | ||
|
|
9655e113c0 | ||
|
|
54c7682f00 | ||
|
|
7c8efa1060 | ||
|
|
0caf2d7a43 | ||
|
|
533590656f | ||
|
|
fe0fa8a9ce | ||
|
|
a85b695c80 | ||
|
|
251a6b7e73 | ||
|
|
08b0d085db | ||
|
|
0b95f35a61 | ||
|
|
4073b7627d | ||
|
|
2c2b599528 | ||
|
|
eb86d6f1d0 | ||
|
|
2d74e441dc | ||
|
|
8145dea0d5 | ||
|
|
a4a217a223 | ||
|
|
cd023a99b5 | ||
|
|
a339e78135 | ||
|
|
1425414b4a | ||
|
|
a8e189408a | ||
|
|
fbb535d241 | ||
|
|
7d6fc09c24 | ||
|
|
00f62124af | ||
|
|
138be996db | ||
|
|
722b2b24b7 | ||
|
|
d90d68332f | ||
|
|
0470d984cc | ||
|
|
c001452abf | ||
|
|
b25378463c | ||
|
|
63d3a95529 | ||
|
|
1c1eb106d6 | ||
|
|
916d2515b0 | ||
|
|
caff7db0d4 | ||
|
|
85006b2c15 | ||
|
|
727c6c6467 | ||
|
|
12fc80c8b0 | ||
|
|
97ae3df30d | ||
|
|
3189043b7f | ||
|
|
9f01adfb25 | ||
|
|
5155e6510f | ||
|
|
37d99eb86f | ||
|
|
014e9354ce | ||
|
|
c8ecab6d78 | ||
|
|
2e7e10aaae | ||
|
|
9f197074ef | ||
|
|
5b054761cf | ||
|
|
be3ae6bd0d | ||
|
|
71980aafeb | ||
|
|
d1c20ed325 | ||
|
|
16f559cd70 | ||
|
|
d0dc6188cd | ||
|
|
e79f6c49a4 | ||
|
|
4ec11f8359 | ||
|
|
52c1780f79 | ||
|
|
c6becb9995 | ||
|
|
194efab1f6 | ||
|
|
34af7a4899 | ||
|
|
2b6c699828 | ||
|
|
e376b972fe | ||
|
|
445a04b9d6 | ||
|
|
4283b2489d | ||
|
|
c6e21b9ed1 | ||
|
|
c61a94495f | ||
|
|
99049d156a | ||
|
|
f8d331fc8b | ||
|
|
667a883fb0 | ||
|
|
2bd1719637 | ||
|
|
d9d62dec6b | ||
|
|
f3fdd45019 | ||
|
|
ded1cd6b06 | ||
|
|
854dcf48b2 | ||
|
|
0916fa38e2 | ||
|
|
c590f5102c | ||
|
|
9bda5b7941 | ||
|
|
ebba92368a | ||
|
|
3e5df92223 | ||
|
|
2d17071c8c | ||
|
|
38d4bff7f4 | ||
|
|
fc5434cb3d | ||
|
|
3c0e545661 | ||
|
|
c0f758ba9b | ||
|
|
e96dd94ee9 | ||
|
|
8a913d075d | ||
|
|
bbaf3a05b3 | ||
|
|
61c4f8861f | ||
|
|
1e7c51a2cb | ||
|
|
21620917f7 | ||
|
|
cc65055f3c | ||
|
|
71fab0ca94 | ||
|
|
b272e812d0 | ||
|
|
cb9092492f | ||
|
|
0a79020e59 | ||
|
|
4e4fa960b6 | ||
|
|
c28fddb4f6 | ||
|
|
e36587f61a | ||
|
|
40c53cf27b | ||
|
|
09c78a1cee | ||
|
|
b2d9e5ab73 | ||
|
|
a630c1a161 | ||
|
|
1771330890 | ||
|
|
02fed86851 | ||
|
|
46ae248056 | ||
|
|
5730a3be09 | ||
|
|
462df0032e | ||
|
|
d058a99874 | ||
|
|
2399cc25ca | ||
|
|
c7fe39bf21 | ||
|
|
a5bf4c64bb | ||
|
|
3fd97ea471 | ||
|
|
3dae4dd155 | ||
|
|
a510740fa3 | ||
|
|
91ba9e7fd3 | ||
|
|
f3056d316f | ||
|
|
0e9f556994 | ||
|
|
b9727c9275 | ||
|
|
d649fb0d87 | ||
|
|
1aa8221931 | ||
|
|
cbb541f1a3 | ||
|
|
8b215d7425 | ||
|
|
52ef344ba4 | ||
|
|
44eff18b3e | ||
|
|
a0c8d47369 | ||
|
|
d19a0020fd | ||
|
|
5494ad911e | ||
|
|
5ead0975c1 | ||
|
|
34cd890cd9 | ||
|
|
329756d664 | ||
|
|
8ebc4f603f | ||
|
|
07bcdf220d | ||
|
|
2f71a011c3 | ||
|
|
e6244fc3f8 | ||
|
|
9eb713cefb | ||
|
|
714c0aa8c9 | ||
|
|
91a0aeec9d | ||
|
|
a28c1d4efe | ||
|
|
a6af12ae06 | ||
|
|
910b2ff187 | ||
|
|
64adbfaab6 | ||
|
|
d60b8d4b83 | ||
|
|
684fc221b1 | ||
|
|
cf96642db5 | ||
|
|
ab6628b1ab | ||
|
|
06beab3865 | ||
|
|
bd77f4400f | ||
|
|
deebb2be9a | ||
|
|
22c6cab910 | ||
|
|
ea771c80d1 | ||
|
|
861b97c4ff | ||
|
|
b1ffe7cfc2 | ||
|
|
852ea15dc2 | ||
|
|
45768a5bba | ||
|
|
76b5a83511 | ||
|
|
c0d1da781f | ||
|
|
1a80a7a8eb | ||
|
|
cd66661026 | ||
|
|
b88e4eea56 | ||
|
|
f64a0d199d | ||
|
|
5f47f49cf4 | ||
|
|
7a0c8d81f6 | ||
|
|
427efca6f8 | ||
|
|
54546185ab | ||
|
|
493f045764 | ||
|
|
fd79e98ed7 | ||
|
|
40bf5762bb | ||
|
|
c291991236 | ||
|
|
7cb9b97bfb | ||
|
|
eddbd9610e | ||
|
|
a66ebec28f | ||
|
|
cdad18194e | ||
|
|
17f69b2bbc | ||
|
|
84176e5e27 | ||
|
|
67a3b924e8 | ||
|
|
84c86873fb | ||
|
|
2a486a2939 | ||
|
|
0550128e1d | ||
|
|
ff867c9ba4 | ||
|
|
c5fada0a62 | ||
|
|
7316ae0ce4 | ||
|
|
c8919e9844 | ||
|
|
4e340466de | ||
|
|
2fceda6f09 | ||
|
|
2aa29fde8a | ||
|
|
a76b7c545a | ||
|
|
8178bf1380 | ||
|
|
63ca190a32 | ||
|
|
836d9fbae7 | ||
|
|
9df1c73641 | ||
|
|
1899efd209 | ||
|
|
9d90766592 | ||
|
|
bd9d3ee4c3 | ||
|
|
20fac6ab26 | ||
|
|
5be5a7d8e3 | ||
|
|
35f0192ecb | ||
|
|
69949d6257 | ||
|
|
94ad45d2b0 | ||
|
|
c62f6085f7 | ||
|
|
2a300a2ef6 | ||
|
|
a77a0f281d | ||
|
|
d794cd989b | ||
|
|
60c687f3f8 | ||
|
|
8da5d3a770 | ||
|
|
ead3e0bc22 | ||
|
|
a0c1f20fc3 | ||
|
|
8e6586d4e4 | ||
|
|
b2f4229f70 | ||
|
|
2425074855 | ||
|
|
7d53a8aedb | ||
|
|
a16617880f | ||
|
|
650431b8ce | ||
|
|
a6654b65a9 | ||
|
|
4f15ea9ed7 | ||
|
|
aa34532b33 | ||
|
|
3fe711a3ba | ||
|
|
93e2175435 | ||
|
|
5c61006d11 | ||
|
|
6da74af830 | ||
|
|
93ba67c405 | ||
|
|
04fed3d4d5 | ||
|
|
1ead6614ba | ||
|
|
887e63464d | ||
|
|
47e5d5e56e | ||
|
|
c505c1e88e | ||
|
|
6a8c04c031 | ||
|
|
33f68a7f41 | ||
|
|
c5af8676e5 | ||
|
|
618898cb09 | ||
|
|
36bdcc57d9 | ||
|
|
eb418c07f5 | ||
|
|
9a265fbbc3 | ||
|
|
cf32d6cf29 | ||
|
|
9d216e3dc2 | ||
|
|
9d387b3e80 | ||
|
|
1e6be2f26d | ||
|
|
e56f824cd2 | ||
|
|
d38014f4b5 | ||
|
|
b331062fa6 | ||
|
|
88df748451 | ||
|
|
5384197bd1 | ||
|
|
2b5d4b7fe9 | ||
|
|
c15d074488 | ||
|
|
b0c3aa71b9 | ||
|
|
32d85ffb55 | ||
|
|
59fcd61738 | ||
|
|
7ce969882d | ||
|
|
ee70cdb94f | ||
|
|
f21fce7730 | ||
|
|
c426c7b341 | ||
|
|
1231d1e0c2 | ||
|
|
66073aebb8 | ||
|
|
882d9e5709 | ||
|
|
ba9ec45d9e | ||
|
|
f2787a41ae | ||
|
|
3469523225 | ||
|
|
1dc9a07cb9 | ||
|
|
a34807e5c9 | ||
|
|
85ef33a720 | ||
|
|
3163c077a1 | ||
|
|
fbb446875d | ||
|
|
e8cdcabffe | ||
|
|
832813d40a | ||
|
|
e2f28bca7d | ||
|
|
3ed894688c | ||
|
|
bb7422d755 | ||
|
|
b2f3f4a6c7 | ||
|
|
f21794a253 | ||
|
|
ffa96e56a5 | ||
|
|
38e50dfe77 | ||
|
|
1d3ec2d5a3 | ||
|
|
495751433b | ||
|
|
de7d73eae9 | ||
|
|
f825cf9613 | ||
|
|
6e32056c26 | ||
|
|
85bc2aa8f9 | ||
|
|
d56de83368 | ||
|
|
065e65a31c | ||
|
|
a68980bc76 | ||
|
|
90880a00f3 | ||
|
|
675dd762a8 | ||
|
|
7cdd436b10 | ||
|
|
a78126c551 | ||
|
|
f729bf15c3 | ||
|
|
ce129703f8 | ||
|
|
c99bba90a4 | ||
|
|
914a8ed5fb | ||
|
|
85b95c189e | ||
|
|
8722bdc8cb | ||
|
|
2ce724cdd0 | ||
|
|
922b6b8534 | ||
|
|
a05f4b2e29 | ||
|
|
e4e32f3f9f | ||
|
|
bf0b864c0d | ||
|
|
4948c8bea1 | ||
|
|
9397bf4255 | ||
|
|
a6d85d7b0c | ||
|
|
16371443e8 | ||
|
|
5738d86988 | ||
|
|
e1bf3fbe94 | ||
|
|
7ce98408f4 | ||
|
|
1a7b219c40 | ||
|
|
8a8e93f3ca | ||
|
|
1d95d9afc2 | ||
|
|
5b49187cb7 | ||
|
|
7b99565636 | ||
|
|
32980d1476 | ||
|
|
490a6d974f | ||
|
|
4e971817a2 | ||
|
|
f649553727 | ||
|
|
3576a80872 | ||
|
|
2bbb9ffd8e | ||
|
|
7d2acae537 | ||
|
|
1e68587097 | ||
|
|
71d77ce6ab | ||
|
|
de849b69d4 | ||
|
|
a8e84995ea | ||
|
|
edffd47067 | ||
|
|
cef474955e | ||
|
|
00dffe7b57 | ||
|
|
fea79bd4f9 | ||
|
|
fb5d30f700 | ||
|
|
ab15b393d0 | ||
|
|
7d1cf12c48 | ||
|
|
14d8acc385 | ||
|
|
e91d639d93 | ||
|
|
3671873349 | ||
|
|
f920a3e954 | ||
|
|
cb35f1f319 | ||
|
|
c8805f5018 | ||
|
|
cc04be6790 | ||
|
|
13eb453c2a | ||
|
|
d20dfa9027 | ||
|
|
38429152f2 | ||
|
|
cf382e9890 | ||
|
|
81b1846fcd | ||
|
|
7d48a65ec1 | ||
|
|
dc50cdff15 | ||
|
|
165e615698 | ||
|
|
2559bef4ce | ||
|
|
7847a74104 | ||
|
|
685596c213 | ||
|
|
20862d3ee4 | ||
|
|
2527792b58 | ||
|
|
d85d307e30 | ||
|
|
58e01e96e1 | ||
|
|
1b425b83b6 | ||
|
|
96d7195365 | ||
|
|
e14af63a4c | ||
|
|
925f1a1f81 | ||
|
|
1e5e2b20dd | ||
|
|
d209718987 | ||
|
|
31619b26c9 | ||
|
|
2277c7410b | ||
|
|
90d8b088d2 | ||
|
|
a5d9588a7d | ||
|
|
ff17b1d857 | ||
|
|
2a5bd83bb8 | ||
|
|
aa7800ba37 | ||
|
|
8a1a1a9d91 | ||
|
|
e7b59f8a2f | ||
|
|
8e75655346 | ||
|
|
e45498a1d7 | ||
|
|
5f838ca2b4 | ||
|
|
85e53ce89f | ||
|
|
51c1cd3fe5 | ||
|
|
29c7db1980 | ||
|
|
663323cd1e | ||
|
|
ab13a6ec0e | ||
|
|
d78eb490cb | ||
|
|
48e724cb4b | ||
|
|
0a3db6c013 | ||
|
|
a843fad921 | ||
|
|
de41e3b058 | ||
|
|
6bf3a5aab4 | ||
|
|
8d4bc8c0bc | ||
|
|
76df322bb4 | ||
|
|
36cdd3cebb | ||
|
|
ca4587cb29 | ||
|
|
ce958ba798 | ||
|
|
7c5c0fea8c | ||
|
|
5bc557a5d2 | ||
|
|
e23a649c17 | ||
|
|
a5300ceab5 | ||
|
|
fdb405e52a | ||
|
|
79cdd26ef0 | ||
|
|
87c24c8f31 | ||
|
|
6216165515 | ||
|
|
77640d21be | ||
|
|
57282f4933 | ||
|
|
1a12e0dc11 | ||
|
|
2b0317d1f6 | ||
|
|
8fce706f31 | ||
|
|
ae0f3ab31d | ||
|
|
34cb438757 | ||
|
|
8747ba2c1d | ||
|
|
bef4e3c735 | ||
|
|
6396b8fdb7 | ||
|
|
e27ba4304d | ||
|
|
4c86e73c4e | ||
|
|
9f9fa8c444 | ||
|
|
9647116572 | ||
|
|
736891fbdd | ||
|
|
acec733af7 | ||
|
|
73cdc35c80 | ||
|
|
cae91b3565 | ||
|
|
ec610f4fbb | ||
|
|
edf9ba01bd | ||
|
|
e942252d9a | ||
|
|
04d1773c03 | ||
|
|
448899c193 | ||
|
|
23d1db4fd5 | ||
|
|
903d3ed452 | ||
|
|
1ad78ba9f6 | ||
|
|
82416a33cc | ||
|
|
e67b32d537 | ||
|
|
dbb6f9ace8 | ||
|
|
d2c69abb71 |
82
.github/workflows/gradle-build.yml
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
# This workflow will build a Java project with Gradle
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
name: Build
|
||||
on:
|
||||
push:
|
||||
branches: [ 1.3.x ]
|
||||
pull_request:
|
||||
branches: [ 1.3.x ]
|
||||
jobs:
|
||||
validation:
|
||||
name: "Gradle wrapper validation"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.3.5
|
||||
- uses: gradle/wrapper-validation-action@v1.0.4
|
||||
build:
|
||||
name: "Build and publish"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.3.5
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'temurin'
|
||||
- name: Cache SonarCloud packages
|
||||
uses: actions/cache@v2.1.6
|
||||
if: env.SONAR_TOKEN != null && env.SONAR_TOKEN != ''
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
with:
|
||||
path: ~/.sonar/cache
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
- name: Build
|
||||
id: gradle
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
arguments: check
|
||||
wrapper-cache-enabled: true
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
- name: "Comment build scan url"
|
||||
uses: actions/github-script@v5
|
||||
if: github.event_name == 'pull_request' && failure()
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
github.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: '❌ ${{ github.workflow }} failed: ${{ steps.gradle.outputs.build-scan-url }}'
|
||||
})
|
||||
- name: Publish Unit Test Results
|
||||
uses: EnricoMi/publish-unit-test-result-action/composite@v1
|
||||
if: always()
|
||||
with:
|
||||
files: '**/test-results/**/*.xml'
|
||||
- name: Analyze with SonarCloud
|
||||
continue-on-error: true
|
||||
if: env.SONAR_TOKEN != null && env.SONAR_TOKEN != ''
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
with:
|
||||
arguments: sonarqube -Psonar.organization=swagger2markup
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
- name: Publish to Sonatype
|
||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/1.3.x' }}
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USER }}
|
||||
ORG_GRADLE_PROJECT_sonatypePassword : ${{ secrets.SONATYPE_PASSWORD }}
|
||||
with:
|
||||
arguments: publishToSonatype
|
||||
dependencies-cache-enabled: true
|
||||
configuration-cache-enabled: true
|
||||
4
.gitignore
vendored
@@ -2,3 +2,7 @@
|
||||
*.iml
|
||||
.gradle
|
||||
build
|
||||
/bin/
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings/
|
||||
|
||||
17
.travis.yml
@@ -1,7 +1,18 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- openjdk8
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
|
||||
- ./gradlew publishGhPages -PgithubUser="${GITHUB_USER}" -PgithubPassword="${GITHUB_PASSWORD}"
|
||||
--stacktrace
|
||||
notifications:
|
||||
slack: swagger2markup:Zz5kz0SnvtG6aVvZUM8yMkER
|
||||
env:
|
||||
global:
|
||||
- secure: SPKolgUdjIa/uJ+7/B/GPFlsa8IZg7NuZdFA8zROTaqew/xu+oX7qVGImseeBpPIEPJb02ac6hr7Y3/zvv0GJxIPtIbyDzVh73ImQUhT1ttLYGJfITAWqAPFF7RNNMtuOl3S2DLZ5OMJddkcFp00pa9nyI82Gk47B8GsaGIntAI=
|
||||
- secure: nXXuHfvFACZwdiFM3Ta0x/f49N7cAgi0AMkgEnQrh/2xWlvQk2z2ySGJQLkhJ7Wy8LDY7Yt1b1GUt6DlP3PuFFMW/cT4iARewqiJRXZXxUQz8fpTDeTo1nmVmW/zzII6Qj3QHM3NRbR/xDOVSJiT30Hnq2hcCBQJWYsTICmzjRk=
|
||||
- secure: Ia/wJ572M2II76roFeGEVCzIiktG4v2j/reSn60fpk1gnoEPQEObL4j1dbVCgXBLz54YWcaQ3mICvOfBPPEl9IIV3Y6DDE2sBOmB3soznfdA/YVnJx0h0f1pfXu1dwqoiv1sgc1wewQuUWq+FV7xeDhFE3cnh9CXIexe9ykip8k=
|
||||
- secure: GWfhYDsHRmTfOuEOIcHY8kT4jKBTbdhNLDQ/2amY06xenFblb4pEn6pgmn4IdK3ytjNovnZPTOOK8HqdEjhbfIGoQt6PZwuyANn4Df+zdqOC0+V+7DFG2QhEhbRCyEwPlDqTPjxlOMfAmvjFuY/NvQywoF3PYUyMfJwUV8ehmYk=
|
||||
|
||||
5
ISSUE_TEMPLATE
Normal file
@@ -0,0 +1,5 @@
|
||||
Thanks for raising a Swagger2Markup issue. Please provide a brief description of your problem along with the Swagger2Markup version you are using. If possible, please also consider putting together a complete Swagger specification that reproduces the issue. It's better if the Swagger specification is small and isolate the issue.
|
||||
|
||||
Swagger2Markup version:
|
||||
|
||||
Problem description:
|
||||
242
README.adoc
@@ -1,213 +1,79 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.2.1
|
||||
:hardbreaks:
|
||||
|
||||
image:https://travis-ci.org/RobWin/swagger2markup.svg["Build Status", link="https://travis-ci.org/RobWin/swagger2markup"] image:https://coveralls.io/repos/RobWin/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/swagger2markup"] image:https://api.bintray.com/packages/robwin/maven/swagger2markup/images/download.svg[link="https://bintray.com/robwin/maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
image:https://travis-ci.org/Swagger2Markup/swagger2markup.svg?branch=master["Build Status", link="https://travis-ci.org/Swagger2Markup/swagger2markup"] image:https://coveralls.io/repos/Swagger2Markup/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/Swagger2Markup/swagger2markup"] image:https://api.codacy.com/project/badge/grade/498a6a39d7d84ff687546359f58ee18d["Codacy code quality", link="https://www.codacy.com/app/robwin/swagger2markup"] image:https://api.bintray.com/packages/swagger2markup/Maven/swagger2markup/images/download.svg[link="https://bintray.com/swagger2markup/Maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
|
||||
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Swagger to Markup (AsciiDoc and Markdown) converter. The *Swagger2MarkupConverter* takes a swagger.json or swagger.yaml file as source and converts it into an AsciiDoc or Markdown document. The Swagger source file can be located locally or remotely accessible via HTTP. The Swagger2MarkupConverter supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
|
||||
The primary goal of this project is to simplify the documentation of RESTful APIs. The result is intended to be an easy-to-read, on- and offline user guide, comparable to https://developer.github.com/v3/[GitHub's API documentation].
|
||||
Swagger2Markup can be used together with https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See <<integration-with-spring-restdocs, Integration with spring-restdocs>>.
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
== Usage
|
||||
|
||||
=== Adding Swagger2Markup to your project
|
||||
The project is published in JCenter and Maven Central.
|
||||
|
||||
==== Maven
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
==== Gradle
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:swagger2markup:0.2.1"
|
||||
----
|
||||
|
||||
=== Using Swagger2Markup
|
||||
|
||||
Using the Swagger2MarkupConverter is simple. For instance, you can generate your AsciiDoc/Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/martypitt/swagger-springmvc[swagger-springmvc] as follows.
|
||||
See demo project https://github.com/RobWin/spring-swagger2markup-demo[spring-swagger2markup-demo].
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootSwaggerConfig.class)
|
||||
@IntegrationTest
|
||||
@WebAppConfiguration
|
||||
public class Swagger2MarkupTest {
|
||||
|
||||
@Test
|
||||
public void convertSwaggerToMarkup() {
|
||||
//Remote Swagger source
|
||||
//Markdown
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
|
||||
//Remote Swagger source
|
||||
//Default is AsciiDoc
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
|
||||
//Local Swagger source
|
||||
//Default is AsciiDoc
|
||||
File file = new File(Swagger2MarkupTest.class.getResource("/json/swagger.json").getFile());
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@EnableSwagger
|
||||
public class SpringBootSwaggerConfig {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootTestConfig.class, args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SpringSwaggerConfig springSwaggerConfig;
|
||||
|
||||
@Bean
|
||||
public SwaggerSpringMvcPlugin customImplementation(){
|
||||
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
|
||||
.apiInfo(apiInfo()).excludeAnnotations(Controller.class);
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"My Apps API Title",
|
||||
"My Apps API Description",
|
||||
"My Apps API terms of service",
|
||||
"My Apps API Contact Email",
|
||||
"My Apps API Licence Type",
|
||||
"My Apps API License URL"
|
||||
);
|
||||
return apiInfo;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
You can generate your HTML5 and PDF documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/aalmiray/markdown-gradle-plugin[markdown-gradle-plugin].
|
||||
You can also use https://github.com/tomchristie/mkdocs[MkDocs] and https://github.com/rtfd/readthedocs.org[ReadTheDocs] to publish your Markdown documentation.
|
||||
See http://spring-swagger2markup-demo.readthedocs.org/[ReadTheDocs-demo]
|
||||
|
||||
== Examples
|
||||
== Swagger source file
|
||||
image::images/swagger_json.PNG[swagger_json]
|
||||
|
||||
=== Generated AsciiDoc file
|
||||
image::images/asciidoc.PNG[asciidoc]
|
||||
|
||||
=== Generated Markdown file
|
||||
image::images/markdown.PNG[markdown]
|
||||
|
||||
=== Generated HTML using AsciidoctorJ
|
||||
image::images/asciidoc_html.PNG[asciidoc_html]
|
||||
|
||||
=== Generated HTML using Mkdocs
|
||||
image::images/mkdocs_html.PNG[mkdocs_html]
|
||||
|
||||
=== Generated PDF using AsciidoctorJ
|
||||
image::images/asciidoc_pdf.PNG[asciidoc_pdf]
|
||||
NOTE: Dear community,
|
||||
unfortunately I can't maintain Swagger2Markup alone anymore. There are many interesting new topics:
|
||||
1) Swagger v3 support
|
||||
2) Fixing bugs
|
||||
2) Merge Swagger2Markup repositories and create a new multi-module repository.
|
||||
Any help is welcome.
|
||||
Kind regards,
|
||||
Robert
|
||||
|
||||
|
||||
== Integration with spring-restdocs
|
||||
https://github.com/spring-projects/spring-restdocs[spring-restdocs] can be used together with Swagger2Markup.
|
||||
Swagger2Markup can include the generated examples from spring-restdocs into the generated AsciiDoc document.
|
||||
Currently it does not work for Markdown, since spring-restdocs generates only AsciiDoc files.
|
||||
The primary goal of this project is to *simplify the generation of an up-to-date RESTful API documentation by combining documentation that's been hand-written with auto-generated API documentation* produced by https://github.com/swagger-api[Swagger]. The result is intended to be an *up-to-date, easy-to-read, on- and offline user guide*, comparable to https://developer.github.com/v3/[GitHub's API documentation]. The output of Swagger2Markup can be used as an alternative to https://github.com/swagger-api/swagger-ui[swagger-ui] and can be served as static content.
|
||||
NOTE: The Swagger Specification has been donated to to the https://openapis.org/[Open API Initiative (OAI)] and has been renamed to the https://github.com/OAI/OpenAPI-Specification[OpenAPI Specification].
|
||||
|
||||
Let's say I have a Swagger-annotated Spring RestController method with an ApiOperation value: _"Create a quota"_
|
||||
Swagger2Markup converts a Swagger JSON or YAML file into several *AsciiDoc* or *GitHub Flavored Markdown* documents which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely via HTTP. Swagger2Markup supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ApiOperation(value = "Create a quota", notes = "Create a quota allows bla bla bla bla")
|
||||
public void createMailStorageQuota(@ApiParam(name = "MailStorageQuota",
|
||||
value = "MailStorageQuota", required = true) @RequestBody MailStorageQuota mailStorageQuota) {
|
||||
}
|
||||
----
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
I'm using spring-restdocs in combination with https://github.com/jayway/rest-assured to test the Controller.
|
||||
The target folder of the generated request and response example files must be _"create_a_quota"_ (similar to the value of the ApiOperation).
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to *HTML*, *PDF* and *EPUB*. AsciiDoc is much better suited for describing public APIs than *JavaDoc* or *Annotations*.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
given().contentType(ContentType.XML).body(storageQuota).resultHandlers(document("create_a_quota")).
|
||||
when().put("/quotas").
|
||||
then().statusCode(204);
|
||||
----
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin].
|
||||
|
||||
The spring-restdocs output directory is configured as follows:
|
||||
The project requires at least JDK 8.
|
||||
|
||||
[source]
|
||||
----
|
||||
io.restdocumented.outputDir = docs/generated
|
||||
----
|
||||
== Example
|
||||
|
||||
The Swagger2MarkupConverter must know the output directory of spring-restdocs.
|
||||
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup.PNG[]
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withExamples("docs/generated").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
----
|
||||
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
|
||||
|
||||
The Swagger2MarkupConverter searches for a Swagger ApiOperation with value: _"Create a quota"_ in a folder called _"docs/generated/create_a_quota"_ and includes the _request.asciidoc_ and _response.asciidoc_ files, if they are available.
|
||||
== Reference documentation
|
||||
- http://swagger2markup.github.io/swagger2markup/1.3.4/[Reference Documentation]
|
||||
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
|
||||
- https://github.com/Swagger2Markup/spring-swagger2markup-demo[Demo using Swagger2Markup, Spring Boot, Springfox and spring-restdocs]
|
||||
|
||||
== Integration of JSON and XML Schema files.
|
||||
Swagger2Markup can also include JSON and XML Schema files into the generated document.
|
||||
== Contributing
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).
|
||||
withExamples("docs/generated").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
----
|
||||
=== Community contributions
|
||||
|
||||
I create the Schemas files in Unit-Tests as follows:
|
||||
Pull requests are welcome.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
RestDocumented restDocumented = RestDocumented.fromProperties();
|
||||
restDocumented.documentJsonSchema(MailStorageQuota.class, "docs/schemas");
|
||||
restDocumented.documentXmlSchema(MailStorageQuota.class, "docs/schemas");
|
||||
----
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
I will make RestDocumented public soon. RestDocumented creates a MailStorageQuota.xsd and MailStorageQuota.json file in the folder "docs/schemas".
|
||||
The Swagger2MarkupConverter will include the JSON and XML Schemas, if a Swagger Operation uses the MailStorageQuota class as Input or Output.
|
||||
=== Bugs
|
||||
If you believe you have found a bug, please take a moment to search the existing issues. If no one else has reported the problem, please open a new issue that describes the problem in detail and, ideally, includes a test that reproduces it.
|
||||
|
||||
See example: http://spring-swagger2markup-demo.readthedocs.org/en/latest/generated/definitions/[ReadTheDocs-demo]
|
||||
=== Enhancements
|
||||
If you’d like an enhancement to be made to Swagger2Markup, pull requests are most welcome. The source code is on GitHub. You may want to search the existing issues and pull requests to see if the enhancement is already being worked on. You may also want to open a new issue to discuss a possible enhancement before work on it begins.
|
||||
|
||||
== Companies who use Swagger2Markup
|
||||
|
||||
* Deutsche Telekom AG
|
||||
* https://restlet.com/[Restlet] -- Restlet offers an API platform, covering the https://restlet.com/products/restlet-studio/[design], https://restlet.com/products/dhc/[test] and https://restlet.com/products/apispark/[operation] of Web APIs, and uses Swagger2Markup to generate appealing HTML documentation from API definitions.
|
||||
* http://www.qaware.de/[QAware GmbH]
|
||||
* http://www.appdirect.com/[AppDirect] -- The leading commerce platform for selling cloud services.
|
||||
* http://www.wescale.com[wescale]
|
||||
* http://taskassure.com[TaskAssure]
|
||||
* https://www.isaac.nl[ISAAC]
|
||||
* https://www.spreadshirt.de[Spreadshirt]
|
||||
|
||||
== License
|
||||
|
||||
Copyright 2015 Robert Winkler
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
@@ -1,10 +1,172 @@
|
||||
= Release Notes
|
||||
|
||||
== Version 0.1.0
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
== Version 0.2.0
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
= Release Notes
|
||||
|
||||
== Version 0.1.0
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
=== Version 0.1.1
|
||||
* Signed jar files
|
||||
|
||||
=== Version 0.1.2
|
||||
* Removed logback from compile dependency
|
||||
|
||||
=== Version 0.1.3
|
||||
* Removed commons.io from compile dependency
|
||||
|
||||
=== Version 0.1.4
|
||||
* Fixed SECTION_TITLE_LEVEL3 in Markdown enum
|
||||
|
||||
=== Version 0.1.5
|
||||
* Added SECTION_TITLE_LEVEL4
|
||||
|
||||
== Version 0.2.0
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
|
||||
=== Version 0.2.2
|
||||
* Fixed wrong dependency version to io.github.robwin:markup-document-builder
|
||||
|
||||
=== Version 0.2.3
|
||||
* Fixed issue #7: @ApiModelProperty metadata are ignored for definitions file
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
|
||||
== Version 0.3.0
|
||||
* Support of YAML or JSON String as input.
|
||||
|
||||
== Version 0.4.0
|
||||
* Updated Swagger-Parser from 1.0.0 to 1.0.5
|
||||
* Updated commons-lang to commons-lang3
|
||||
* Swagger2MarkupConverter generates three documents now: overview, paths and definitions
|
||||
* Support for enums in HeaderParameter, QueryParameter, FormParameter and QueryParameter
|
||||
* Support for global consumes, produces and tags
|
||||
|
||||
== Version 0.5.0
|
||||
* Support for including hand-written descriptions instead of using Swagger Annotations for descriptions
|
||||
|
||||
=== Version 0.5.1
|
||||
* Bugfix: Definition name must be lowercase so that descriptions file can be found
|
||||
|
||||
=== Version 0.5.2
|
||||
* Swagger License is not mandatory anymore
|
||||
* Updated markup-document-builder from v0.1.3 to v0.1.4
|
||||
|
||||
=== Version 0.5.3
|
||||
* Fixed compiler warning: [options] bootstrap class path not set in conjunction with -source 1.7
|
||||
|
||||
== Version 0.6.0
|
||||
* Updated swagger-parser from v1.0.5 to v1.0.6
|
||||
* Support for default values in Parameters and Model properties
|
||||
|
||||
=== Version 0.6.1
|
||||
* Updated swagger-parser from v1.0.6 to v1.0.8
|
||||
|
||||
=== Version 0.6.2
|
||||
* curl-request.adoc from spring-restdocs is also added to the example chapters
|
||||
|
||||
=== Version 0.6.3
|
||||
* Added possibility to write object definitions to separate files. Issue #19
|
||||
|
||||
== Version 0.7.0
|
||||
* Added support for both reference models and composed models
|
||||
|
||||
=== Version 0.7.1
|
||||
* Workaround: If the type of a BodyParameter is String and not a Model, the schema is null and lost. Therefore the fallback type of a BodyParameter is String now.
|
||||
|
||||
== Version 0.8.0
|
||||
* Enhancement #26 and #27: Added a pre-process hook to modify a Swagger Model before it is converted.
|
||||
* Bugfix #29: Tags are rendered twice
|
||||
|
||||
== Version 0.9.0
|
||||
* Updated swagger-parser from v1.0.8 to v1.0.13
|
||||
* Support for global responses and parameters
|
||||
|
||||
=== Version 0.9.1
|
||||
* Added support to group the paths by tags or as-is
|
||||
* Added support to order the definitions by natural ordering or as-is
|
||||
|
||||
=== Version 0.9.2
|
||||
* Multi language support. Added russian.
|
||||
|
||||
=== Version 0.9.3
|
||||
* Updated swagger-parser from v1.0.13 to v1.0.16
|
||||
* Enhancement #61: Refactor separated documents logic to support inter-document cross-references
|
||||
* Enhancement #53: Support for tags, paths and methods ordering
|
||||
* Enhancement #51: Support for separated operations files
|
||||
* Enhancement #52: Markdown generation for inline schemas
|
||||
|
||||
== Version 1.0.0
|
||||
* New configuration API
|
||||
* New extension SPI
|
||||
* Added new languages: turkish, german, france
|
||||
* New security document
|
||||
* Inline schema support
|
||||
* New configuration options
|
||||
* Support of deprecated path operations
|
||||
|
||||
=== Version 1.0.1
|
||||
* Enhancement: Support to render validation constraints of properties
|
||||
* Enhancement: Possibility to disable rendering of the security chapter below operations
|
||||
|
||||
== Version 1.1.0
|
||||
* PR #177: Fixed rendering of recursive examples
|
||||
* PR #186: Add support for Chinese language
|
||||
* PR #190: Add support for Spanish language
|
||||
* PR #192: Updated min/max value to format correctly based on the data type
|
||||
* PR #193: Added support for exclusiveMin and exclusiveMax
|
||||
* Changed bold to ** and italic to __ so that special chars in the text are possible
|
||||
|
||||
=== Version 1.1.1
|
||||
* Issue #194: Added a config parameter which allows to prepend the basePath to all paths.
|
||||
* Updated swagger-parser from v1.0.16 to v1.0.23
|
||||
* Added javslang v2.0.4 as a dependency
|
||||
* Added paleo-core v0.10.1 as a dependency
|
||||
* Updated markup-document-builder from 1.0.0 to 1.1.0
|
||||
* PR #201: Add support for Brazilian Portuguese language
|
||||
* PR #202: Add support for Japanese language
|
||||
* Issue #205: Fixed the option to influence resource ordering
|
||||
* Issue #198: Chinese chinese language encoding
|
||||
* Issue #207: Properties that start with an underscore are displayed correctly now
|
||||
* Refactored Swagger2Markup to use a Component-Based design. A document can be composed of components and components can be composed of other components.
|
||||
* Added a method to add page breaks.
|
||||
|
||||
== Version 1.1.2
|
||||
* Improve code blocks in markdown
|
||||
|
||||
== Version 1.2.0
|
||||
* Issue #214: Add page break locations
|
||||
* Issue #223: Improve example rendering
|
||||
* Issue #215: Add ability to group operations by RegEx
|
||||
* Added new configuration options: pageBreakLocations, headerRegex
|
||||
* Added new valid value for configuration headerRegex: REGEX
|
||||
* Updated markup-document-builder from 1.1.0 to 1.1.1
|
||||
|
||||
== Version 1.3.0
|
||||
* Updated javslang from 2.0.4 to 2.0.5
|
||||
* Updated paleo-core from 0.10.1 to 0.10.2
|
||||
* Updated swagger-parser from v1.0.23 to v1.0.25
|
||||
* Decimal numbers are formatted into locale-specific strings
|
||||
|
||||
=== Version 1.3.1
|
||||
* PR #247: Fix request path and query params example support.
|
||||
|
||||
=== Version 1.3.2
|
||||
* PR #290: Fixed list parsing in properties file
|
||||
* PR #293: Fixed crash on empty tables
|
||||
* Updated markup-document-builder from 1.1.1 to 1.1.2
|
||||
|
||||
=== Version 1.3.3
|
||||
* Updated swagger-parser from v1.0.25 to 1.0.35
|
||||
* PR #294: Examples always start with a newline if there is other content in the same cell
|
||||
* PR 307: Include required parameters in example request
|
||||
|
||||
=== Version 1.3.4
|
||||
* Moved from bintray to Sonatype
|
||||
* Introduced Github actions
|
||||
* Certain bug fixes
|
||||
* Added support for MIME types with structured syntax suffixes (#410)
|
||||
|
||||
|
||||
|
||||
188
build.gradle
@@ -1,105 +1,117 @@
|
||||
buildscript {
|
||||
plugins {
|
||||
id "org.sonarqube" version "2.7"
|
||||
id "me.champeau.gradle.jmh" version "0.4.8"
|
||||
id 'org.asciidoctor.convert' version '1.6.0'
|
||||
id "org.ajoberstar.github-pages" version "1.7.2"
|
||||
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
|
||||
}
|
||||
apply plugin: 'idea'
|
||||
apply from: "${rootDir}/libraries.gradle"
|
||||
|
||||
ext {
|
||||
releaseVersion = '1.3.4'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'me.champeau.gradle.jmh'
|
||||
|
||||
version = '1.3.4'
|
||||
group 'io.github.swagger2markup'
|
||||
description = 'swagger2markup Build'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.2'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.4.0.RELEASE'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.2.1'
|
||||
group = 'io.github.robwin'
|
||||
//artifactoryPublish.skip = true // apply to all projects except the root
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply from: 'gradle/publishing.gradle'
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = "1.7"
|
||||
targetCompatibility = "1.7"
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs << "-Xlint:unchecked"
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.github.robwin:markup-document-builder'
|
||||
compile 'io.swagger:swagger-compat-spec-parser'
|
||||
compile 'commons-collections:commons-collections'
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'junit:junit'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"io.github.robwin:markup-document-builder" "0.1.0"
|
||||
"io.swagger:swagger-compat-spec-parser" "1.0.0"
|
||||
"commons-collections:commons-collections" "3.2.1"
|
||||
"commons-io:commons-io" "2.4"
|
||||
"com.mangofactory:swagger-springmvc" "0.9.5"
|
||||
"com.jayway.restassured:spring-mock-mvc" "2.4.0"
|
||||
"ch.qos.logback:logback-classic" "1.1.2"
|
||||
"junit:junit" "4.11"
|
||||
ext {
|
||||
coreProjects = subprojects.findAll {
|
||||
p -> !p.name.endsWith("-bom")
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
configure(project.coreProjects) {
|
||||
apply plugin: 'signing'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'maven-publish'
|
||||
apply from: "${rootDir}/publishing.gradle"
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '2',
|
||||
numbered: ''
|
||||
]
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = "11"
|
||||
targetCompatibility = "11"
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs += ["-Xlint:unchecked", "-parameters"]
|
||||
}
|
||||
tasks.withType(Javadoc){
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
jmh {
|
||||
duplicateClassesStrategy = 'warn'
|
||||
}
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
failOnVersionConflict()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
nexusPublishing {
|
||||
repositories {
|
||||
sonatype()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.asciidoctor {
|
||||
dependsOn 'check'
|
||||
sonarqube {
|
||||
properties {
|
||||
property "sonar.host.url", "https://sonarcloud.io"
|
||||
property "sonar.organization", "swagger2markup"
|
||||
property "sonar.projectName", "swagger2markup"
|
||||
property "sonar.projectKey", "Swagger2Markup_swagger2markup"
|
||||
property "sonar.links.homepage", "https://github.com/Swagger2Markup/swagger2markup"
|
||||
property "sonar.links.ci", "https://travis-ci.org/Swagger2Markup/swagger2markup"
|
||||
property "sonar.links.scm", "https://github.com/Swagger2Markup/swagger2markup"
|
||||
property "sonar.links.issue", "https://github.com/Swagger2Markup/swagger2markup/issues"
|
||||
property "sonar.language", "java"
|
||||
}
|
||||
}
|
||||
def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"
|
||||
|
||||
task jacocoMergeTest(type: JacocoMerge) {
|
||||
destinationFile = file(allTestCoverageFile)
|
||||
executionData = project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
}
|
||||
task jacocoMerge(dependsOn: ['jacocoMergeTest']) {
|
||||
// used to run the other merge tasks
|
||||
}
|
||||
|
||||
subprojects {
|
||||
sonarqube {
|
||||
properties {
|
||||
property "sonar.jacoco.reportPaths", allTestCoverageFile
|
||||
}
|
||||
}
|
||||
afterEvaluate {
|
||||
// exclude subprojects that don't produce a jar file or by design.
|
||||
if (!project.name.equals('swagger2markup-bom') && !project.name.equals('swagger2markup-documentation')) {
|
||||
jar {
|
||||
inputs.property('moduleName', moduleName)
|
||||
manifest.attributes(
|
||||
'Automatic-Module-Name': moduleName
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.check.dependsOn tasks.jacocoTestReport
|
||||
|
||||
test {
|
||||
dependsOn(subprojects.test) // required by cobertura to aggregate report
|
||||
}
|
||||
|
||||
2
gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
systemProp.file.encoding=UTF-8
|
||||
systemProp.sun.jnu.encoding=UTF-8
|
||||
@@ -1,91 +0,0 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
Date buildTimeAndDate = new Date()
|
||||
ext {
|
||||
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
|
||||
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
|
||||
}
|
||||
|
||||
def projectArtifactId = 'swagger2markup'
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Built-By': 'Robert Winkler',
|
||||
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
|
||||
'Build-Date': project.buildDate,
|
||||
'Build-Time': project.buildTime,
|
||||
'Specification-Title': projectArtifactId,
|
||||
'Specification-Version': project.version,
|
||||
'Implementation-Title': projectArtifactId,
|
||||
'Implementation-Version': project.version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = ''
|
||||
if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = ''
|
||||
if (!project.hasProperty('gpgPassphrase')) ext.gpgPassphrase = ''
|
||||
if (!project.hasProperty('ossUser')) ext.ossUser = ''
|
||||
if (!project.hasProperty('ossPassword')) ext.ossPassword = ''
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = 'swagger2markup'
|
||||
websiteUrl = 'https://github.com/RobWin/swagger2markup'
|
||||
issueTrackerUrl = 'https://github.com/RobWin/swagger2markup/issues'
|
||||
vcsUrl = 'https://github.com/RobWin/swagger2markup.git'
|
||||
desc = 'A Swagger to Markup (AsciiDoc and Markdown) converter.'
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = project.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler']
|
||||
def root = asNode()
|
||||
root.appendNode('name', 'swagger2markup')
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/swagger2markup')
|
||||
root.appendNode('description', 'A Swagger to Markup (AsciiDoc and Markdown) converter.')
|
||||
|
||||
def license = root.appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', 'https://github.com/RobWin/swagger2markup/blob/master/LICENSE.txt')
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/swagger2markup.git')
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
def d = developers.appendNode('developer')
|
||||
d.appendNode('id', it.key)
|
||||
d.appendNode('name', it.value)
|
||||
}
|
||||
}
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Fri Feb 13 13:57:45 CET 2015
|
||||
#Mon Oct 21 16:35:38 BST 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
|
||||
|
||||
110
gradlew
vendored
Normal file → Executable file
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,47 +6,6 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@@ -90,7 +89,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@@ -114,6 +113,7 @@ fi
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
@@ -154,11 +154,19 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
174
gradlew.bat
vendored
@@ -1,90 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
||||
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 26 KiB |
52
libraries.gradle
Normal file
@@ -0,0 +1,52 @@
|
||||
// Allows centralized definition of the version of artifacts to
|
||||
// use. In that respect it serves a role similar to <dependencyManagement> in Maven
|
||||
ext {
|
||||
implLibraries = [:]
|
||||
testLibraries = [:]
|
||||
dependencyOverrides = [:]
|
||||
}
|
||||
implLibraries = [
|
||||
asciiDocJApi : "org.asciidoctor:asciidoctorj-api:2.2.0",
|
||||
commonsBeanUtils : "commons-beanutils:commons-beanutils:1.9.4",
|
||||
commonsCodec : "commons-codec:commons-codec:1.13",
|
||||
commonsCollections4: "org.apache.commons:commons-collections4:4.4",
|
||||
commonsConf2 : "org.apache.commons:commons-configuration2:2.6",
|
||||
commonsLang3 : "org.apache.commons:commons-lang3:3.9",
|
||||
commonsIO : "commons-io:commons-io:2.6",
|
||||
commonsText : "org.apache.commons:commons-text:1.8",
|
||||
guava : 'com.google.guava:guava:27.0.1-android',
|
||||
jacksonDatabind : 'com.fasterxml.jackson.core:jackson-databind:2.9.10',
|
||||
mark2Ascii : "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.1",
|
||||
paleo : "ch.netzwerg:paleo-core:0.14.0",
|
||||
pegdown : "org.pegdown:pegdown:1.6.0",
|
||||
slf4j : "org.slf4j:slf4j-api:1.7.28",
|
||||
swaggerV2 : "io.swagger:swagger-parser:1.0.47",
|
||||
swaggerV2Converter : "io.swagger.parser.v3:swagger-parser-v2-converter:2.0.15",
|
||||
swaggerV3 : "io.swagger.parser.v3:swagger-parser:2.0.15",
|
||||
vavr : "io.vavr:vavr:0.10.2"
|
||||
]
|
||||
|
||||
testLibraries = [
|
||||
asciiDocJ : "org.asciidoctor:asciidoctorj:2.2.0",
|
||||
assertj : "org.assertj:assertj-core:3.13.2",
|
||||
assertjDiff: "io.github.robwin:assertj-diff:0.1.1",
|
||||
junit : "junit:junit:4.12",
|
||||
logback : "ch.qos.logback:logback-classic:1.2.3",
|
||||
mockito : "org.mockito:mockito-core:3.1.0"
|
||||
]
|
||||
|
||||
dependencyOverrides = [
|
||||
assertj : testLibraries.assertj,
|
||||
commonsCodec : implLibraries.commonsCodec,
|
||||
commonsIO : implLibraries.commonsIO,
|
||||
commonsLang3 : implLibraries.commonsLang3,
|
||||
findBugs : 'com.google.code.findbugs:jsr305:3.0.2',
|
||||
guava : implLibraries.guava,
|
||||
jaksonCore : 'com.github.fge:jackson-coreutils:1.8',
|
||||
jacksonDatabind: implLibraries.jacksonDatabind,
|
||||
jnrConstants : 'com.github.jnr:jnr-constants:0.9.12',
|
||||
jnrEnxio : 'com.github.jnr:jnr-enxio:0.19',
|
||||
jnrPosix : 'com.github.jnr:jnr-posix:3.0.49',
|
||||
jodaTime : 'joda-time:joda-time:2.9.9',
|
||||
slf4j : implLibraries.slf4j,
|
||||
]
|
||||
91
publishing.gradle
Normal file
@@ -0,0 +1,91 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
Date buildTimeAndDate = new Date()
|
||||
ext {
|
||||
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
|
||||
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
|
||||
licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
|
||||
scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
}
|
||||
|
||||
def projectArtifactId = 'swagger2markup'
|
||||
def projectUrl = 'https://github.com/Swagger2Markup/swagger2markup'
|
||||
def licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
|
||||
def scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
def issuesUrl = 'https://github.com/Swagger2Markup/swagger2markup/issues'
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Built-By': 'Robert Winkler',
|
||||
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
|
||||
'Build-Date': project.buildDate,
|
||||
'Build-Time': project.buildTime,
|
||||
'Specification-Title': projectArtifactId,
|
||||
'Specification-Version': project.version,
|
||||
'Implementation-Title': projectArtifactId,
|
||||
'Implementation-Version': project.version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.allJava
|
||||
archiveClassifier = 'sources'
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
from javadoc
|
||||
archiveClassifier = 'javadoc'
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler',
|
||||
'austek': 'Ali Ustek']
|
||||
def root = asNode()
|
||||
|
||||
root.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
}.each() {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', projectArtifactId)
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', projectUrl)
|
||||
root.appendNode('description', project.description)
|
||||
|
||||
def license = root.appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', licenseUrl)
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
root.appendNode('scm').appendNode('url', scmUrl)
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
def d = developers.appendNode('developer')
|
||||
d.appendNode('id', it.key)
|
||||
d.appendNode('name', it.value)
|
||||
}
|
||||
}
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1,9 @@
|
||||
rootProject.name = 'swagger2markup'
|
||||
rootProject.name = 'swagger2markup'
|
||||
|
||||
include 'swagger2markup-asciidoc'
|
||||
include 'swagger2markup-bom'
|
||||
include 'swagger2markup-builder'
|
||||
include 'swagger2markup-documentation'
|
||||
include 'swagger2markup'
|
||||
include 'swagger2markup-core'
|
||||
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.builder.document.DefinitionsDocument;
|
||||
import io.github.robwin.swagger2markup.builder.document.PathsDocument;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupConverter.class);
|
||||
|
||||
private final Swagger swagger;
|
||||
private final MarkupLanguage markupLanguage;
|
||||
private final String examplesFolderPath;
|
||||
private final String schemasFolderPath;
|
||||
private static final String PATHS_DOCUMENT = "paths";
|
||||
private static final String DEFINITIONS_DOCUMENT = "definitions";
|
||||
|
||||
/**
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param swagger the Swagger object
|
||||
* @param examplesFolderPath the folderPath where examples are stored
|
||||
* @param schemasFolderPath the folderPath where (XML, JSON)-Schema files are stored
|
||||
*/
|
||||
Swagger2MarkupConverter(MarkupLanguage markupLanguage, Swagger swagger, String examplesFolderPath, String schemasFolderPath){
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.swagger = swagger;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(String swaggerSource){
|
||||
Validate.notEmpty(swaggerSource, "swaggerSource must not be null!");
|
||||
return new Builder(swaggerSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and stores
|
||||
* the files in the given folder.
|
||||
*
|
||||
* @param targetFolderPath the target folder
|
||||
* @throws IOException if the files cannot be written
|
||||
*/
|
||||
public void intoFolder(String targetFolderPath) throws IOException {
|
||||
Validate.notEmpty(targetFolderPath, "folderPath must not be null!");
|
||||
buildDocuments(targetFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file for the Paths (API) and a file for the Definitions (Model)
|
||||
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @throws IOException if a file cannot be written
|
||||
*/
|
||||
private void buildDocuments(String directory) throws IOException {
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
private final Swagger swagger;
|
||||
private String examplesFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
*/
|
||||
Builder(String swaggerSource){
|
||||
swagger = new SwaggerParser().read(swaggerSource);
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(markupLanguage, swagger, examplesFolderPath, schemasFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withMarkupLanguage(MarkupLanguage markupLanguage){
|
||||
this.markupLanguage = markupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include examples into the Paths document
|
||||
*
|
||||
* @param examplesFolderPath the path to the folder where the example documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withExamples(String examplesFolderPath){
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include (JSON, XML) schemas into the Definitions document
|
||||
*
|
||||
* @param schemasFolderPath the path to the folder where the schema documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withSchemas(String schemasFolderPath){
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
private static final String DEFINITIONS = "Definitions";
|
||||
private static final List<String> IGNORED_DEFINITIONS = Arrays.asList("Void");
|
||||
private static final String JSON_SCHEMA = "JSON Schema";
|
||||
private static final String XML_SCHEMA = "XML Schema";
|
||||
private static final String NAME_COLUMN = "Name";
|
||||
private static final String TYPE_COLUMN = "Type";
|
||||
public static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
public static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
public static final String JSON = "json";
|
||||
public static final String XML = "xml";
|
||||
private boolean schemasEnabled;
|
||||
private String schemasFolderPath;
|
||||
|
||||
public DefinitionsDocument(Swagger swagger, MarkupLanguage markupLanguage, String schemasFolderPath){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(schemasFolderPath)){
|
||||
this.schemasEnabled = true;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
}
|
||||
if(schemasEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
definitions(swagger.getDefinitions());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Swagger definitions.
|
||||
*
|
||||
* @param definitions the Swagger definitions
|
||||
*/
|
||||
private void definitions(Map<String, Model> definitions) throws IOException {
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
this.markupDocBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
for(Map.Entry<String, Model> definitionsEntry : definitions.entrySet()){
|
||||
String definitionName = definitionsEntry.getKey();
|
||||
if(StringUtils.isNotBlank(definitionName)) {
|
||||
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
|
||||
definition(definitionName, definitionsEntry.getValue());
|
||||
definitionSchema(definitionName);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed: {}", definitionName);
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Definition was ignored: {}", definitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the definition is not in the list of ignored definitions.
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @return true if the definition can be processed
|
||||
*/
|
||||
private boolean checkThatDefinitionIsNotInIgnoreList(String definitionName) {
|
||||
return !IGNORED_DEFINITIONS.contains(definitionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete definition
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @param model the Swagger Model of the definition
|
||||
*/
|
||||
private void definition(String definitionName, Model model) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(definitionName);
|
||||
Map<String, Property> properties = model.getProperties();
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(NAME_COLUMN + DELIMITER + TYPE_COLUMN + DELIMITER + REQUIRED_COLUMN);
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
csvContent.add(propertyEntry.getKey() + DELIMITER + property.getType() + DELIMITER + property.getRequired());
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName) throws IOException {
|
||||
if(schemasEnabled) {
|
||||
if (StringUtils.isNotBlank(definitionName)) {
|
||||
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON);
|
||||
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void schema(String title, String schemasFolderPath, String schemaName, String language) throws IOException {
|
||||
java.nio.file.Path path = Paths.get(schemasFolderPath, schemaName);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Schema file processed: {}", path);
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Schema file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = ",";
|
||||
protected static final String REQUIRED_COLUMN = "Required";
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
protected MarkupDocBuilder markupDocBuilder;
|
||||
|
||||
MarkupDocument(Swagger swagger, MarkupLanguage markupLanguage){
|
||||
this.swagger = swagger;
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the MarkupDocument.
|
||||
*
|
||||
* @return the built MarkupDocument
|
||||
* @throws IOException if the files to include are not readable
|
||||
*/
|
||||
public abstract MarkupDocument build() throws IOException ;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
public String toString(){
|
||||
return markupDocBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file and clears the builder.
|
||||
*
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @param fileName the name of the file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @throws IOException if the file cannot be written
|
||||
*/
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException{
|
||||
markupDocBuilder.writeToFile(directory, fileName, charset);
|
||||
}
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.Parameter;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private static final String VERSION = "Version: ";
|
||||
private static final String DESCRIPTION_COLUMN = "Description";
|
||||
private static final String DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
private static final String PRODUCES = "Produces";
|
||||
private static final String CONSUMES = "Consumes";
|
||||
private static final String RESPONSES = "Responses";
|
||||
private static final String EXAMPLE_REQUEST = "Example request";
|
||||
private static final String EXAMPLE_RESPONSE = "Example response";
|
||||
private static final String NAME_COLUMN = "Name";
|
||||
private static final String LOCATED_IN_COLUMN = "Located in";
|
||||
private static final String CODE_COLUMN = "Code";
|
||||
public static final String REQUEST_EXAMPLE_FILE_NAME = "request";
|
||||
public static final String RESPONSE_EXAMPLE_FILE_NAME = "response";
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
|
||||
public PathsDocument(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(examplesFolderPath)){
|
||||
this.examplesEnabled = true;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
}
|
||||
if(examplesEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
documentHeader(swagger.getInfo());
|
||||
paths(swagger.getPaths());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document header
|
||||
*
|
||||
* @param info the Swagger Info
|
||||
*/
|
||||
private void documentHeader(Info info) {
|
||||
this.markupDocBuilder
|
||||
.documentTitle(info.getTitle())
|
||||
.textLine(info.getDescription())
|
||||
.textLine(VERSION + info.getVersion())
|
||||
.newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds all paths of the Swagger file
|
||||
*
|
||||
* @param paths a Map of Swagger Paths
|
||||
*/
|
||||
private void paths(Map<String, Path> paths) throws IOException {
|
||||
if(MapUtils.isNotEmpty(paths)) {
|
||||
//this.documentBuilder.sectionTitleLevel1(FEATURES);
|
||||
for (Map.Entry<String, Path> entry : paths.entrySet()) {
|
||||
Path path = entry.getValue();
|
||||
path("GET", entry.getKey(), path.getGet());
|
||||
path("PUT", entry.getKey(), path.getPut());
|
||||
path("DELETE", entry.getKey(), path.getDelete());
|
||||
path("POST", entry.getKey(), path.getPost());
|
||||
path("PATCH", entry.getKey(), path.getPatch());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path
|
||||
*
|
||||
* @param httpMethod the HTTP method of the path
|
||||
* @param resourcePath the URL of the path
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void path(String httpMethod, String resourcePath, Operation operation) throws IOException {
|
||||
if(operation != null){
|
||||
pathTitle(httpMethod, resourcePath, operation);
|
||||
descriptionSection(operation);
|
||||
parametersSection(operation);
|
||||
responsesSection(operation);
|
||||
consumesSection(operation);
|
||||
producesSection(operation);
|
||||
examplesSection(operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void pathTitle(String httpMethod, String resourcePath, Operation operation) {
|
||||
String summary = operation.getSummary();
|
||||
String title;
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
title = summary;
|
||||
this.markupDocBuilder.sectionTitleLevel1(title);
|
||||
this.markupDocBuilder.listing(httpMethod + " " + resourcePath);
|
||||
}else{
|
||||
title = httpMethod + " " + resourcePath;
|
||||
this.markupDocBuilder.sectionTitleLevel1(title);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Path processed: {}", title);
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionSection(Operation operation) {
|
||||
String description = operation.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(DESCRIPTION);
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private void parametersSection(Operation operation) {
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if(CollectionUtils.isNotEmpty(parameters)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(NAME_COLUMN + DELIMITER + LOCATED_IN_COLUMN + DELIMITER + DESCRIPTION_COLUMN + DELIMITER + REQUIRED_COLUMN);
|
||||
for(Parameter parameter : parameters){
|
||||
csvContent.add(parameter.getName() + DELIMITER + parameter.getIn() + DELIMITER + parameter.getDescription() + DELIMITER + parameter.getRequired());
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel2(PARAMETERS);
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONSUMES);
|
||||
this.markupDocBuilder.unorderedList(consumes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void producesSection(Operation operation) {
|
||||
List<String> produces = operation.getProduces();
|
||||
if(CollectionUtils.isNotEmpty(produces)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(PRODUCES);
|
||||
this.markupDocBuilder.unorderedList(produces);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @throws IOException if the example file is not readable
|
||||
*/
|
||||
private void examplesSection(Operation operation) throws IOException {
|
||||
if(examplesEnabled){
|
||||
String summary = operation.getSummary();
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
String exampleFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
example(EXAMPLE_REQUEST, exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
|
||||
example(EXAMPLE_RESPONSE, exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete example
|
||||
*
|
||||
* @param title the title of the example
|
||||
* @param exampleFolder the name of the folder where the example file resides
|
||||
* @param exampleFileName the name of the example file
|
||||
* @throws IOException
|
||||
*/
|
||||
private void example(String title, String exampleFolder, String exampleFileName) throws IOException {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
this.markupDocBuilder.paragraph(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Example file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void responsesSection(Operation operation) {
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if(MapUtils.isNotEmpty(responses)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(CODE_COLUMN + DELIMITER + DESCRIPTION_COLUMN);
|
||||
for(Map.Entry<String, Response> entry : responses.entrySet()){
|
||||
Response response = entry.getValue();
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription());
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel2(RESPONSES);
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConverter() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).
|
||||
withExamples("docs").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).
|
||||
withExamples("docs").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,846 +0,0 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n",
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "apiteam@wordnik.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"basePath": "/v2",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Add a new pet to the store",
|
||||
"description": "",
|
||||
"operationId": "addPet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Update an existing pet",
|
||||
"description": "",
|
||||
"operationId": "updatePet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
},
|
||||
"405": {
|
||||
"description": "Validation exception"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/findByStatus": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by status",
|
||||
"description": "Multiple status values can be provided with comma seperated strings",
|
||||
"operationId": "findPetsByStatus",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "status",
|
||||
"description": "Status values that need to be considered for filter",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid status value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/findByTags": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by tags",
|
||||
"description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
|
||||
"operationId": "findPetsByTags",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "tags",
|
||||
"description": "Tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid tag value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/{petId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Find pet by ID",
|
||||
"description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
|
||||
"operationId": "getPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
},
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Updates a pet in the store with form data",
|
||||
"description": "",
|
||||
"operationId": "updatePetWithForm",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of pet that needs to be updated",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"description": "Updated name of the pet",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "status",
|
||||
"description": "Updated status of the pet",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Deletes a pet",
|
||||
"description": "",
|
||||
"operationId": "deletePet",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "api_key",
|
||||
"description": "",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "Pet id to delete",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid pet value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/stores/order": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Place an order for a pet",
|
||||
"description": "",
|
||||
"operationId": "placeOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "order placed for purchasing the pet",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid Order"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stores/order/{orderId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Find purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
|
||||
"operationId": "getOrderById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "orderId",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Delete purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
|
||||
"operationId": "deleteOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "orderId",
|
||||
"description": "ID of the order that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Create user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "createUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Created user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/createWithArray": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithArrayInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/createWithList": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithListInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/login": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs user into the system",
|
||||
"description": "",
|
||||
"operationId": "loginUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "username",
|
||||
"description": "The user name for login",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "password",
|
||||
"description": "The password for login in clear text",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username/password supplied"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/logout": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs out current logged in user session",
|
||||
"description": "",
|
||||
"operationId": "logoutUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{username}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get user by user name",
|
||||
"description": "",
|
||||
"operationId": "getUserByName",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "The name that needs to be fetched. Use user1 for testing.",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Updated user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "updateUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "name that need to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Updated user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid user supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Delete user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "deleteUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "The name that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"api_key": {
|
||||
"type": "apiKey",
|
||||
"name": "api_key",
|
||||
"in": "header"
|
||||
},
|
||||
"petstore_auth": {
|
||||
"type": "oauth2",
|
||||
"authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog",
|
||||
"flow": "implicit",
|
||||
"scopes": {
|
||||
"write_pets": "modify pets in your account",
|
||||
"read_pets": "read your pets"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"User": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string"
|
||||
},
|
||||
"userStatus": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "User Status"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Category": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Pet": {
|
||||
"required": [
|
||||
"name",
|
||||
"photoUrls"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"category": {
|
||||
"$ref": "#/definitions/Category"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "doggie"
|
||||
},
|
||||
"photoUrls": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Tag"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "pet status in the store"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Tag": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Order": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"petId": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"shipDate": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "Order Status"
|
||||
},
|
||||
"complete": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
swagger2markup-asciidoc/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
ext.moduleName="io.github.swagger2markup.asciidoc"
|
||||
|
||||
dependencies {
|
||||
configurations.all {
|
||||
// resolutionStrategy.force dependencyOverrides.commonsCodec
|
||||
// resolutionStrategy.force dependencyOverrides.commonsIO
|
||||
// resolutionStrategy.force dependencyOverrides.commonsLang3
|
||||
resolutionStrategy.force dependencyOverrides.jnrConstants
|
||||
resolutionStrategy.force dependencyOverrides.jnrEnxio
|
||||
resolutionStrategy.force dependencyOverrides.jnrPosix
|
||||
// resolutionStrategy.force dependencyOverrides.jodaTime
|
||||
resolutionStrategy.force dependencyOverrides.slf4j
|
||||
// resolutionStrategy.force dependencyOverrides.jacksonDatabind
|
||||
// resolutionStrategy.force dependencyOverrides.guava
|
||||
// resolutionStrategy.force dependencyOverrides.findBugs
|
||||
// resolutionStrategy.force dependencyOverrides.jaksonCore
|
||||
}
|
||||
implementation implLibraries.asciiDocJApi
|
||||
implementation implLibraries.commonsText
|
||||
implementation implLibraries.slf4j
|
||||
testImplementation implLibraries.commonsIO
|
||||
testImplementation testLibraries.asciiDocJ
|
||||
testImplementation testLibraries.junit
|
||||
testImplementation testLibraries.logback
|
||||
}
|
||||
@@ -0,0 +1,887 @@
|
||||
package io.github.swagger2markup.adoc;
|
||||
|
||||
import io.github.swagger2markup.adoc.converter.internal.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.asciidoctor.ast.List;
|
||||
import org.asciidoctor.ast.*;
|
||||
import org.asciidoctor.converter.ConverterFor;
|
||||
import org.asciidoctor.converter.StringConverter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
|
||||
|
||||
@ConverterFor(AsciidocConverter.NAME)
|
||||
public class AsciidocConverter extends StringConverter {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public static final String NAME = "adoc";
|
||||
|
||||
private final Pattern emptyLineOrStartWith = Pattern.compile("(?m)^\\s*(?:\\r?\\n)|(?m)^\\s+");
|
||||
private final Pattern coListItemIdPattern = Pattern.compile(".*-(\\d+)");
|
||||
private final Pattern tableColumnsStylePattern = Pattern.compile("((\\d+)\\*)?([<^>])?(\\.[<^>])?(\\d+)?([adehlmsv])?");
|
||||
|
||||
private static final java.util.List<String> attributeToExclude = Arrays.asList(
|
||||
"localtime",
|
||||
"filetype",
|
||||
"asciidoctor-version",
|
||||
"doctime",
|
||||
"localyear",
|
||||
"docdate",
|
||||
"localdate",
|
||||
"localdatetime",
|
||||
"docdatetime",
|
||||
"backend",
|
||||
"basebackend",
|
||||
"doctitle",
|
||||
"docyear"
|
||||
);
|
||||
|
||||
private static final String[] supportedUrlSchemes = new String[]{
|
||||
"http",
|
||||
"https",
|
||||
"ftp",
|
||||
"irc",
|
||||
"mailto"
|
||||
};
|
||||
|
||||
public AsciidocConverter(String backend, Map<String, Object> opts) {
|
||||
super(backend, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link ContentNode} using the specified transform along
|
||||
* with additional options. If a transform is not specified, implementations
|
||||
* typically derive one from the {@link ContentNode#getNodeName()} property.
|
||||
*
|
||||
* <p>Implementations are free to decide how to carry out the conversion. In
|
||||
* the case of the built-in converters, the tranform value is used to
|
||||
* dispatch to a handler method. The TemplateConverter uses the value of
|
||||
* the transform to select a template to render.
|
||||
*
|
||||
* @param node The concrete instance of FlowNode to convert
|
||||
* @param transform An optional String transform that hints at which transformation
|
||||
* should be applied to this node. If a transform is not specified,
|
||||
* the transform is typically derived from the value of the
|
||||
* node's node_name property. (optional, default: null)
|
||||
* @param opts An optional map of options that provide additional hints about
|
||||
* how to convert the node. (optional, default: empty map)
|
||||
* @return the converted result
|
||||
*/
|
||||
@Override
|
||||
public String convert(ContentNode node, String transform, Map<Object, Object> opts) {
|
||||
if (null == transform) {
|
||||
transform = node.getNodeName();
|
||||
}
|
||||
switch (transform) {
|
||||
case "inline_quoted":
|
||||
return convertInlineQuoted((PhraseNode) node);
|
||||
case "paragraph":
|
||||
return convertParagraph((StructuralNode) node);
|
||||
case "inline_anchor":
|
||||
return convertInlineAnchor((PhraseNode) node);
|
||||
case "section":
|
||||
return convertSection((Section) node);
|
||||
case "listing":
|
||||
return convertListing((Block) node);
|
||||
case "literal":
|
||||
return convertLiteral((StructuralNode) node);
|
||||
case "ulist":
|
||||
return convertUList((List) node);
|
||||
case "olist":
|
||||
return convertOList((List) node);
|
||||
case "dlist":
|
||||
return convertDescriptionList((DescriptionList) node);
|
||||
case "admonition":
|
||||
return convertAdmonition((Block) node);
|
||||
case "colist":
|
||||
return convertCoList((List) node);
|
||||
case "embedded":
|
||||
case "document":
|
||||
return convertEmbedded((Document) node);
|
||||
case "example":
|
||||
return convertExample((Block) node);
|
||||
case "floating_title":
|
||||
return convertFloatingTitle((StructuralNode) node);
|
||||
case "image":
|
||||
return convertImage((StructuralNode) node);
|
||||
case "inline_break":
|
||||
return convertInlineBreak(node);
|
||||
case "inline_button":
|
||||
return convertInlineButton(node);
|
||||
case "inline_callout":
|
||||
return convertInlineCallout(node);
|
||||
case "inline_footnote":
|
||||
return convertInlineFootnote(node);
|
||||
case "inline_image":
|
||||
return convertInlineImage((PhraseNode) node);
|
||||
case "inline_indexterm":
|
||||
return convertInlineIndexTerm(node);
|
||||
case "inline_kbd":
|
||||
return convertInlineKbd(node);
|
||||
case "inline_menu":
|
||||
return convertInlineMenu(node);
|
||||
case "open":
|
||||
return convertOpen((StructuralNode) node);
|
||||
case "page_break":
|
||||
return convertPageBreak(node);
|
||||
case "preamble":
|
||||
return convertPreamble((StructuralNode) node);
|
||||
case "quote":
|
||||
return convertQuote((StructuralNode) node);
|
||||
case "sidebar":
|
||||
return convertSidebar((StructuralNode) node);
|
||||
case "stem":
|
||||
return convertStem(node);
|
||||
case "table":
|
||||
return convertTable((Table) node);
|
||||
case "thematic_break":
|
||||
return convertThematicBreak(node);
|
||||
case "verse":
|
||||
return convertVerse((StructuralNode) node);
|
||||
case "video":
|
||||
return convertVideo(node);
|
||||
case "toc":
|
||||
return convertToc(node);
|
||||
case "pass":
|
||||
return convertPass(node);
|
||||
case "audio":
|
||||
return convertAudio(node);
|
||||
// didn't exist on html converter
|
||||
case "list":
|
||||
return convertList((List) node);
|
||||
case "list_item":
|
||||
return convertListItem((ListItem) node);
|
||||
default:
|
||||
logger.debug("Don't know how to convert transform: [" + transform + "] Node: " + node);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String convertEmbedded(Document node) {
|
||||
logger.debug("convertEmbedded");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendId(node, sb);
|
||||
if (StringUtils.isNotBlank(node.getDoctitle())) {
|
||||
sb.append(repeat(node.getLevel() + 1,DOCUMENT_TITLE)).append(' ').append(StringEscapeUtils.unescapeHtml4(node.getDoctitle())).append(LINE_SEPARATOR);
|
||||
}
|
||||
Map<String, Object> attributes = node.getAttributes();
|
||||
appendAuthors(sb, attributes);
|
||||
appendRevisionDetails(sb, attributes);
|
||||
appendDocumentAttributes(sb, attributes);
|
||||
appendTrailingNewLine(sb);
|
||||
appendChildBlocks(node, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void appendAuthors(StringBuilder sb, Map<String, Object> attributes) {
|
||||
Long authorCount = (Long) attributes.getOrDefault("authorcount", 0L);
|
||||
if (authorCount == 1) {
|
||||
String author = getAuthorDetail(attributes, "author", "email");
|
||||
if (StringUtils.isNotBlank(author)) {
|
||||
sb.append(author).append(LINE_SEPARATOR);
|
||||
}
|
||||
} else if (authorCount > 1) {
|
||||
String authors = LongStream.rangeClosed(1, authorCount)
|
||||
.mapToObj(i -> getAuthorDetail(attributes, "author_" + i, "email_" + i))
|
||||
.collect(Collectors.joining("; "));
|
||||
|
||||
if (StringUtils.isNotBlank(authors)) {
|
||||
sb.append(authors).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendDocumentAttributes(StringBuilder sb, Map<String, Object> attributes) {
|
||||
attributes.forEach((k, v) -> {
|
||||
if (!attributeToExclude.contains(k) && v != null && !v.toString().isEmpty())
|
||||
sb.append(COLON).append(k).append(COLON).append(" ").append(v).append(LINE_SEPARATOR);
|
||||
});
|
||||
}
|
||||
|
||||
private void appendRevisionDetails(StringBuilder sb, Map<String, Object> attributes) {
|
||||
String revDetails = Stream.of(attributes.get("revnumber"), attributes.get("revdate")).filter(Objects::nonNull)
|
||||
.filter(o -> !o.toString().isEmpty()).map(Object::toString)
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
if (!revDetails.isEmpty()) {
|
||||
sb.append("v").append(revDetails).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private String getAuthorDetail(Map<String, Object> attributes, String authorKey, String emailKey) {
|
||||
String author = attributes.getOrDefault(authorKey, "").toString();
|
||||
String email = attributes.getOrDefault(emailKey, "").toString();
|
||||
if (StringUtils.isNotBlank(email)) {
|
||||
email = " <" + email + ">";
|
||||
}
|
||||
|
||||
return (author + email).trim();
|
||||
}
|
||||
|
||||
private String convertInlineAnchor(PhraseNode node) {
|
||||
logger.debug("convertInlineAnchor");
|
||||
String type = node.getType();
|
||||
switch (type) {
|
||||
case "xref": {
|
||||
String attrs;
|
||||
String text;
|
||||
String path = Optional.ofNullable(node.getAttributes().get("path")).orElse("").toString();
|
||||
if (StringUtils.isNotBlank(path)) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(node.getRole())) {
|
||||
list.add(" class=\"#{node.role}\"");
|
||||
}
|
||||
append_link_constraint_attrs(node, list);
|
||||
attrs = String.join(" ", list);
|
||||
text = StringUtils.isNotBlank(node.getText()) ? node.getText() : path;
|
||||
} else {
|
||||
attrs = StringUtils.isNotBlank(node.getRole()) ? " class=\"" + node.getRole() + "\"" : "";
|
||||
text = node.getText();
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
text = node.getAttributes().get("refid").toString();
|
||||
}
|
||||
}
|
||||
return node.getTarget() + ATTRIBUTES_BEGIN + text + (StringUtils.isNotBlank(attrs) ? "," + attrs : "") + ATTRIBUTES_END;
|
||||
}
|
||||
case "ref":
|
||||
return node.getId();
|
||||
case "link": {
|
||||
ArrayList<String> attrs = new ArrayList<>();
|
||||
String target = node.getTarget();
|
||||
String includePrefix = !StringUtils.startsWithAny(target, supportedUrlSchemes) ? "include::" : "";
|
||||
|
||||
String text = node.getText();
|
||||
if (!target.equals(text)) {
|
||||
attrs.add(text);
|
||||
}
|
||||
if (StringUtils.isNotBlank(node.getId())) {
|
||||
attrs.add("id=\"" + node.getId() + "\"");
|
||||
}
|
||||
String role = node.getRole();
|
||||
if (StringUtils.isNotBlank(role) && !role.equals("bare")) {
|
||||
attrs.add("role=\"" + role + "\"");
|
||||
}
|
||||
String title = node.getAttribute("title", "").toString();
|
||||
if (StringUtils.isNotBlank(title)) {
|
||||
attrs.add("title=\"" + title + "\"");
|
||||
}
|
||||
return includePrefix + target + ATTRIBUTES_BEGIN + String.join(",", attrs) + ATTRIBUTES_END;
|
||||
}
|
||||
case "bibref":
|
||||
return node.getId() + ATTRIBUTES_BEGIN + (StringUtils.isNotBlank(node.getReftext()) ? node.getReftext() : node.getId()) + ATTRIBUTES_END;
|
||||
default:
|
||||
logger.warn("unknown anchor type: " + node.getType());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String convertAdmonition(Block node) {
|
||||
logger.debug("convertAdmonition");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
java.util.List<StructuralNode> blocks = node.getBlocks();
|
||||
if (blocks.isEmpty()) {
|
||||
sb.append(node.getStyle()).append(": ").append(node.getSource());
|
||||
} else {
|
||||
appendTitle(node, sb);
|
||||
sb.append(ATTRIBUTES_BEGIN).append(node.getStyle()).append(ATTRIBUTES_END)
|
||||
.append(LINE_SEPARATOR).append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
|
||||
appendChildBlocks(node, sb);
|
||||
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertInlineQuoted(PhraseNode node) {
|
||||
logger.debug("convertInlineQuoted");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String marker = "";
|
||||
switch (node.getType()) {
|
||||
case "monospaced":
|
||||
marker = "`";
|
||||
break;
|
||||
case "emphasis":
|
||||
marker = "_";
|
||||
break;
|
||||
case "strong":
|
||||
marker = "*";
|
||||
break;
|
||||
case "superscript":
|
||||
marker = "^";
|
||||
break;
|
||||
case "subscript":
|
||||
marker = "~";
|
||||
break;
|
||||
case "double":
|
||||
case "single":
|
||||
case "mark":
|
||||
case "asciimath":
|
||||
case "latexmath":
|
||||
marker = "";
|
||||
break;
|
||||
}
|
||||
sb.append(marker).append(node.getText()).append(marker);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertFloatingTitle(StructuralNode node) {
|
||||
logger.debug("convertFloatingTitle");
|
||||
return ATTRIBUTES_BEGIN + "discrete" + ATTRIBUTES_END + LINE_SEPARATOR +
|
||||
repeat(node.getLevel() + 1, TITLE) + ' ' + node.getTitle() + LINE_SEPARATOR;
|
||||
}
|
||||
|
||||
private String convertExample(Block node) {
|
||||
logger.debug("convertExample");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
|
||||
appendChildBlocks(node, sb);
|
||||
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertInlineButton(ContentNode node) {
|
||||
logger.debug("convertInlineButton: name" + node.getNodeName());
|
||||
return "convertInlineButton";
|
||||
}
|
||||
|
||||
private String convertInlineCallout(ContentNode node) {
|
||||
logger.debug("convertInlineCallout: name" + node.getNodeName());
|
||||
return "convertInlineCallout";
|
||||
}
|
||||
|
||||
private String convertInlineBreak(ContentNode node) {
|
||||
logger.debug("convertInlineBreak: name" + node.getNodeName());
|
||||
return "convertInlineBreak";
|
||||
}
|
||||
|
||||
private String convertInlineFootnote(ContentNode node) {
|
||||
logger.debug("convertInlineFootnote: name" + node.getNodeName());
|
||||
return "convertInlineFootnote";
|
||||
}
|
||||
|
||||
private String convertInlineImage(PhraseNode node) {
|
||||
logger.debug("convertInlineImage");
|
||||
if (node.getType().equals("icon")) {
|
||||
return (new IconNode(node)).toAsciiDocContent();
|
||||
} else {
|
||||
return (new BlockImageNode(node)).toAsciiDocContent();
|
||||
}
|
||||
}
|
||||
|
||||
private String convertInlineIndexTerm(ContentNode node) {
|
||||
logger.debug("convertInlineIndexTerm: name" + node.getNodeName());
|
||||
return "convertInlineIndexTerm";
|
||||
}
|
||||
|
||||
private String convertInlineKbd(ContentNode node) {
|
||||
logger.debug("convertInlineKbd: name" + node.getNodeName());
|
||||
return "convertInlineKbd";
|
||||
}
|
||||
|
||||
private String convertInlineMenu(ContentNode node) {
|
||||
logger.debug("convertInlineMenu: name" + node.getNodeName());
|
||||
return "convertInlineMenu";
|
||||
}
|
||||
|
||||
private String convertOpen(StructuralNode node) {
|
||||
logger.debug("convertOpen");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
switch (node.getStyle()) {
|
||||
case "abstract":
|
||||
sb.append(ATTRIBUTES_BEGIN).append("abstract").append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
break;
|
||||
case "open":
|
||||
sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR);
|
||||
}
|
||||
sb.append(Optional.ofNullable(((Block) node).getSource()).orElse(""));
|
||||
appendChildBlocks(node, sb);
|
||||
|
||||
if ("open".equals(node.getStyle())) {
|
||||
sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertPageBreak(ContentNode node) {
|
||||
logger.debug("convertPageBreak: name" + node.getNodeName());
|
||||
return DELIMITER_PAGE_BREAK + LINE_SEPARATOR;
|
||||
}
|
||||
|
||||
private String convertQuote(StructuralNode node) {
|
||||
logger.debug("convertQuote");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
sb.append(ATTRIBUTES_BEGIN);
|
||||
java.util.List<String> attrs = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(node.getStyle())) {
|
||||
attrs.add("quote");
|
||||
}
|
||||
appendAttributeTo(node, attrs, "attribution");
|
||||
appendAttributeTo(node, attrs, "citetitle");
|
||||
sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
java.util.List<StructuralNode> blocks = node.getBlocks();
|
||||
if (!blocks.isEmpty()) {
|
||||
sb.append("____").append(LINE_SEPARATOR);
|
||||
appendChildBlocks(node, sb);
|
||||
sb.append("____").append(LINE_SEPARATOR);
|
||||
} else {
|
||||
sb.append(((Block) node).getSource());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertSidebar(StructuralNode node) {
|
||||
logger.debug("convertSidebar");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
appendChildBlocks(node, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertStem(ContentNode node) {
|
||||
logger.debug("convertStem: name" + node.getNodeName());
|
||||
return "convertStem";
|
||||
}
|
||||
|
||||
private String convertThematicBreak(ContentNode node) {
|
||||
logger.debug("convertThematicBreak: name" + node.getNodeName());
|
||||
return DELIMITER_THEMATIC_BREAK + LINE_SEPARATOR;
|
||||
}
|
||||
|
||||
private String convertVerse(StructuralNode node) {
|
||||
logger.debug("convertVerse");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
sb.append(ATTRIBUTES_BEGIN);
|
||||
java.util.List<String> attrs = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(node.getStyle())) {
|
||||
attrs.add("verse");
|
||||
}
|
||||
appendAttributeTo(node, attrs, "attribution");
|
||||
appendAttributeTo(node, attrs, "citetitle");
|
||||
sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
String source = ((Block) node).getSource();
|
||||
boolean matches = emptyLineOrStartWith.matcher(source).find();
|
||||
if (matches) {
|
||||
sb.append(DELIMITER_VERSE).append(LINE_SEPARATOR);
|
||||
}
|
||||
sb.append(source);
|
||||
if (matches) {
|
||||
sb.append(LINE_SEPARATOR).append(DELIMITER_VERSE);
|
||||
}
|
||||
appendTrailingNewLine(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertVideo(ContentNode node) {
|
||||
logger.debug("convertVideo: name" + node.getNodeName());
|
||||
return "convertVideo";
|
||||
}
|
||||
|
||||
private String convertToc(ContentNode node) {
|
||||
logger.debug("convertToc: name" + node.getNodeName());
|
||||
return "convertToc";
|
||||
}
|
||||
|
||||
private String convertPass(ContentNode node) {
|
||||
logger.debug("convertPass: name" + node.getNodeName());
|
||||
return "convertPass";
|
||||
}
|
||||
|
||||
private String convertAudio(ContentNode node) {
|
||||
logger.debug("convertAudio: name" + node.getNodeName());
|
||||
return "convertAudio";
|
||||
}
|
||||
|
||||
private String convertCell(Cell node) {
|
||||
logger.debug("convertCell");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String source = node.getSource();
|
||||
if (StringUtils.isNotBlank(source)) {
|
||||
sb.append(source);
|
||||
}
|
||||
Document innerDocument = node.getInnerDocument();
|
||||
if (null != innerDocument) {
|
||||
appendChildBlocks(innerDocument, sb, false);
|
||||
}
|
||||
return sb.toString().replaceAll(LINE_SEPARATOR + LINE_SEPARATOR + "+", LINE_SEPARATOR + LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
private String convertRow(Row node, java.util.List<TableCellStyle> columnStyles, String delimiterTableCell) {
|
||||
logger.debug("convertRow");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
node.getCells().forEach(cell -> {
|
||||
boolean addNewLine = false;
|
||||
int colspan = cell.getColspan();
|
||||
if (colspan != 0) {
|
||||
addNewLine = true;
|
||||
sb.append(colspan).append('+');
|
||||
}
|
||||
int rowspan = cell.getRowspan();
|
||||
if (rowspan != 0) {
|
||||
addNewLine = true;
|
||||
sb.append('.').append(rowspan).append('+');
|
||||
}
|
||||
int index = cell.getColumn().getColumnNumber() - 1;
|
||||
TableCellStyle tableCellStyle = (columnStyles.size() > index) ? columnStyles.get(index) : null;
|
||||
|
||||
boolean hAlignmentAdded = false;
|
||||
TableCellHorizontalAlignment hAlignment = TableCellHorizontalAlignment.fromName(cell.getHorizontalAlignment().name());
|
||||
if ((null != hAlignment) && (null == tableCellStyle || hAlignment != tableCellStyle.horizontalAlignment)) {
|
||||
hAlignmentAdded = true;
|
||||
addNewLine = true;
|
||||
sb.append(hAlignment.getDelimiter());
|
||||
}
|
||||
|
||||
TableCellVerticalAlignment vAlignment = TableCellVerticalAlignment.fromName(cell.getVerticalAlignment().name());
|
||||
if ((null != vAlignment) && (null == tableCellStyle || hAlignmentAdded || vAlignment != tableCellStyle.verticalAlignment)) {
|
||||
addNewLine = true;
|
||||
sb.append(vAlignment.getDelimiter());
|
||||
}
|
||||
|
||||
Style style = Style.fromName(cell.getAttribute("style", "").toString());
|
||||
if (null != style && (null == tableCellStyle || style != tableCellStyle.style)) {
|
||||
addNewLine = true;
|
||||
sb.append(style.getShortHand());
|
||||
}
|
||||
sb.append(delimiterTableCell).append(convertCell(cell));
|
||||
if (addNewLine) {
|
||||
sb.append(LINE_SEPARATOR);
|
||||
} else {
|
||||
sb.append(' ');
|
||||
}
|
||||
});
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertTable(Table node) {
|
||||
logger.debug("convertTable");
|
||||
java.util.List<TableCellStyle> columnStyles = new ArrayList<>();
|
||||
for (String col : node.getAttribute("cols", "").toString().split(",")) {
|
||||
Matcher matcher = tableColumnsStylePattern.matcher(col);
|
||||
if (matcher.find()) {
|
||||
int multiplier = 1;
|
||||
String multiplierGroup = matcher.group(2);
|
||||
if (null != multiplierGroup) {
|
||||
try {
|
||||
multiplier = Integer.parseInt(multiplierGroup);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
int width = 0;
|
||||
try {
|
||||
width = Integer.parseInt(matcher.group(5));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
TableCellStyle tableCellStyle = new TableCellStyle(
|
||||
TableCellHorizontalAlignment.fromString(matcher.group(3)),
|
||||
TableCellVerticalAlignment.fromString(matcher.group(4)),
|
||||
Style.fromString(matcher.group(6)),
|
||||
width
|
||||
);
|
||||
for (int i = 0; i < multiplier; i++) {
|
||||
columnStyles.add(tableCellStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
sb.append(new TableNode(node).toAsciiDocContent());
|
||||
boolean innerTable = isInnerTable(node);
|
||||
String tableDelimiter = innerTable ? DELIMITER_INNER_TABLE : DELIMITER_TABLE;
|
||||
String cellDelimiter = innerTable ? DELIMITER_INNER_TABLE_CELL : DELIMITER_TABLE_CELL;
|
||||
sb.append(tableDelimiter).append(LINE_SEPARATOR);
|
||||
appendRows(node.getHeader(), sb, columnStyles, cellDelimiter);
|
||||
appendRows(node.getBody(), sb, columnStyles, cellDelimiter);
|
||||
appendRows(node.getFooter(), sb, columnStyles, cellDelimiter);
|
||||
sb.append(tableDelimiter).append(LINE_SEPARATOR);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean isInnerTable(ContentNode node) {
|
||||
if(null != node) {
|
||||
ContentNode parent = node.getParent();
|
||||
if (null != parent) {
|
||||
return parent instanceof Table || isInnerTable(parent);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void appendRows(java.util.List<Row> rows, StringBuilder sb, java.util.List<TableCellStyle> columnStyles, String delimiterTableCell) {
|
||||
rows.forEach(row -> sb.append(convertRow(row, columnStyles, delimiterTableCell)).append(LINE_SEPARATOR));
|
||||
}
|
||||
|
||||
private String convertDescriptionList(DescriptionList node) {
|
||||
logger.debug("convertDescriptionList");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
appendTitle(node, sb);
|
||||
String style = Optional.ofNullable(node.getStyle()).orElse("");
|
||||
switch (style) {
|
||||
case STYLE_HORIZONTAL:
|
||||
sb.append(ATTRIBUTES_BEGIN).append(STYLE_HORIZONTAL).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), false)));
|
||||
break;
|
||||
case STYLE_Q_AND_A:
|
||||
sb.append(ATTRIBUTES_BEGIN).append(STYLE_Q_AND_A).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
default:
|
||||
node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), true)));
|
||||
break;
|
||||
}
|
||||
appendTrailingNewLine(sb);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertDescriptionListEntry(DescriptionListEntry node, int level, Boolean descriptionOnNewLine) {
|
||||
logger.debug("convertDescriptionListEntry");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String delimiter = repeat(level + 1, MARKER_D_LIST_ITEM);
|
||||
String entryTerms = node.getTerms().stream()
|
||||
.map(term -> Optional.ofNullable(term.getSource()).orElse(""))
|
||||
.collect(Collectors.joining(delimiter + LINE_SEPARATOR, "", delimiter));
|
||||
sb.append(entryTerms);
|
||||
ListItem description = node.getDescription();
|
||||
if (null != description) {
|
||||
if (descriptionOnNewLine) {
|
||||
sb.append(LINE_SEPARATOR);
|
||||
}
|
||||
String desc = Optional.ofNullable(description.getSource()).orElse("");
|
||||
if (StringUtils.isNotBlank(desc)) {
|
||||
sb.append(desc).append(LINE_SEPARATOR);
|
||||
}
|
||||
appendChildBlocks(description, sb);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertListing(Block node) {
|
||||
logger.debug("convertListing");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
if (STYLE_SOURCE.equals(node.getStyle())) {
|
||||
sb.append(new SourceNode(node).toAsciiDocContent());
|
||||
} else {
|
||||
sb.append(new BlockListingNode(node).toAsciiDocContent());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertUList(List node) {
|
||||
logger.debug("convertUList");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendStyle(node, sb);
|
||||
appendTitle(node, sb);
|
||||
appendChildBlocks(node, sb);
|
||||
appendTrailingNewLine(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertOList(List node) {
|
||||
logger.debug("convertOList");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
java.util.List<String> attrs = new ArrayList<>();
|
||||
String start = node.getAttribute("start", "").toString();
|
||||
if (StringUtils.isNotBlank(start)) {
|
||||
attrs.add("start=" + start);
|
||||
}
|
||||
if (node.isOption("reversed")) {
|
||||
attrs.add("%reversed");
|
||||
}
|
||||
if (!attrs.isEmpty()) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
appendTitle(node, sb);
|
||||
appendChildBlocks(node, sb);
|
||||
appendTrailingNewLine(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertCoList(List node) {
|
||||
logger.debug("convertCoList");
|
||||
StringBuilder result = new StringBuilder();
|
||||
appendChildBlocks(node, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String convertListItem(ListItem node) {
|
||||
logger.debug("convertListItem");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String marker = Optional.ofNullable(node.getMarker()).orElse(repeat(node.getLevel(), MARKER_LIST_ITEM));
|
||||
|
||||
String coids = node.getAttribute("coids", "").toString();
|
||||
Matcher matcher = coListItemIdPattern.matcher(coids);
|
||||
if (matcher.find()) {
|
||||
marker = marker.replaceAll("\\d+", matcher.group(1));
|
||||
}
|
||||
|
||||
sb.append(marker).append(" ");
|
||||
|
||||
if (node.hasAttribute("checkbox")) {
|
||||
sb.append('[');
|
||||
if (node.hasAttribute("checked")) {
|
||||
sb.append('x');
|
||||
} else {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(']').append(' ');
|
||||
}
|
||||
|
||||
sb.append(Optional.ofNullable(node.getSource()).orElse(""));
|
||||
appendTrailingNewLine(sb);
|
||||
appendChildBlocks(node, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertList(List node) {
|
||||
logger.debug("convertList");
|
||||
return node.getContent().toString();
|
||||
}
|
||||
|
||||
private String convertPreamble(StructuralNode node) {
|
||||
logger.debug("convertPreamble");
|
||||
return node.getContent().toString();
|
||||
}
|
||||
|
||||
private String convertImage(StructuralNode node) {
|
||||
logger.debug("convertImage");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
appendRoles(node, sb);
|
||||
sb.append(new BlockImageNode(node).toAsciiDocContent());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertLiteral(StructuralNode node) {
|
||||
logger.debug("convertLiteral");
|
||||
return ATTRIBUTES_BEGIN + node.getContext() + ATTRIBUTES_END + LINE_SEPARATOR +
|
||||
StringEscapeUtils.unescapeHtml4(node.getContent().toString()) + LINE_SEPARATOR;
|
||||
}
|
||||
|
||||
private String convertParagraph(StructuralNode node) {
|
||||
logger.debug("convertParagraph");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendTitle(node, sb);
|
||||
sb.append(new ParagraphAttributes(node).toAsciiDocContent());
|
||||
appendSource((Block) node, sb);
|
||||
appendTrailingNewLine(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String convertSection(Section node) {
|
||||
logger.debug("convertSection");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendId(node, sb);
|
||||
sb.append(new DelimitedBlockNode(node).toAsciiDocContent()).append(StringUtils.repeat(TITLE, node.getLevel() + 1))
|
||||
.append(" ").append(StringEscapeUtils.unescapeHtml4(node.getTitle())).append(LINE_SEPARATOR);
|
||||
appendChildBlocks(node, sb);
|
||||
appendTrailingNewLine(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void append_link_constraint_attrs(ContentNode node, java.util.List<String> attrs) {
|
||||
String rel = node.getAttribute("nofollow-option").toString();
|
||||
String window = node.getAttributes().get("window").toString();
|
||||
if (StringUtils.isNotBlank(window)) {
|
||||
attrs.add("target = \"#{window}\"");
|
||||
if (window.equals("_blank") || (node.getAttributes().containsKey("option-noopener"))) {
|
||||
if (StringUtils.isNotBlank(rel)) {
|
||||
attrs.add("rel = \"" + rel + "noopener\"");
|
||||
} else {
|
||||
attrs.add(" rel=\"noopener\"");
|
||||
}
|
||||
}
|
||||
} else if (StringUtils.isNotBlank(rel)) {
|
||||
attrs.add("rel = " + rel + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
private String repeat(int count, String with) {
|
||||
return new String(new char[count]).replace("\0", with);
|
||||
}
|
||||
|
||||
private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb) {
|
||||
appendChildBlocks(parentNode, sb, true);
|
||||
}
|
||||
|
||||
private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb, boolean addTrailingLineSeparator) {
|
||||
final boolean isParentAListItem = parentNode instanceof ListItem || parentNode instanceof DescriptionListEntry;
|
||||
parentNode.getBlocks().forEach(childNode -> {
|
||||
String childNodeValue = childNode.convert();
|
||||
if (StringUtils.isNotBlank(childNodeValue)) {
|
||||
if (isParentAListItem && (sb.toString().contains("+" + LINE_SEPARATOR) || !(childNode instanceof List || childNode instanceof DescriptionList))) {
|
||||
sb.append('+').append(LINE_SEPARATOR);
|
||||
}
|
||||
sb.append(childNodeValue);
|
||||
if (addTrailingLineSeparator && !StringUtils.endsWith(childNodeValue, LINE_SEPARATOR)) {
|
||||
sb.append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void appendTrailingNewLine(StringBuilder sb) {
|
||||
if (!sb.toString().endsWith(LINE_SEPARATOR + LINE_SEPARATOR)) {
|
||||
sb.append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendId(StructuralNode node, StringBuilder sb) {
|
||||
String id = node.getId();
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
sb.append("[[").append(id).append("]]").append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendSource(Block node, StringBuilder sb) {
|
||||
String source = node.getSource();
|
||||
if (StringUtils.isNotBlank(source)) {
|
||||
sb.append(source).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendTitle(StructuralNode node, StringBuilder sb) {
|
||||
String title = node.getTitle();
|
||||
if (StringUtils.isNotBlank(title)) {
|
||||
sb.append(".").append(StringEscapeUtils.unescapeHtml4(title)).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendStyle(StructuralNode node, StringBuilder sb) {
|
||||
String style = node.getStyle();
|
||||
if (StringUtils.isNotBlank(style)) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(style).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendRoles(StructuralNode node, StringBuilder sb) {
|
||||
java.util.List<String> roles = node.getRoles();
|
||||
if (!roles.isEmpty()) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(".").append(String.join(".", roles))
|
||||
.append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendAttributeTo(StructuralNode node, java.util.List<String> attrs, String name) {
|
||||
String attribution = node.getAttribute(name, "").toString();
|
||||
if (StringUtils.isNotBlank(attribution)) {
|
||||
attrs.add(attribution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Block;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BlockImpl extends StructuralNodeImpl implements Block {
|
||||
|
||||
private List<String> lines;
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context) {
|
||||
this(parent, context, "");
|
||||
}
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context, Object content) {
|
||||
this(parent, context, new HashMap<>(), content);
|
||||
}
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context, Map<String, Object> attributes) {
|
||||
this(parent, context, attributes, "");
|
||||
}
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context, Map<String, Object> attributes, Object content) {
|
||||
this(parent, context, attributes, new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>());
|
||||
}
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel, List<String> subs) {
|
||||
this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs);
|
||||
}
|
||||
|
||||
public BlockImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel, List<String> subs) {
|
||||
super(parent, context, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.lines = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<String> lines() {
|
||||
return getLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLines(List<String> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String source() {
|
||||
return getSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(String source) {
|
||||
setLines(Arrays.asList(source.split("\n")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Cell;
|
||||
import org.asciidoctor.ast.Column;
|
||||
import org.asciidoctor.ast.Document;
|
||||
import org.asciidoctor.ast.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CellImpl extends ContentNodeImpl implements Cell {
|
||||
|
||||
private final int colspan;
|
||||
private final int rowspan;
|
||||
private String text;
|
||||
private String style;
|
||||
private Document innerDocument;
|
||||
|
||||
public CellImpl(Column parent, String text) {
|
||||
this(parent, "table_cell", new HashMap<>(), new ArrayList<>(), 0, 0);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public CellImpl(Column parent, Document innerDocument) {
|
||||
this(parent, "table_cell", new HashMap<>(), new ArrayList<>(), 0, 0);
|
||||
this.innerDocument = innerDocument;
|
||||
}
|
||||
|
||||
public CellImpl(Column parent, String context, Map<String, Object> attributes, List<String> roles, int colspan, int rowspan) {
|
||||
super(parent, context, attributes, roles);
|
||||
this.colspan = colspan;
|
||||
this.rowspan = rowspan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column getColumn() {
|
||||
return (Column) getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColspan() {
|
||||
return colspan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowspan() {
|
||||
return rowspan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(String source) {
|
||||
this.text = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyle(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Table.HorizontalAlignment getHorizontalAlignment() {
|
||||
return Table.HorizontalAlignment.valueOf(((String) getAttribute("halign", "left")).toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHorizontalAlignment(Table.HorizontalAlignment halign) {
|
||||
setAttribute("halign", halign.name().toLowerCase(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Table.VerticalAlignment getVerticalAlignment() {
|
||||
return Table.VerticalAlignment.valueOf(((String) getAttribute("valign", "top")).toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVerticalAlignment(Table.VerticalAlignment valign) {
|
||||
setAttribute("valign", valign.name().toLowerCase(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getInnerDocument() {
|
||||
return innerDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInnerDocument(Document document) {
|
||||
this.innerDocument = document;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Column;
|
||||
import org.asciidoctor.ast.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ColumnImpl extends ContentNodeImpl implements Column {
|
||||
|
||||
private String style;
|
||||
private Number columnNumber = -1;
|
||||
private Number width = 0;
|
||||
|
||||
public ColumnImpl(Table parent) {
|
||||
this(parent, "table_column", new HashMap<>(), new ArrayList<>());
|
||||
}
|
||||
|
||||
public ColumnImpl(Table parent, String context, Map<String, Object> attributes, List<String> roles) {
|
||||
super(parent, context, attributes, roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyle(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Table getTable() {
|
||||
return (Table) getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnNumber() {
|
||||
return columnNumber.intValue();
|
||||
}
|
||||
|
||||
public void setColumnNumber(Integer columnNumber) {
|
||||
setAttribute("colnumber", columnNumber, true);
|
||||
this.columnNumber = columnNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
setAttribute("width", width, true);
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Table.HorizontalAlignment getHorizontalAlignment() {
|
||||
return Table.HorizontalAlignment.valueOf(((String) getAttribute("halign", "left")).toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHorizontalAlignment(Table.HorizontalAlignment halign) {
|
||||
setAttribute("halign", halign.name().toLowerCase(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Table.VerticalAlignment getVerticalAlignment() {
|
||||
return Table.VerticalAlignment.valueOf(((String) getAttribute("valign", "top")).toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVerticalAlignment(Table.VerticalAlignment valign) {
|
||||
setAttribute("valign", valign.name().toLowerCase(), true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.ContentNode;
|
||||
import org.asciidoctor.ast.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
public abstract class ContentNodeImpl implements ContentNode {
|
||||
|
||||
private String id;
|
||||
private final String context;
|
||||
private final Map<String, Object> attributes;
|
||||
private final List<String> roles;
|
||||
private final ContentNode parent;
|
||||
|
||||
public ContentNodeImpl(ContentNode parent, String context) {
|
||||
this(parent, context, new HashMap<>(), new ArrayList<>());
|
||||
}
|
||||
|
||||
public ContentNodeImpl(ContentNode parent, String context, Map<String, Object> attributes, List<String> roles) {
|
||||
this.parent = parent;
|
||||
this.context = context;
|
||||
this.attributes = attributes;
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String id() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
this.id = id.toLowerCase().replaceAll("\\s+", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String context() {
|
||||
return getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ContentNode parent() {
|
||||
return getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Document document() {
|
||||
return getDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getDocument() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeName() {
|
||||
return getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInline() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object getAttr(Object name, Object defaultValue, boolean inherit) {
|
||||
return getAttribute(name, defaultValue, inherit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object getAttr(Object name, Object defaultValue) {
|
||||
return getAttribute(name, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object getAttr(Object name) {
|
||||
return getAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(Object name, Object defaultValue, boolean inherit) {
|
||||
return getAttribute(name, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(Object name, Object defaultValue) {
|
||||
return attributes.getOrDefault(name, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(Object name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isAttr(Object name, Object expected, boolean inherit) {
|
||||
return isAttribute(name, expected, inherit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isAttr(Object name, Object expected) {
|
||||
return isAttribute(name, expected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAttribute(Object name, Object expected, boolean inherit) {
|
||||
return isAttribute(name, expected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAttribute(Object name, Object expected) {
|
||||
try {
|
||||
if (attributes.containsKey(name)) {
|
||||
return attributes.get(name).equals(expected);
|
||||
} else return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean hasAttr(Object name) {
|
||||
return hasAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean hasAttr(Object name, boolean inherited) {
|
||||
return hasAttribute(name, inherited);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(Object name) {
|
||||
return attributes.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(Object name, boolean inherited) {
|
||||
return hasAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean setAttr(Object name, Object value, boolean overwrite) {
|
||||
return setAttribute(name, value, overwrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setAttribute(Object name, Object value, boolean overwrite) {
|
||||
return setAttribute((String)name, value, overwrite);
|
||||
}
|
||||
|
||||
public boolean setAttribute(String name, Object value, boolean overwrite) {
|
||||
try {
|
||||
if (overwrite) {
|
||||
attributes.put(name, value);
|
||||
} else {
|
||||
attributes.putIfAbsent(name, value);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Object removeAttribute(String name){
|
||||
return attributes.remove(name);
|
||||
}
|
||||
|
||||
public boolean removeAttribute(String name, Object value){
|
||||
return attributes.remove(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOption(Object name) {
|
||||
try {
|
||||
Object o = attributes.get(name + "-option");
|
||||
return null != o && o.toString().equals("");
|
||||
}catch (Exception ignored){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setOption(String name){
|
||||
return setAttribute(name + "-option", "", true);
|
||||
}
|
||||
|
||||
public Object removeOption(String name){
|
||||
return removeAttribute(name + "-option");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRole() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRole() {
|
||||
return String.join(",", roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String role() {
|
||||
return getRole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRole(String role) {
|
||||
return roles.contains(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRole(String role) {
|
||||
roles.add(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRole(String role) {
|
||||
roles.remove(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReftext() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReftext() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String iconUri(String name) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mediaUri(String target) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String imageUri(String targetImage) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String imageUri(String targetImage, String assetDirKey) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readAsset(String path, Map<Object, Object> opts) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String normalizeWebPath(String path, String start, boolean preserveUriTarget) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Cursor;
|
||||
|
||||
public class CursorImpl implements Cursor {
|
||||
|
||||
private int lineno;
|
||||
|
||||
public CursorImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLineNumber() {
|
||||
return lineno;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDir() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFile() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.DescriptionListEntry;
|
||||
import org.asciidoctor.ast.ListItem;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DescriptionListEntryImpl extends StructuralNodeImpl implements DescriptionListEntry {
|
||||
|
||||
private final List<ListItem> terms;
|
||||
private ListItem description;
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent) {
|
||||
this(parent, new ArrayList<>());
|
||||
}
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent, List<ListItem> terms) {
|
||||
this(parent, terms, null);
|
||||
}
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent, List<ListItem> terms, ListItem description) {
|
||||
this(parent, null, terms, description);
|
||||
}
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent, Object content, List<ListItem> terms, ListItem description) {
|
||||
this(parent, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), terms, description);
|
||||
}
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel, List<String> subs,
|
||||
List<ListItem> terms, ListItem description) {
|
||||
this(parent, attributes, roles, content, blocks, null != parent ? parent.getLevel() : 1, contentModel, subs, terms, description);
|
||||
}
|
||||
|
||||
public DescriptionListEntryImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel,
|
||||
List<String> subs, List<ListItem> terms, ListItem description) {
|
||||
super(parent, "dlist_item", attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.terms = terms;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ListItem> getTerms() {
|
||||
return terms;
|
||||
}
|
||||
|
||||
public boolean addTerm(ListItem term) {
|
||||
return terms.add(term);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItem getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(final ListItem description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.DescriptionList;
|
||||
import org.asciidoctor.ast.DescriptionListEntry;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DescriptionListImpl extends StructuralNodeImpl implements DescriptionList {
|
||||
|
||||
public static final String CONTEXT = "dlist";
|
||||
private List<DescriptionListEntry> items;
|
||||
|
||||
public DescriptionListImpl(StructuralNode parent) {
|
||||
this(parent, new ArrayList<>());
|
||||
}
|
||||
|
||||
public DescriptionListImpl(StructuralNode parent, List<DescriptionListEntry> items) {
|
||||
this(parent, null, items);
|
||||
}
|
||||
|
||||
public DescriptionListImpl(StructuralNode parent, Object content, List<DescriptionListEntry> items) {
|
||||
this(parent, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), items);
|
||||
}
|
||||
|
||||
public DescriptionListImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel,
|
||||
List<String> subs, List<DescriptionListEntry> items) {
|
||||
this(parent, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs, items);
|
||||
}
|
||||
|
||||
public DescriptionListImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level,
|
||||
String contentModel, List<String> subs, List<DescriptionListEntry> items) {
|
||||
super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DescriptionListEntry> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<DescriptionListEntry> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void addEntry(DescriptionListEntry entry) {
|
||||
this.items.add(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItems() {
|
||||
return !items.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String render() {
|
||||
return convert();
|
||||
}
|
||||
|
||||
protected static Integer calculateLevel(StructuralNode parent) {
|
||||
int level = 1;
|
||||
if (parent instanceof DescriptionList)
|
||||
level = parent.getLevel() + 1;
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Document;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
import org.asciidoctor.ast.Title;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DocumentImpl extends StructuralNodeImpl implements Document {
|
||||
|
||||
public DocumentImpl() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public DocumentImpl(StructuralNode parent) {
|
||||
this(parent, "document", "");
|
||||
}
|
||||
|
||||
public DocumentImpl(StructuralNode parent, String context, Object content) {
|
||||
this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>());
|
||||
}
|
||||
|
||||
public DocumentImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel,
|
||||
List<String> subs) {
|
||||
this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() + 1 : 0, contentModel, subs);
|
||||
}
|
||||
|
||||
public DocumentImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel,
|
||||
List<String> subs) {
|
||||
super(parent, context, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBasebackend(String backend) {
|
||||
return isAttribute("basebackend", backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean basebackend(String backend) {
|
||||
return isBasebackend(backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> getOptions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Title getStructuredDoctitle() {
|
||||
return (Title) getOptions().get("doctitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDoctitle() {
|
||||
return getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String doctitle() {
|
||||
return getDoctitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAndIncrementCounter(String name) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAndIncrementCounter(String name, int initialValue) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSourcemap() {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourcemap(boolean state) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.List;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListImpl extends StructuralNodeImpl implements List {
|
||||
|
||||
private final java.util.List<StructuralNode> items;
|
||||
|
||||
public ListImpl(StructuralNode parent, String context) {
|
||||
this(parent, context, new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
public ListImpl(StructuralNode parent, String context, java.util.List<StructuralNode> items) {
|
||||
this(parent, context, null, items);
|
||||
}
|
||||
|
||||
public ListImpl(StructuralNode parent, String context, Object content, java.util.List<StructuralNode> items) {
|
||||
this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), items);
|
||||
}
|
||||
|
||||
public ListImpl(StructuralNode parent, String context, Map<String, Object> attributes, java.util.List<String> roles,
|
||||
Object content, java.util.List<StructuralNode> blocks,
|
||||
String contentModel, java.util.List<String> subs, java.util.List<StructuralNode> items) {
|
||||
this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() + 1 : 0, contentModel, subs, items);
|
||||
}
|
||||
|
||||
public ListImpl(StructuralNode parent, String context, Map<String, Object> attributes, java.util.List<String> roles,
|
||||
Object content, java.util.List<StructuralNode> blocks,
|
||||
Integer level, String contentModel, java.util.List<String> subs, java.util.List<StructuralNode> items) {
|
||||
super(parent, context, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<StructuralNode> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItems() {
|
||||
return !items.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String render() {
|
||||
return convert();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.ListItem;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListItemImpl extends StructuralNodeImpl implements ListItem {
|
||||
|
||||
private final String marker;
|
||||
private String text;
|
||||
|
||||
public ListItemImpl(StructuralNode parent, String text) {
|
||||
this(parent, "list_item", null, "*", text);
|
||||
}
|
||||
|
||||
public ListItemImpl(StructuralNode parent, String context, Object content, String marker, String text) {
|
||||
this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), marker, text);
|
||||
}
|
||||
|
||||
public ListItemImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel,
|
||||
List<String> subs, String marker, String text) {
|
||||
this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() : 1, contentModel, subs, marker, text);
|
||||
}
|
||||
|
||||
public ListItemImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level,
|
||||
String contentModel, List<String> subs, String marker, String text) {
|
||||
super(parent, context, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.marker = marker;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarker() {
|
||||
return marker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(String source) {
|
||||
this.text = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasText() {
|
||||
return StringUtils.isNotBlank(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParagraphBlockImpl extends BlockImpl {
|
||||
|
||||
public static final String CONTEXT = "paragraph";
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent) {
|
||||
super(parent, CONTEXT);
|
||||
}
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent, Object content) {
|
||||
super(parent, CONTEXT, content);
|
||||
}
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent, Map<String, Object> attributes) {
|
||||
super(parent, CONTEXT, attributes);
|
||||
}
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent, Map<String, Object> attributes, Object content) {
|
||||
super(parent, CONTEXT, attributes, content);
|
||||
}
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel, List<String> subs) {
|
||||
super(parent, CONTEXT, attributes, roles, content, blocks, contentModel, subs);
|
||||
}
|
||||
|
||||
public ParagraphBlockImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel,
|
||||
List<String> subs) {
|
||||
super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import io.github.swagger2markup.adoc.AsciidocConverter;
|
||||
import org.asciidoctor.ast.ContentNode;
|
||||
import org.asciidoctor.ast.PhraseNode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PhraseNodeImpl extends ContentNodeImpl implements PhraseNode {
|
||||
|
||||
private final String type;
|
||||
private final String text;
|
||||
private final String target;
|
||||
private final AsciidocConverter converter = new AsciidocConverter(AsciidocConverter.NAME, new HashMap<>());
|
||||
|
||||
public PhraseNodeImpl(ContentNode parent, String context, Map<String, Object> attributes, List<String> roles, String type, String text, String target) {
|
||||
super(parent, context, attributes, roles);
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String render() {
|
||||
return convert();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convert() {
|
||||
return converter.convert(this, null, new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Cell;
|
||||
import org.asciidoctor.ast.Row;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RowImpl implements Row {
|
||||
|
||||
private final List<Cell> cells;
|
||||
|
||||
public RowImpl(List<Cell> cells) {
|
||||
this.cells = cells;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cell> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Section;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SectionImpl extends StructuralNodeImpl implements Section {
|
||||
|
||||
private final Integer index;
|
||||
private final Integer number;
|
||||
private final String numeral;
|
||||
private final String sectionName;
|
||||
private final boolean special;
|
||||
private final boolean numbered;
|
||||
|
||||
public SectionImpl(StructuralNode parent) {
|
||||
this(parent, new HashMap<>());
|
||||
}
|
||||
|
||||
public SectionImpl(StructuralNode parent, Map<String, Object> attributes) {
|
||||
this(parent, "section", null, "");
|
||||
}
|
||||
|
||||
|
||||
public SectionImpl(StructuralNode parent, String context, Object content, String sectionName) {
|
||||
this(parent, context, content, null, null, "", sectionName, false, false);
|
||||
}
|
||||
|
||||
public SectionImpl(StructuralNode parent, String context, Object content, Integer index, Integer number, String numeral,
|
||||
String sectionName, boolean special, boolean numbered) {
|
||||
this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(),
|
||||
"", new ArrayList<>(), index, number, numeral, sectionName, special, numbered);
|
||||
}
|
||||
|
||||
public SectionImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel, List<String> subs,
|
||||
Integer index, Integer number, String numeral, String sectionName, boolean special, boolean numbered) {
|
||||
this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs, index, number, numeral, sectionName, special, numbered);
|
||||
}
|
||||
|
||||
public SectionImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel, List<String> subs,
|
||||
Integer index, Integer number, String numeral, String sectionName, boolean special, boolean numbered) {
|
||||
super(parent, context, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.index = index;
|
||||
this.number = number;
|
||||
this.numeral = numeral;
|
||||
this.sectionName = sectionName;
|
||||
this.special = special;
|
||||
this.numbered = numbered;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int index() {
|
||||
return getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int number() {
|
||||
return getNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNumeral() {
|
||||
return numeral;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String sectname() {
|
||||
return getSectionName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSectionName() {
|
||||
return sectionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean special() {
|
||||
return isSpecial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecial() {
|
||||
return special;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean numbered() {
|
||||
return isNumbered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNumbered() {
|
||||
return numbered;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import io.github.swagger2markup.adoc.AsciidocConverter;
|
||||
import org.asciidoctor.ast.Cursor;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StructuralNodeImpl extends ContentNodeImpl implements StructuralNode {
|
||||
|
||||
private String title;
|
||||
private String caption;
|
||||
private String style;
|
||||
private final Object content;
|
||||
private final List<StructuralNode> blocks;
|
||||
private Integer level;
|
||||
private final String contentModel;
|
||||
private List<String> subs;
|
||||
private final AsciidocConverter converter = new AsciidocConverter(AsciidocConverter.NAME, new HashMap<>());
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context) {
|
||||
this(parent, context, new HashMap<>());
|
||||
}
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context, Map<String, Object> attributes) {
|
||||
this(parent, context, attributes, null);
|
||||
}
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context, Object content) {
|
||||
this(parent, context, new HashMap<>(), content);
|
||||
}
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context, Map<String, Object> attributes, Object content) {
|
||||
this(parent, context, attributes, new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>());
|
||||
}
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, String contentModel, List<String> subs) {
|
||||
this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs);
|
||||
}
|
||||
|
||||
public StructuralNodeImpl(StructuralNode parent, String context, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel, List<String> subs) {
|
||||
super(parent, context, attributes, roles);
|
||||
this.content = content;
|
||||
this.blocks = blocks;
|
||||
this.level = level;
|
||||
this.contentModel = contentModel;
|
||||
this.subs = subs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String title() {
|
||||
return getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String style() {
|
||||
return getStyle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStyle(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<StructuralNode> blocks() {
|
||||
return getBlocks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructuralNode> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(StructuralNode block) {
|
||||
blocks.add(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object content() {
|
||||
return getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convert() {
|
||||
return converter.convert(this, null, new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getSourceLocation() {
|
||||
return new CursorImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentModel() {
|
||||
return contentModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubstitutions() {
|
||||
return subs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubstitutionEnabled(String substitution) {
|
||||
return subs.contains(substitution);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubstitution(String substitution) {
|
||||
subs.remove(substitution);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubstitution(String substitution) {
|
||||
subs.add(substitution);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prependSubstitution(String substitution) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubstitutions(String... substitutions) {
|
||||
subs = Arrays.asList(substitutions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructuralNode> findBy(Map<Object, Object> selector) {
|
||||
throw new UnsupportedOperationException("Not implemented, yet");
|
||||
}
|
||||
|
||||
protected static Integer calculateLevel(StructuralNode parent) {
|
||||
return null != parent ? parent.getLevel() + 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class TableImpl extends StructuralNodeImpl implements Table {
|
||||
public static final String OPTION_UNBREAKABLE = "unbreakable";
|
||||
public static final String OPTION_BREAKABLE = "breakable";
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
public static final String CONTEXT = "table";
|
||||
private static final String FRAME_ATTR = "frame";
|
||||
private static final String GRID_ATTR = "grid";
|
||||
private RowList headerRows;
|
||||
private RowList bodyRows;
|
||||
private RowList footerRows;
|
||||
|
||||
private List<Column> columns = new ArrayList<>();
|
||||
|
||||
public TableImpl(StructuralNode parent) {
|
||||
this(parent, new HashMap<>(), new ArrayList<>());
|
||||
}
|
||||
|
||||
public TableImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles) {
|
||||
this(parent, attributes, roles, calculateLevel(parent));
|
||||
}
|
||||
|
||||
public TableImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles, Integer level) {
|
||||
this(parent, attributes, roles, null, new ArrayList<>(), level, "", new ArrayList<>());
|
||||
}
|
||||
|
||||
public TableImpl(StructuralNode parent, Map<String, Object> attributes, List<String> roles,
|
||||
Object content, List<StructuralNode> blocks, Integer level, String contentModel, List<String> subs) {
|
||||
super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs);
|
||||
this.headerRows = new RowList(new ArrayList<>());
|
||||
this.bodyRows = new RowList(new ArrayList<>());
|
||||
this.footerRows = new RowList(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasHeaderOption() {
|
||||
return isOption("header");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFrame() {
|
||||
return (String) getAttribute(FRAME_ATTR, "all");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrame(String frame) {
|
||||
setAttribute(FRAME_ATTR, frame, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrid() {
|
||||
return (String) getAttribute(GRID_ATTR, "all");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGrid(String grid) {
|
||||
setAttribute(GRID_ATTR, grid, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Column> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Row> getHeader() {
|
||||
return headerRows;
|
||||
}
|
||||
|
||||
public void setHeaderRow(Row row) {
|
||||
headerRows.clear();
|
||||
headerRows.add(row);
|
||||
scanRowForColumns(row);
|
||||
}
|
||||
|
||||
public void setHeaderRow(List<Cell> cells) {
|
||||
setHeaderRow(new RowImpl(cells));
|
||||
}
|
||||
|
||||
public void setHeaderRow(String... documentContents) {
|
||||
headerRows.clear();
|
||||
headerRows.add(generateRow(documentContents));
|
||||
}
|
||||
|
||||
public RowImpl generateRow(Document... innerDocs) {
|
||||
List<Cell> cells = new ArrayList<>();
|
||||
for (int i = 0; i < innerDocs.length; i++) {
|
||||
|
||||
Column column = null;
|
||||
try {
|
||||
column = columns.get(i);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (null == column) {
|
||||
ColumnImpl newColumn = new ColumnImpl(this);
|
||||
newColumn.setColumnNumber(i + 1);
|
||||
column = newColumn;
|
||||
addColumnAt(column, i);
|
||||
}
|
||||
cells.add(new CellImpl(column, innerDocs[i]));
|
||||
|
||||
}
|
||||
return new RowImpl(cells);
|
||||
}
|
||||
|
||||
public RowImpl generateRow(String... documentContents) {
|
||||
Document[] documents = Arrays.stream(documentContents).map(documentContent -> {
|
||||
Document innerDoc = new DocumentImpl();
|
||||
Block paragraph = new ParagraphBlockImpl(innerDoc);
|
||||
paragraph.setSource(documentContent);
|
||||
innerDoc.append(paragraph);
|
||||
return innerDoc;
|
||||
}).toArray(Document[]::new);
|
||||
return generateRow(documents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Row> getBody() {
|
||||
return bodyRows;
|
||||
}
|
||||
|
||||
public void setBodyRows(List<Row> rows) {
|
||||
bodyRows.clear();
|
||||
bodyRows.addAll(rows);
|
||||
bodyRows.forEach(this::scanRowForColumns);
|
||||
}
|
||||
|
||||
public void addRow(Row row) {
|
||||
bodyRows.add(row);
|
||||
scanRowForColumns(row);
|
||||
}
|
||||
|
||||
public void addRow(List<Cell> cells) {
|
||||
bodyRows.add(new RowImpl(cells));
|
||||
}
|
||||
|
||||
public RowImpl addRow(Document... documentContents) {
|
||||
RowImpl row = generateRow(documentContents);
|
||||
bodyRows.add(row);
|
||||
return row;
|
||||
}
|
||||
|
||||
public RowImpl addRow(String... documentContents) {
|
||||
RowImpl row = generateRow(documentContents);
|
||||
bodyRows.add(row);
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Row> getFooter() {
|
||||
return footerRows;
|
||||
}
|
||||
|
||||
public void setFooterRow(Row row) {
|
||||
footerRows.clear();
|
||||
footerRows.add(row);
|
||||
scanRowForColumns(row);
|
||||
}
|
||||
|
||||
public void setFooterRow(String... documentContents) {
|
||||
footerRows.clear();
|
||||
footerRows.add(generateRow(documentContents));
|
||||
}
|
||||
|
||||
private void scanRowForColumns(Row row) {
|
||||
row.getCells().forEach(cell -> {
|
||||
Column column = cell.getColumn();
|
||||
int i = column.getColumnNumber() - 1;
|
||||
addColumnAt(column, i);
|
||||
});
|
||||
}
|
||||
|
||||
private void addColumnAt(Column column, int i) {
|
||||
if (columns.size() >= i) {
|
||||
columns.add(i, column);
|
||||
} else {
|
||||
while (columns.size() < i) {
|
||||
columns.add(columns.size(), null);
|
||||
}
|
||||
columns.add(column);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFooterRow(List<Cell> cells) {
|
||||
setFooterRow(new RowImpl(cells));
|
||||
}
|
||||
|
||||
class RowList extends AbstractList<Row> {
|
||||
|
||||
private final List<Row> rubyArray;
|
||||
|
||||
private RowList(List<Row> rubyArray) {
|
||||
this.rubyArray = rubyArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return rubyArray.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return rubyArray.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return rubyArray.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Row row) {
|
||||
boolean changed = false;
|
||||
try {
|
||||
changed = rubyArray.add(row);
|
||||
setAttribute("rowcount", size(), true);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Couldn't add row", e);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
if (!(o instanceof RowImpl)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
boolean changed = rubyArray.remove(o);
|
||||
setAttribute("rowcount", size(), true);
|
||||
return changed;
|
||||
} catch (Exception e) {
|
||||
logger.debug("Couldn't add row", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
rubyArray.clear();
|
||||
setAttribute("rowcount", size(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row get(int index) {
|
||||
return rubyArray.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row set(int index, Row element) {
|
||||
Row oldRow = get(index);
|
||||
rubyArray.set(index, element);
|
||||
return oldRow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Row element) {
|
||||
rubyArray.add(index, element);
|
||||
setAttribute("rowcount", size(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row remove(int index) {
|
||||
Row removed = rubyArray.remove(index);
|
||||
setAttribute("rowcount", size(), true);
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
if (!(o instanceof RowImpl)) {
|
||||
return -1;
|
||||
}
|
||||
return rubyArray.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
if (!(o instanceof RowImpl)) {
|
||||
return -1;
|
||||
}
|
||||
return rubyArray.lastIndexOf(o);
|
||||
}
|
||||
}
|
||||
|
||||
protected static Integer calculateLevel(StructuralNode parent) {
|
||||
int level = 1;
|
||||
if (parent instanceof Table)
|
||||
level = parent.getLevel() + 1;
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.github.swagger2markup.adoc.ast.impl;
|
||||
|
||||
import org.asciidoctor.ast.Title;
|
||||
|
||||
public class TitleImpl implements Title {
|
||||
|
||||
private final String main;
|
||||
private final String subtitle;
|
||||
|
||||
public TitleImpl(String main, String subtitle) {
|
||||
this.main = main;
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCombined() {
|
||||
return main + ": " + subtitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSanitized() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.ContentNode;
|
||||
|
||||
public class BlockImageNode extends NodeAttributes {
|
||||
|
||||
final private String target;
|
||||
|
||||
public BlockImageNode(ContentNode node) {
|
||||
super(node.getAttributes());
|
||||
target = pop("target").replaceAll("\\s", "{sp}");
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPositionalAttributes() {
|
||||
String attr1 = pop("1", "alt");
|
||||
if (StringUtils.isNotBlank(attr1)) {
|
||||
attrs.add(attr1);
|
||||
}
|
||||
|
||||
String attr2 = pop("2", "width");
|
||||
if (StringUtils.isNotBlank(attr2)) {
|
||||
attrs.add(attr2);
|
||||
}
|
||||
|
||||
String attr3 = pop("3", "height");
|
||||
if (StringUtils.isNotBlank(attr3)) {
|
||||
attrs.add(attr3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void processAttributes() {
|
||||
attributes.forEach((k, v) -> {
|
||||
if (!k.equals("role") && null != v) {
|
||||
attrs.add(k + "=" + v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAsciiDocContent() {
|
||||
return "image::" + target + '[' + String.join(",", attrs) + ']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.asciidoctor.ast.Block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
|
||||
|
||||
public class BlockListingNode extends ParagraphAttributes {
|
||||
|
||||
final private Block node;
|
||||
|
||||
public BlockListingNode(Block node) {
|
||||
super(node);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAsciiDocContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
attrsToString(sb, attrs);
|
||||
sb.append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR).append(node.getSource()).append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void attrsToString(StringBuilder sb, List<String> list) {
|
||||
if (!list.isEmpty()) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(String.join(",", list)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
|
||||
|
||||
public class DelimitedBlockNode extends ParagraphAttributes {
|
||||
|
||||
public DelimitedBlockNode(StructuralNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPositionalAttributes() {
|
||||
String source = pop("1", "style");
|
||||
StringBuilder options = new StringBuilder();
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
attributes.forEach((k, v) -> {
|
||||
if (k.endsWith(OPTION_SUFFIX)) {
|
||||
toRemove.add(k);
|
||||
options.append('%').append(k.replace(OPTION_SUFFIX, ""));
|
||||
}
|
||||
});
|
||||
toRemove.forEach(attributes::remove);
|
||||
source += options.toString();
|
||||
|
||||
if (StringUtils.isNotBlank(source)) {
|
||||
attrs.add(source);
|
||||
}
|
||||
super.processPositionalAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAsciiDocContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!attrs.isEmpty()) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
public class Delimiters {
|
||||
public static final String ATTRIBUTES_BEGIN = "[";
|
||||
public static final String ATTRIBUTES_END = "]";
|
||||
public static final String COLON = ":";
|
||||
public static final String DELIMITER_BLOCK = "----";
|
||||
public static final String DELIMITER_EXAMPLE = "====";
|
||||
public static final String DELIMITER_INNER_TABLE_CELL = "!";
|
||||
public static final String DELIMITER_INNER_TABLE = "!===";
|
||||
public static final String DELIMITER_PAGE_BREAK = "<<<";
|
||||
public static final String DELIMITER_OPEN_BLOCK = "--";
|
||||
public static final String DELIMITER_SIDEBAR = "****";
|
||||
public static final String DELIMITER_TABLE = "|===";
|
||||
public static final String DELIMITER_TABLE_CELL = "|";
|
||||
public static final String DELIMITER_THEMATIC_BREAK = "'''";
|
||||
public static final String DELIMITER_VERSE = "____";
|
||||
public static final String DOCUMENT_TITLE = "=";
|
||||
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
public static final String MARKER_LIST_ITEM = "*";
|
||||
public static final String MARKER_D_LIST_ITEM = ":";
|
||||
public static final String STYLE_HORIZONTAL = "horizontal";
|
||||
public static final String STYLE_Q_AND_A = "qanda";
|
||||
public static final String STYLE_SOURCE = "source";
|
||||
public static final String TITLE = "=";
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.ContentNode;
|
||||
|
||||
public class IconNode extends NodeAttributes {
|
||||
|
||||
final private String alt;
|
||||
|
||||
public IconNode(ContentNode node) {
|
||||
super(node.getAttributes());
|
||||
alt = pop("alt", "default-alt");
|
||||
}
|
||||
|
||||
public String getAlt() {
|
||||
return alt;
|
||||
}
|
||||
|
||||
@Override
|
||||
void processPositionalAttributes() {
|
||||
String attr1 = pop("1", "size");
|
||||
if (StringUtils.isNotBlank(attr1)) {
|
||||
attrs.add(attr1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void processAttributes() {
|
||||
attributes.forEach((k, v) -> {
|
||||
attrs.add(k + "=" + v);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
String processAsciiDocContent() {
|
||||
return "icon:" + alt + '[' + String.join(",", attrs) + ']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
|
||||
|
||||
abstract class NodeAttributes {
|
||||
public static final String TITLE = "title";
|
||||
|
||||
final Map<String, Object> attributes;
|
||||
List<String> attrs = new ArrayList<>();
|
||||
|
||||
NodeAttributes(Map<String, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String pop(String... keys) {
|
||||
AtomicReference<String> value = new AtomicReference<>("");
|
||||
Stream.of(keys).forEach(key -> {
|
||||
try {
|
||||
String tmpValue = attributes.remove(key).toString();
|
||||
if (null != tmpValue && !tmpValue.isEmpty() && value.get().isEmpty()) {
|
||||
value.set(tmpValue);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
});
|
||||
return value.get();
|
||||
}
|
||||
|
||||
String pop(String key) {
|
||||
try {
|
||||
String value = attributes.remove(key).toString();
|
||||
if (null == value) {
|
||||
value = "";
|
||||
}
|
||||
return value;
|
||||
} catch (NullPointerException ignored) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
final public String toAsciiDocContent() {
|
||||
processPositionalAttributes();
|
||||
processAttributes();
|
||||
return processAsciiDocContent();
|
||||
}
|
||||
|
||||
abstract void processPositionalAttributes();
|
||||
|
||||
abstract void processAttributes();
|
||||
|
||||
String processAsciiDocContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!attrs.isEmpty()) {
|
||||
sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.StructuralNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParagraphAttributes extends NodeAttributes {
|
||||
|
||||
public static final String OPTION_SUFFIX = "-option";
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public ParagraphAttributes(StructuralNode node) {
|
||||
super(node.getAttributes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPositionalAttributes() {
|
||||
String attr1 = pop("1", "style");
|
||||
if (StringUtils.isNotBlank(attr1)) {
|
||||
attrs.add(attr1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void processAttributes() {
|
||||
String id = pop("id");
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
id = "#" + id;
|
||||
}
|
||||
String roles = String.join(".", pop("role").split(" "));
|
||||
if (StringUtils.isNotBlank(roles)) {
|
||||
roles = "." + roles;
|
||||
}
|
||||
StringBuilder options = new StringBuilder();
|
||||
List<String> namedAttributes = new ArrayList<>();
|
||||
|
||||
attributes.forEach((k, v) -> {
|
||||
if (k.equals(TITLE)) {
|
||||
logger.debug("Skipping attribute: " + TITLE);
|
||||
} else if (k.endsWith(OPTION_SUFFIX)) {
|
||||
options.append('%').append(k.replace(OPTION_SUFFIX, ""));
|
||||
} else if (null != v) {
|
||||
if(v.toString().contains(" ") || v.toString().contains(",")) {
|
||||
namedAttributes.add(k + "=\"" + v +"\"");
|
||||
} else {
|
||||
namedAttributes.add(k + "=" + v);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Don't know how to handle key: " + k);
|
||||
}
|
||||
});
|
||||
|
||||
String nonNamedAttributes = id + roles + options.toString();
|
||||
if (StringUtils.isNotBlank(nonNamedAttributes)) {
|
||||
attrs.add(nonNamedAttributes);
|
||||
}
|
||||
attrs.addAll(namedAttributes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.asciidoctor.ast.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
|
||||
|
||||
public class SourceNode extends BlockListingNode {
|
||||
|
||||
private List<String> sourceAttrs = new ArrayList<>();
|
||||
private final Block node;
|
||||
|
||||
public SourceNode(Block node) {
|
||||
super(node);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPositionalAttributes() {
|
||||
String source = pop("1", "style");
|
||||
String language = pop("2", "language");
|
||||
StringBuilder options = new StringBuilder();
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
attributes.forEach((k, v) -> {
|
||||
if (k.endsWith(OPTION_SUFFIX)) {
|
||||
toRemove.add(k);
|
||||
options.append('%').append(k.replace(OPTION_SUFFIX, ""));
|
||||
}
|
||||
});
|
||||
toRemove.forEach(attributes::remove);
|
||||
source += options.toString();
|
||||
|
||||
if (StringUtils.isNotBlank(source)) {
|
||||
sourceAttrs.add(source);
|
||||
}
|
||||
if (StringUtils.isNotBlank(language)) {
|
||||
sourceAttrs.add(language);
|
||||
}
|
||||
super.processPositionalAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAsciiDocContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
attrsToString(sb, attrs);
|
||||
attrsToString(sb, sourceAttrs);
|
||||
sb.append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR).append(node.getSource()).append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum Style {
|
||||
ASCIIDOC("a"), EMPHASIS("e"), HEADER("h"), LITERAL("l"), MONOSPACED("m"), NONE("d"), STRONG("s"), VERSE("v");
|
||||
|
||||
String shortHand;
|
||||
|
||||
Style(String h) {
|
||||
this.shortHand = h;
|
||||
}
|
||||
|
||||
public static Style fromString(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
for (Style s : Style.values()) {
|
||||
if (s.shortHand.equalsIgnoreCase(text)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Style fromName(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
return valueOf(text.toUpperCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getShortHand() {
|
||||
return shortHand;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum TableCellHorizontalAlignment {
|
||||
LEFT("<"), CENTER("^"), RIGHT(">");
|
||||
|
||||
String delimiter;
|
||||
|
||||
TableCellHorizontalAlignment(String s) {
|
||||
this.delimiter = s;
|
||||
}
|
||||
|
||||
public static TableCellHorizontalAlignment fromString(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
for (TableCellHorizontalAlignment a : TableCellHorizontalAlignment.values()) {
|
||||
if (a.delimiter.equalsIgnoreCase(text)) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TableCellHorizontalAlignment fromName(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
return valueOf(text.toUpperCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
public class TableCellStyle {
|
||||
public final TableCellHorizontalAlignment horizontalAlignment;
|
||||
public final TableCellVerticalAlignment verticalAlignment;
|
||||
public final Style style;
|
||||
public final int width;
|
||||
|
||||
public TableCellStyle(TableCellHorizontalAlignment horizontalAlignment, TableCellVerticalAlignment verticalAlignment, Style style, int width) {
|
||||
this.horizontalAlignment = horizontalAlignment;
|
||||
this.verticalAlignment = verticalAlignment;
|
||||
this.style = style;
|
||||
this.width = width;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum TableCellVerticalAlignment {
|
||||
TOP(".<"), MIDDLE(".^"), BOTTOM(".>");
|
||||
|
||||
String delimiter;
|
||||
|
||||
TableCellVerticalAlignment(String s) {
|
||||
this.delimiter = s;
|
||||
}
|
||||
|
||||
public static TableCellVerticalAlignment fromString(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
for (TableCellVerticalAlignment a : TableCellVerticalAlignment.values()) {
|
||||
if (a.delimiter.equalsIgnoreCase(text)) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TableCellVerticalAlignment fromName(String text) {
|
||||
if(StringUtils.isNotBlank(text)) {
|
||||
return valueOf(text.toUpperCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.swagger2markup.adoc.converter.internal;
|
||||
|
||||
import org.asciidoctor.ast.Table;
|
||||
|
||||
public class TableNode extends DelimitedBlockNode {
|
||||
public TableNode(Table table) {
|
||||
super(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
void processAttributes() {
|
||||
pop("colcount", "rowcount", "tablepcwidth");
|
||||
super.processAttributes();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.github.swagger2markup.adoc.AsciiDocConverterRegistry
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.github.swagger2markup.adoc;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.asciidoctor.Asciidoctor;
|
||||
import org.asciidoctor.OptionsBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class AsciidocConverterTest {
|
||||
|
||||
private Asciidoctor asciidoctor = Asciidoctor.Factory.create();
|
||||
|
||||
@Parameterized.Parameters(name = "Run {index}: file={0}")
|
||||
public static Iterable<?> data() {
|
||||
return Arrays.asList(
|
||||
"simple.adoc",
|
||||
"arrows-and-boxes-example.ad",
|
||||
"brokeninclude.asciidoc",
|
||||
"changeattribute.adoc",
|
||||
"chronicles-example.adoc",
|
||||
"document-with-arrays.adoc"
|
||||
);
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String asciidocFile;
|
||||
|
||||
|
||||
@Test
|
||||
public void converts_asciidoc_to_asciidoc() throws IOException {
|
||||
//Given
|
||||
String originalAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/original/" + asciidocFile), StandardCharsets.UTF_8);
|
||||
String expectedAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/expected/" + asciidocFile), StandardCharsets.UTF_8);
|
||||
|
||||
//When
|
||||
asciidoctor.javaConverterRegistry().register(AsciidocConverter.class, AsciidocConverter.NAME);
|
||||
String result = asciidoctor.convert(originalAsciiDoc, OptionsBuilder.options().backend(AsciidocConverter.NAME).headerFooter(false).asMap());
|
||||
|
||||
//Then
|
||||
assertEquals(expectedAsciiDoc, result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
= Document Title
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:appendix-refsig: Appendix
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:attribute-missing: skip
|
||||
:section-refsig: Section
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:note-caption: Note
|
||||
:stylesdir: .
|
||||
:untitled-label: Untitled
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:authorcount: 0
|
||||
:example-caption: Example
|
||||
:version-label: Version
|
||||
:last-update-label: Last updated
|
||||
:doctype: article
|
||||
:chapter-refsig: Chapter
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
[arrowsAndBoxes]
|
||||
(User) > (Admin)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
= Title
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:appendix-refsig: Appendix
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:attribute-missing: skip
|
||||
:section-refsig: Section
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:note-caption: Note
|
||||
:stylesdir: .
|
||||
:untitled-label: Untitled
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:authorcount: 0
|
||||
:example-caption: Example
|
||||
:version-label: Version
|
||||
:last-update-label: Last updated
|
||||
:doctype: article
|
||||
:chapter-refsig: Chapter
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
link:b.adoc[]
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
= Document Title
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:appendix-refsig: Appendix
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:attribute-missing: skip
|
||||
:section-refsig: Section
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:note-caption: Note
|
||||
:stylesdir: .
|
||||
:untitled-label: Untitled
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:authorcount: 0
|
||||
:example-caption: Example
|
||||
:version-label: Version
|
||||
:last-update-label: Last updated
|
||||
:doctype: article
|
||||
:chapter-refsig: Chapter
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
sample {content}
|
||||
|
||||
@@ -0,0 +1,535 @@
|
||||
= The Dangerous & _Thrilling_ Documentation Chronicles: Based on True Events
|
||||
Kismet Caméléon; Lazarus het Draeke
|
||||
v1.0, 2014-01-01
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:toclevels: 3
|
||||
:appendix-refsig: Appendix
|
||||
:author_2: Lazarus het Draeke
|
||||
:uri-stbernardusabt12: http://www.sintbernardus.be/stbernardusabt12.php?l=en
|
||||
:authorinitials: KC
|
||||
:author_1: Kismet Caméléon
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:author: Kismet Caméléon
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:lastname: Caméléon
|
||||
:attribute-missing: skip
|
||||
:lastname_1: Caméléon
|
||||
:section-refsig: Section
|
||||
:uri-devoxx: https://devoxx.be
|
||||
:lastname_2: het Draeke
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:authors: Kismet Caméléon, Lazarus het Draeke
|
||||
:note-caption: Note
|
||||
:firstname: Kismet
|
||||
:stylesdir: .
|
||||
:uri-devoxx-top-talks: https://www.youtube.com/watch?v=1OpAgZvYXLQ&list=PLRsbF2sD7JVq7fv1GZGORShSUIae1ZAPy&index=1
|
||||
:untitled-label: Untitled
|
||||
:description: This story chronicles the inexplicable hazards and vicious beasts a team must conquer and vanquish on their journey to discovering the true power of Open Source.
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:listing-caption: Listing
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:firstname_1: Kismet
|
||||
:authorcount: 2
|
||||
:revdate: 2014-01-01
|
||||
:example-caption: Example
|
||||
:firstname_2: Lazarus
|
||||
:version-label: Version
|
||||
:revnumber: 1.0
|
||||
:last-update-label: Last updated
|
||||
:doctype: book
|
||||
:chapter-refsig: Chapter
|
||||
:uri-wolpertinger: http://en.wikipedia.org/wiki/Wolpertinger
|
||||
:organization: Company Name
|
||||
:authorinitials_1: KC
|
||||
:authorinitials_2: Lh
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
[abstract]
|
||||
{description}
|
||||
[[_its_a_city_under_siege]]
|
||||
== It’s a City Under Siege
|
||||
This journey begins one late Monday afternoon at {uri-devoxx}[((Devoxx))].
|
||||
Our team needs coffee, _desperately_, but none of us dare open the theater doors...
|
||||
|
||||
During the {uri-devoxx-top-talks}[opening university session], a script-happy warlock inadvertently released a legion of Wolpertingers!
|
||||
To leave now would mean *code dismemberment and certain death*.
|
||||
|
||||
Behold -> the horror!
|
||||
|
||||
.Wolpertinger, stuffed
|
||||
[.left.thumb]
|
||||
image::wolpertinger.jpg[Wolpertinger,link=http://en.wikipedia.org/wiki/Wolpertinger,pdfwidth=50%]
|
||||
(((Wolpertinger)))
|
||||
(((Ravenous Beast,Wolpertinger)))
|
||||
You may not be familiar with these {uri-wolpertinger}[ravenous beasts].
|
||||
Trust us, they'll eat your shorts and suck loops from your code.
|
||||
In light of this danger, we've searched high and wide for the security crew's defensive operations manual.
|
||||
We can't find it and the DefOps{empty}footnote:defops[DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central.
|
||||
They've either eaten each other or fallen victim to the Wolpertingers roaming the streets of ((Antwerp)).
|
||||
Quick, hit kbd:[Ctrl,Alt,Backspace] or select menu:File[Quit] and let's bail out of here!
|
||||
|
||||
WARNING: Working with DefOps{empty}footnote:defops[] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement.
|
||||
_Weak light from the hallway trickled across the theater, chased by a distant scream._
|
||||
|
||||
[[_rendezvous_point]]
|
||||
=== Rendezvous Point
|
||||
Come on, [[bier-central,Bier Central]]_Bier Central_, of course!
|
||||
Did you have to ask?
|
||||
If you beat me there, order me a {uri-stbernardusabt12}[St. Bernardus Abt 12].
|
||||
Here's some €.
|
||||
|
||||
[[ravages]]
|
||||
[#ravages]
|
||||
== The Ravages of Writing
|
||||
Crystalline XML tags relentlessly bombarded the theater.
|
||||
|
||||
.XML tags
|
||||
[source,xml]
|
||||
|
||||
----
|
||||
<author id="1">
|
||||
<personname>
|
||||
<firstname>Lazarus</firstname>
|
||||
<surname>het Draeke</surname>
|
||||
</personname>
|
||||
</author>
|
||||
----
|
||||
Despite the assault, we continued our pursuit to draft a DefOps{empty}footnote:defops[] plan.
|
||||
|
||||
.DefOps Plan
|
||||
====
|
||||
Click btn:[Download Zip] to download the defensive operation plan bundle.
|
||||
|
||||
OMG!
|
||||
Somebody please save us now!
|
||||
I want my mum -- and an extra-large double macchiato, please.
|
||||
|
||||
====
|
||||
Unfortunately, Lazarus and I had both come to the conclusion that we weren't going to get out of this without corrupted hardrives if we didn't locate caffeine within the next few hours.
|
||||
|
||||
[[_a_recipe_for_potion_that_will_ensure_you_win_the_hearts_of_developers]]
|
||||
=== A Recipe for Potion That Will Ensure You Win the Hearts of Developers
|
||||
This potion for a sample document contains the following ingredients, which are listed in a very random, chaotically nested order.
|
||||
|
||||
.Ingredients for Potion that Demystifies Documents
|
||||
* all the headings
|
||||
** syntax highlighted source code
|
||||
*** non-syntax highlighted source code or just a listing block
|
||||
|
||||
* quote block
|
||||
** verse block
|
||||
*** table with some cell formatting
|
||||
**** sequential paragraphs
|
||||
***** admonition blocks, but use them sparingly
|
||||
|
||||
*** bullet list with nesting
|
||||
|
||||
** numbered list with nesting
|
||||
** definition list
|
||||
*** sidebar
|
||||
|
||||
* example block
|
||||
** block image (no inline images)
|
||||
*** inline formatting in a paragraph
|
||||
**** two fresh Burdockian leaves
|
||||
***** They must be harvested by the light of the teal moons.
|
||||
|
||||
Are you square?
|
||||
|
||||
[square]
|
||||
* one
|
||||
* two
|
||||
* three
|
||||
|
||||
What is there to do?
|
||||
|
||||
* [x] Done
|
||||
* [ ] Next
|
||||
* Who's counting?
|
||||
|
||||
[[_searching_for_burdockian]]
|
||||
==== Searching for Burdockian
|
||||
.Steps for finding and preparing Burdockian leaves
|
||||
. Locate dusty botany
|
||||
.. Sneeze
|
||||
... Sneeze some more
|
||||
|
||||
. Find section on Burdockian
|
||||
.. Review its characteristics
|
||||
... Take a picture of the diagram of its leaves
|
||||
.... Don't rip out the picture like a troglodyte
|
||||
..... Don't do it, I'm watching you
|
||||
|
||||
. Put on your hiking boots
|
||||
. Freeze your butt off on the side of a mountain at midnight
|
||||
|
||||
Let's skip a few steps and start counting from 10.
|
||||
|
||||
[start=10]
|
||||
. arabic (10)
|
||||
.. loweralpha (a)
|
||||
... lowerroman (i)
|
||||
... lowerroman (ii)
|
||||
... lowerroman (iii)
|
||||
... lowerroman (iv)
|
||||
.... upperalpha (A)
|
||||
|
||||
. arabic (11)
|
||||
|
||||
It's time for a top 5 list, made using the `reversed` option on an ordered list!
|
||||
|
||||
[%reversed]
|
||||
. Stone Imperial Russian Stout
|
||||
. Pliny the Elder
|
||||
. Chimay Grande Réserve (Blue)
|
||||
. St. Bernardus Abt 12
|
||||
. Westvleteren 12 (XII)
|
||||
|
||||
How about a list with some terms?
|
||||
|
||||
* Fruits
|
||||
Apple::::
|
||||
The round fruit of a tree of the rose family, which typically has thin red or green skin and crisp flesh.
|
||||
Yes, I said _flesh_.
|
||||
Pear::::
|
||||
A yellowish- or brownish-green edible fruit that is typically narrow at the stalk and wider toward the base, with sweet, slightly gritty flesh.
|
||||
More flesh.
|
||||
Mmmmm.
|
||||
|
||||
* Vegetables
|
||||
Carrot::::
|
||||
An orange-colored root eaten as a vegetable.
|
||||
Beware, it's a favorite of the Wolpertinger.
|
||||
|
||||
[[_are_you_still_here]]
|
||||
===== Are You Still Here?
|
||||
.Move, move, move!
|
||||
[CAUTION]
|
||||
====
|
||||
The Wolpertingers can smell your procrastination.
|
||||
It's not their fault you can't find your boots.
|
||||
|
||||
====
|
||||
[[_sigh]]
|
||||
====== Sigh…
|
||||
TIP: Your boots are in your closet.
|
||||
|
||||
[[_dawn_on_the_plateau]]
|
||||
== Dawn on the Plateau
|
||||
Lazarus was hanging from the bottom limb of a Burdockian tree, licking the bark.
|
||||
|
||||
[quote,Mark Tobey]
|
||||
On pavements and the bark of trees I have found whole worlds.
|
||||
"`If there are whole worlds on that bark, he just swallowed them,`" Kizmet replied.
|
||||
|
||||
[verse,The documentation attorneys]
|
||||
____
|
||||
No bark was harmed in the making of this potion.
|
||||
We're not so sure about a couple ants though.
|
||||
|
||||
Nor those worlds...
|
||||
|
||||
Crap, I smell an injunction.
|
||||
____
|
||||
We'd retrieved the leaves, but we'd obviously lost our minds in the process.
|
||||
|
||||
[verse]
|
||||
Roses are +++<span style="color: #FF0000">red</span>+++.
|
||||
Violets are +++<span style="color: #0000FF">blue</span>+++__-ish__.
|
||||
|
||||
[[_words_seasoned_with_power]]
|
||||
== Words Seasoned with Power
|
||||
To _tame_ the [.wild]#wild# wolpertingers, we needed to build a *charm*.
|
||||
But **ul**timate victory could only be won if we divined the *_true name_* of the __war__lock.
|
||||
|
||||
"`What kind of charm?`" Lazarus asked. "`An odoriferous one or a mineral one?`"
|
||||
Kizmet shrugged. "`The note from Olaf's desk says '`wormwood and licorice,`' but these could be normal groceries for werewolves.`"
|
||||
|
||||
"`Well the H~2~O written on the security whiteboard could be part of a shopping list, but I don't think the local bodega also sells e = mc^2^,`" Lazarus replied.
|
||||
|
||||
"`Wait!`" Indigo plucked a small vial from her desk's top drawer and held it toward us.
|
||||
The vial's label read '```e = mc^2^ *_the scent of science_* _smells like a genius_```'.
|
||||
|
||||
[[_can_i_get_some_code]]
|
||||
=== Can I Get Some `Code`?
|
||||
[%hardbreaks]
|
||||
Sure.
|
||||
Have a listing block.
|
||||
|
||||
[listing]
|
||||
|
||||
----
|
||||
This is an example of a listing block.
|
||||
The content inside is rendered as <pre> text.
|
||||
----
|
||||
But I'm not giving you any highlighting shazam just yet.
|
||||
|
||||
.What is a listing block?
|
||||
Like literal blocks, the content in listing blocks is displayed exactly as you entered it.
|
||||
Listing block content is rendered as `<pre>` text.
|
||||
|
||||
The `listing` style is applied to an element, such as a paragraph, by setting the `listing` attribute on that element.
|
||||
|
||||
Let's get our #((highlighting))# on!
|
||||
|
||||
<<<
|
||||
Install Prawn:
|
||||
|
||||
[literal]
|
||||
$ gem install prawn
|
||||
Then create your first PDF document in Ruby!
|
||||
|
||||
.Generates a basic PDF document using Prawn
|
||||
[source,ruby]
|
||||
|
||||
----
|
||||
require 'prawn' # <1>
|
||||
|
||||
Prawn::Document.generate 'output.pdf' do # <3>
|
||||
text 'Hello, World!' # <2>
|
||||
end
|
||||
----
|
||||
<1> Imports Prawn library
|
||||
<3> Adds text “Hello, World!” to first page
|
||||
<2> Writes PDF to [file]_output.pdf_ after executing all statements
|
||||
How about some source code that styles code? So meta!
|
||||
|
||||
[source,css]
|
||||
|
||||
----
|
||||
code {
|
||||
padding: 2px 4px;
|
||||
font-size: 90%;
|
||||
font-weight: normal;
|
||||
color: #c7254e;
|
||||
white-space: nowrap !important;
|
||||
background-color: #f9f2f4;
|
||||
border-radius: 4px;
|
||||
}
|
||||
----
|
||||
Where could we go without some Java(TM)?
|
||||
Naturally, some autosizing is necessary.
|
||||
|
||||
[source%autofit,java]
|
||||
|
||||
----
|
||||
package org.javaee7.cdi.events;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.enterprise.event.Observes;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.*;
|
||||
|
||||
/**
|
||||
* This session-scoped bean receives greeting strings from the event bus
|
||||
* and provides access to the collection of these greetings via a REST API.
|
||||
*
|
||||
* @author The Duke
|
||||
* @since 1.0
|
||||
*/
|
||||
@SessionScoped
|
||||
public class GreetingReceiver implements EventReceiver, Serializable {
|
||||
|
||||
private List<String> greetings;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
this.greetings = new ArrayList<String>();
|
||||
}
|
||||
|
||||
void receive(@Observes String greet) {
|
||||
this.greetings.add(greet);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
public List<String> listAll(@QueryParam("start") Integer start, @QueryParam("max") Integer max) {
|
||||
int numGreetings = this.greetings.size();
|
||||
|
||||
if (numGreetings == 0 || max == 0) {
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
if (start == null) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (max == null) {
|
||||
max = numGreetings;
|
||||
}
|
||||
|
||||
return this.greetings.subList(start, Math.min(max + start, numGreetings));
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
We already showed you an XML example in <<ravages>>, a language we often rant about over beers at <<bier-central>>.
|
||||
|
||||
I'll trade you a little table for some of that bark.
|
||||
|
||||
[table%header,grid=rows,cols=4,frame=topbot]
|
||||
|===
|
||||
<.<|Column 1
|
||||
<.<|Column 2
|
||||
<.<|Column 3
|
||||
<.<|Column 4
|
||||
|
||||
^.<m|Prefix `{vbar}` with `{caret}` to center content horizontally within the cell.
|
||||
<.>|Prefix `{vbar}` with a `.` and `>` to align content to the bottom of the cell.
|
||||
^.^|Prefix `{vbar}` with a `^`, `.`, and `^` to place content in the middle of the cell.
|
||||
>.<|Prefix `{vbar}` with `>` to align content to the right horizontally within the cell.
|
||||
|
||||
4+^.<e|This content spans all four columns (`4{plus}`) and is centered horizontally (`{caret}`) within the cell.
|
||||
|
||||
|===
|
||||
Wait.
|
||||
What?
|
||||
Where is this story going?
|
||||
|
||||
`<span>`:::
|
||||
an html tag that makes me crazy
|
||||
align:::
|
||||
something I never get going in the right direction.
|
||||
Also has to do with my poor verbal communication skills
|
||||
float:::
|
||||
style:::
|
||||
don't make me laugh
|
||||
|
||||
Does anyone have the time?
|
||||
|
||||
Tg lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumj.
|
||||
|
||||
[[_keeping_it_together]]
|
||||
== Keeping It Together
|
||||
On this page we have nested "`keep together`" logic.
|
||||
The combined block will be shifted to the next page if there isn't room available on this one.
|
||||
|
||||
[verse]
|
||||
First,
|
||||
we
|
||||
need
|
||||
to
|
||||
waste
|
||||
several
|
||||
lines
|
||||
using
|
||||
a
|
||||
verse
|
||||
to
|
||||
push
|
||||
the
|
||||
next
|
||||
block
|
||||
to
|
||||
its
|
||||
breaking
|
||||
point.
|
||||
.What happens if there is both a field and a method with the same name?
|
||||
[NOTE]
|
||||
====
|
||||
Back to the previous example, suppose that we have both a field and a method with the same name, as in:
|
||||
|
||||
.Java class with a field and method that share the same name
|
||||
[source,java]
|
||||
|
||||
----
|
||||
public class Foo {
|
||||
public String bar;
|
||||
|
||||
public String bar() {
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
----
|
||||
*Golo resolves methods first, fields last.*
|
||||
Hence, the following Golo code will resolve the `bar()` method, not the `bar` field:
|
||||
|
||||
.Golo picks the method over the field with the same name
|
||||
[source,golo]
|
||||
|
||||
----
|
||||
let foo = Foo()
|
||||
|
||||
foo: bar("baz") # <1>
|
||||
|
||||
println(foo: bar()) # <2>
|
||||
----
|
||||
<1> Writes the field
|
||||
<2> Calls the `bar()` method
|
||||
====
|
||||
<<<
|
||||
Here's a preview of how each heading level is rendered.
|
||||
|
||||
[discrete]
|
||||
= Heading 1 (Level 0)
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
== Heading 2 (Level 1)
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
=== Heading 3 (Level 2)
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
==== Heading 4 (Level 3)
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
===== Heading 5 (Level 4)
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
====== Heading 6 (Level 5)
|
||||
filler content
|
||||
|
||||
'''
|
||||
--
|
||||
Here's some content inside an open block.
|
||||
|
||||
--
|
||||
|
||||
[[_credits]]
|
||||
[appendix]
|
||||
== Credits
|
||||
.Brought to you with icon:heart[set=fas,role=love] by OpenDevise
|
||||
[table%footer%header,grid=rows,width=75%,cols="2,2s,^4",frame=topbot]
|
||||
|===
|
||||
<.<|Name
|
||||
<.<|Title
|
||||
.<|Alias
|
||||
|
||||
<.<|Sarah White
|
||||
<.<|President
|
||||
.<|http://twitter.com/carbonfray[@carbonfray]
|
||||
|
||||
<.<|Dan Allen
|
||||
<.<|Vice President
|
||||
.<|http://twitter.com/mojavelinux[@mojavelinux]
|
||||
|
||||
3+^.<e|Powered by Open Source
|
||||
|
||||
|===
|
||||
|
||||
[[_index]]
|
||||
[index]
|
||||
== Index
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
= Asciidoctor Changelog
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:appendix-refsig: Appendix
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:attribute-missing: skip
|
||||
:section-refsig: Section
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:note-caption: Note
|
||||
:stylesdir: .
|
||||
:untitled-label: Untitled
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:authorcount: 0
|
||||
:example-caption: Example
|
||||
:version-label: Version
|
||||
:last-update-label: Last updated
|
||||
:doctype: article
|
||||
:chapter-refsig: Chapter
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
http://asciidoctor.org[Asciidoctor] is an open source text processor and publishing toolchain for converting http://asciidoctor.org[AsciiDoc] markup into HTML, DocBook and custom formats.
|
||||
|
||||
|
||||
This document provides a high-level view of the changes introduced in Asciidoctor by release.
|
||||
For a detailed view of what has changed, refer to the https://github.com/asciidoctor/asciidoctor/commits/master[commit history] on GitHub.
|
||||
|
||||
[[_0_1_4_2013_09_05_mojavelinux]]
|
||||
== 0.1.4 (2013-09-05) - @mojavelinux
|
||||
Performance::
|
||||
* 15% increase in speed compared to 0.1.3
|
||||
|
||||
Enhancements::
|
||||
* updated xref inline macro to support inter-document references (#417)
|
||||
|
||||
Bug Fixes::
|
||||
* lowercase attribute names passed to API (#508)
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
= Simple Inventory API
|
||||
You <you@your-company.com>
|
||||
v1.0.0
|
||||
:tip-caption: Tip
|
||||
:appendix-caption: Appendix
|
||||
:appendix-refsig: Appendix
|
||||
:authorinitials: Y
|
||||
:toc-title: Table of Contents
|
||||
:iconsdir: ./images/icons
|
||||
:author: You
|
||||
:warning-caption: Warning
|
||||
:figure-caption: Figure
|
||||
:attribute-missing: skip
|
||||
:section-refsig: Section
|
||||
:toc-placement: auto
|
||||
:important-caption: Important
|
||||
:authors: You
|
||||
:note-caption: Note
|
||||
:firstname: You
|
||||
:stylesdir: .
|
||||
:untitled-label: Untitled
|
||||
:max-include-depth: 64
|
||||
:caution-caption: Caution
|
||||
:user-home: .
|
||||
:max-attribute-value-size: 4096
|
||||
:safe-mode-level: 20
|
||||
:safe-mode-name: secure
|
||||
:table-caption: Table
|
||||
:part-refsig: Part
|
||||
:authorcount: 1
|
||||
:example-caption: Example
|
||||
:email: you@your-company.com
|
||||
:version-label: Version
|
||||
:revnumber: 1.0.0
|
||||
:last-update-label: Last updated
|
||||
:doctype: article
|
||||
:chapter-refsig: Chapter
|
||||
:attribute-undefined: drop-line
|
||||
|
||||
[[_overview]]
|
||||
== Overview
|
||||
This is a simple API
|
||||
|
||||
[[_license]]
|
||||
=== License
|
||||
[%hardbreaks]
|
||||
http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
|
||||
|
||||
[[_servers]]
|
||||
== Servers
|
||||
* https://{username}.gigantic-server.com:{port}/{basePath}
|
||||
+
|
||||
The production API server
|
||||
|
||||
+
|
||||
.Variables
|
||||
username::
|
||||
*this* __value__ is assigned by the service provider, in this example `gigantic-server.com`
|
||||
Possible Values::
|
||||
Any
|
||||
Default::
|
||||
demo
|
||||
|
||||
port::
|
||||
Possible Values::
|
||||
- 8443
|
||||
- 443
|
||||
|
||||
Default::
|
||||
8443
|
||||
|
||||
basePath::
|
||||
Possible Values::
|
||||
Any
|
||||
Default::
|
||||
v2
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
= Document Title
|
||||
|
||||
[arrowsAndBoxes]
|
||||
(User) > (Admin)
|
||||
@@ -0,0 +1,3 @@
|
||||
= Title
|
||||
|
||||
include::b.adoc[]
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
= Document Title
|
||||
|
||||
sample {content}
|
||||
@@ -0,0 +1,529 @@
|
||||
= The Dangerous & _Thrilling_ Documentation Chronicles: Based on True Events
|
||||
Kismet Caméléon; Lazarus het_Draeke
|
||||
v1.0, 2014-01-01
|
||||
:description: This story chronicles the inexplicable hazards and vicious beasts a \
|
||||
team must conquer and vanquish on their journey to discovering the true power of \
|
||||
Open Source.
|
||||
:organization: Company Name
|
||||
:doctype: book
|
||||
// Settings:
|
||||
:experimental:
|
||||
:reproducible:
|
||||
:icons: font
|
||||
:listing-caption: Listing
|
||||
:sectnums:
|
||||
:toc:
|
||||
:toclevels: 3
|
||||
ifeval::["{asciidoctor-version}" < "1.5.7"]
|
||||
:legacy-footnoteref:
|
||||
endif::[]
|
||||
ifdef::backend-pdf[]
|
||||
:pdf-theme: chronicles
|
||||
:pdf-themesdir: {docdir}
|
||||
:title-logo-image: image:sample-banner.svg[pdfwidth=4.25in,align=center]
|
||||
:source-highlighter: rouge
|
||||
//:rouge-style: github
|
||||
endif::[]
|
||||
// URIs:
|
||||
:uri-devoxx: https://devoxx.be
|
||||
:uri-devoxx-top-talks: https://www.youtube.com/watch?v=1OpAgZvYXLQ&list=PLRsbF2sD7JVq7fv1GZGORShSUIae1ZAPy&index=1
|
||||
:uri-stbernardusabt12: http://www.sintbernardus.be/stbernardusabt12.php?l=en
|
||||
:uri-wolpertinger: http://en.wikipedia.org/wiki/Wolpertinger
|
||||
|
||||
[abstract]
|
||||
{description}
|
||||
|
||||
== It's a City Under Siege
|
||||
|
||||
This journey begins one late Monday afternoon at {uri-devoxx}[((Devoxx))].
|
||||
Our team needs coffee, _desperately_, but none of us dare open the theater doors...
|
||||
|
||||
During the {uri-devoxx-top-talks}[opening university session], a script-happy warlock inadvertently released a legion of Wolpertingers!
|
||||
To leave now would mean *code dismemberment and certain death*.
|
||||
|
||||
Behold -> the horror!
|
||||
|
||||
.Wolpertinger, stuffed
|
||||
[.left.thumb]
|
||||
image::wolpertinger.jpg[Wolpertinger,pdfwidth=50%,link={uri-wolpertinger}]
|
||||
|
||||
(((Wolpertinger)))
|
||||
(((Ravenous Beast,Wolpertinger)))
|
||||
You may not be familiar with these {uri-wolpertinger}[ravenous beasts].
|
||||
Trust us, they'll eat your shorts and suck loops from your code.
|
||||
In light of this danger, we've searched high and wide for the security crew's defensive operations manual.
|
||||
ifndef::legacy-footnoteref[]
|
||||
We can't find it and the DefOps{empty}footnote:defops[DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central.
|
||||
endif::[]
|
||||
ifdef::legacy-footnoteref[]
|
||||
We can't find it and the DefOps{empty}footnoteref:[defops,DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central.
|
||||
endif::[]
|
||||
They've either eaten each other or fallen victim to the Wolpertingers roaming the streets of ((Antwerp)).
|
||||
Quick, hit kbd:[Ctrl,Alt,Backspace] or select menu:File[Quit] and let's bail out of here!
|
||||
|
||||
ifndef::legacy-footnoteref[]
|
||||
WARNING: Working with DefOps{empty}footnote:defops[] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement.
|
||||
endif::[]
|
||||
ifdef::legacy-footnoteref[]
|
||||
WARNING: Working with DefOps{empty}footnoteref:[defops] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement.
|
||||
endif::[]
|
||||
|
||||
_Weak light from the hallway trickled across the theater, chased by a distant scream._
|
||||
|
||||
=== Rendezvous Point
|
||||
|
||||
Come on, [[bier-central,Bier Central]]_Bier Central_, of course!
|
||||
Did you have to ask?
|
||||
If you beat me there, order me a {uri-stbernardusabt12}[St. Bernardus Abt 12].
|
||||
Here's some €.
|
||||
|
||||
[#ravages]
|
||||
== The Ravages of Writing
|
||||
|
||||
Crystalline XML tags relentlessly bombarded the theater.
|
||||
|
||||
.XML tags
|
||||
[source,xml]
|
||||
----
|
||||
<author id="1">
|
||||
<personname>
|
||||
<firstname>Lazarus</firstname>
|
||||
<surname>het Draeke</surname>
|
||||
</personname>
|
||||
</author>
|
||||
----
|
||||
|
||||
ifndef::legacy-footnoteref[]
|
||||
Despite the assault, we continued our pursuit to draft a DefOps{empty}footnote:defops[] plan.
|
||||
endif::[]
|
||||
ifdef::legacy-footnoteref[]
|
||||
Despite the assault, we continued our pursuit to draft a DefOps{empty}footnoteref:[defops] plan.
|
||||
endif::[]
|
||||
|
||||
.DefOps Plan
|
||||
====
|
||||
Click btn:[Download Zip] to download the defensive operation plan bundle.
|
||||
|
||||
OMG!
|
||||
Somebody please save us now!
|
||||
I want my mum -- and an extra-large double macchiato, please.
|
||||
====
|
||||
|
||||
Unfortunately, Lazarus and I had both come to the conclusion that we weren't going to get out of this without corrupted hardrives if we didn't locate caffeine within the next few hours.
|
||||
|
||||
=== A Recipe for Potion That Will Ensure You Win the Hearts of Developers
|
||||
|
||||
This potion for a sample document contains the following ingredients, which are listed in a very random, chaotically nested order.
|
||||
|
||||
.Ingredients for Potion that Demystifies Documents
|
||||
* all the headings
|
||||
** syntax highlighted source code
|
||||
*** non-syntax highlighted source code or just a listing block
|
||||
* quote block
|
||||
** verse block
|
||||
*** table with some cell formatting
|
||||
**** sequential paragraphs
|
||||
***** admonition blocks, but use them sparingly
|
||||
*** bullet list with nesting
|
||||
** numbered list with nesting
|
||||
** definition list
|
||||
*** sidebar
|
||||
* example block
|
||||
** block image (no inline images)
|
||||
*** inline formatting in a paragraph
|
||||
**** two fresh Burdockian leaves
|
||||
***** They must be harvested by the light of the teal moons.
|
||||
|
||||
Are you square?
|
||||
|
||||
[square]
|
||||
* one
|
||||
* two
|
||||
* three
|
||||
|
||||
What is there to do?
|
||||
|
||||
* [x] Done
|
||||
* [ ] Next
|
||||
* Who's counting?
|
||||
|
||||
==== Searching for Burdockian
|
||||
|
||||
.Steps for finding and preparing Burdockian leaves
|
||||
. Locate dusty botany
|
||||
.. Sneeze
|
||||
... Sneeze some more
|
||||
. Find section on Burdockian
|
||||
.. Review its characteristics
|
||||
... Take a picture of the diagram of its leaves
|
||||
.... Don't rip out the picture like a troglodyte
|
||||
..... Don't do it, I'm watching you
|
||||
. Put on your hiking boots
|
||||
. Freeze your butt off on the side of a mountain at midnight
|
||||
|
||||
Let's skip a few steps and start counting from 10.
|
||||
|
||||
[start=10]
|
||||
. arabic (10)
|
||||
.. loweralpha (a)
|
||||
... lowerroman (i)
|
||||
... lowerroman (ii)
|
||||
... lowerroman (iii)
|
||||
... lowerroman (iv)
|
||||
.... upperalpha (A)
|
||||
. arabic (11)
|
||||
|
||||
It's time for a top 5 list, made using the `reversed` option on an ordered list!
|
||||
|
||||
[%reversed]
|
||||
. Stone Imperial Russian Stout
|
||||
. Pliny the Elder
|
||||
. Chimay Grande Réserve (Blue)
|
||||
. St. Bernardus Abt 12
|
||||
. Westvleteren 12 (XII)
|
||||
|
||||
How about a list with some terms?
|
||||
|
||||
* Fruits
|
||||
|
||||
Apple::
|
||||
The round fruit of a tree of the rose family, which typically has thin red or green skin and crisp flesh.
|
||||
Yes, I said _flesh_.
|
||||
|
||||
Pear::
|
||||
A yellowish- or brownish-green edible fruit that is typically narrow at the stalk and wider toward the base, with sweet, slightly gritty flesh.
|
||||
More flesh.
|
||||
Mmmmm.
|
||||
|
||||
* Vegetables
|
||||
|
||||
Carrot::
|
||||
An orange-colored root eaten as a vegetable.
|
||||
Beware, it's a favorite of the Wolpertinger.
|
||||
|
||||
===== Are You Still Here?
|
||||
|
||||
.Move, move, move!
|
||||
[CAUTION]
|
||||
====
|
||||
The Wolpertingers can smell your procrastination.
|
||||
It's not their fault you can't find your boots.
|
||||
====
|
||||
|
||||
====== Sigh...
|
||||
|
||||
TIP: Your boots are in your closet.
|
||||
|
||||
== Dawn on the Plateau
|
||||
|
||||
Lazarus was hanging from the bottom limb of a Burdockian tree, licking the bark.
|
||||
|
||||
[quote,Mark Tobey]
|
||||
On pavements and the bark of trees I have found whole worlds.
|
||||
|
||||
"`If there are whole worlds on that bark, he just swallowed them,`" Kizmet replied.
|
||||
|
||||
[verse,The documentation attorneys]
|
||||
____
|
||||
No bark was harmed in the making of this potion.
|
||||
We're not so sure about a couple ants though.
|
||||
|
||||
Nor those worlds...
|
||||
|
||||
Crap, I smell an injunction.
|
||||
____
|
||||
|
||||
We'd retrieved the leaves, but we'd obviously lost our minds in the process.
|
||||
|
||||
[verse]
|
||||
Roses are +++<span style="color: #FF0000">red</span>+++.
|
||||
Violets are +++<span style="color: #0000FF">blue</span>+++__-ish__.
|
||||
|
||||
== Words Seasoned with Power
|
||||
|
||||
To _tame_ the [.wild]#wild# wolpertingers, we needed to build a *charm*.
|
||||
But **ul**timate victory could only be won if we divined the *_true name_* of the __war__lock.
|
||||
|
||||
"`What kind of charm?`" Lazarus asked. "`An odoriferous one or a mineral one?`"
|
||||
Kizmet shrugged. "`The note from Olaf's desk says '`wormwood and licorice,`' but these could be normal groceries for werewolves.`"
|
||||
|
||||
"`Well the H~2~O written on the security whiteboard could be part of a shopping list, but I don't think the local bodega also sells e = mc^2^,`" Lazarus replied.
|
||||
|
||||
"`Wait!`" Indigo plucked a small vial from her desk's top drawer and held it toward us.
|
||||
The vial's label read '```e = mc^2^ *_the scent of science_* _smells like a genius_```'.
|
||||
|
||||
=== Can I Get Some `Code`?
|
||||
|
||||
[%hardbreaks]
|
||||
Sure.
|
||||
Have a listing block.
|
||||
|
||||
----
|
||||
This is an example of a listing block.
|
||||
The content inside is rendered as <pre> text.
|
||||
----
|
||||
|
||||
But I'm not giving you any highlighting shazam just yet.
|
||||
|
||||
.What is a listing block?
|
||||
****
|
||||
Like literal blocks, the content in listing blocks is displayed exactly as you entered it.
|
||||
Listing block content is rendered as `<pre>` text.
|
||||
|
||||
The `listing` style is applied to an element, such as a paragraph, by setting the `listing` attribute on that element.
|
||||
****
|
||||
|
||||
Let's get our #((highlighting))# on!
|
||||
|
||||
<<<
|
||||
|
||||
Install Prawn:
|
||||
|
||||
$ gem install prawn
|
||||
|
||||
Then create your first PDF document in Ruby!
|
||||
|
||||
.Generates a basic PDF document using Prawn
|
||||
[source,ruby]
|
||||
----
|
||||
require 'prawn' # <1>
|
||||
|
||||
Prawn::Document.generate 'output.pdf' do # <3>
|
||||
text 'Hello, World!' # <2>
|
||||
end
|
||||
----
|
||||
<1> Imports Prawn library
|
||||
<2> Adds text “Hello, World!” to first page
|
||||
<3> Writes PDF to [file]_output.pdf_ after executing all statements
|
||||
|
||||
How about some source code that styles code? So meta!
|
||||
|
||||
[source,css]
|
||||
----
|
||||
code {
|
||||
padding: 2px 4px;
|
||||
font-size: 90%;
|
||||
font-weight: normal;
|
||||
color: #c7254e;
|
||||
white-space: nowrap !important;
|
||||
background-color: #f9f2f4;
|
||||
border-radius: 4px;
|
||||
}
|
||||
----
|
||||
|
||||
Where could we go without some Java(TM)?
|
||||
Naturally, some autosizing is necessary.
|
||||
|
||||
[source%autofit,java]
|
||||
----
|
||||
package org.javaee7.cdi.events;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.enterprise.event.Observes;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.*;
|
||||
|
||||
/**
|
||||
* This session-scoped bean receives greeting strings from the event bus
|
||||
* and provides access to the collection of these greetings via a REST API.
|
||||
*
|
||||
* @author The Duke
|
||||
* @since 1.0
|
||||
*/
|
||||
@SessionScoped
|
||||
public class GreetingReceiver implements EventReceiver, Serializable {
|
||||
|
||||
private List<String> greetings;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
this.greetings = new ArrayList<String>();
|
||||
}
|
||||
|
||||
void receive(@Observes String greet) {
|
||||
this.greetings.add(greet);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
public List<String> listAll(@QueryParam("start") Integer start, @QueryParam("max") Integer max) {
|
||||
int numGreetings = this.greetings.size();
|
||||
|
||||
if (numGreetings == 0 || max == 0) {
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
if (start == null) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (max == null) {
|
||||
max = numGreetings;
|
||||
}
|
||||
|
||||
return this.greetings.subList(start, Math.min(max + start, numGreetings));
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
We already showed you an XML example in <<ravages>>, a language we often rant about over beers at <<bier-central>>.
|
||||
|
||||
I'll trade you a little table for some of that bark.
|
||||
|
||||
[cols=4,frame=topbot,grid=rows]
|
||||
|===
|
||||
|Column 1 |Column 2 |Column 3 |Column 4
|
||||
|
||||
^m|Prefix `{vbar}` with `{caret}` to center content horizontally within the cell.
|
||||
.>|Prefix `{vbar}` with a `.` and `>` to align content to the bottom of the cell.
|
||||
^.^|Prefix `{vbar}` with a `^`, `.`, and `^` to place content in the middle of the cell.
|
||||
>|Prefix `{vbar}` with `>` to align content to the right horizontally within the cell.
|
||||
|
||||
4+^e|This content spans all four columns (`4{plus}`) and is centered horizontally (`{caret}`) within the cell.
|
||||
|===
|
||||
|
||||
Wait.
|
||||
What?
|
||||
Where is this story going?
|
||||
|
||||
`<span>`:: an html tag that makes me crazy
|
||||
|
||||
align:: something I never get going in the right direction.
|
||||
Also has to do with my poor verbal communication skills
|
||||
|
||||
float::
|
||||
style::
|
||||
don't make me laugh
|
||||
|
||||
Does anyone have the time?
|
||||
|
||||
Tg lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumj.
|
||||
|
||||
== Keeping It Together
|
||||
|
||||
On this page we have nested "`keep together`" logic.
|
||||
The combined block will be shifted to the next page if there isn't room available on this one.
|
||||
|
||||
[verse]
|
||||
First,
|
||||
we
|
||||
need
|
||||
to
|
||||
waste
|
||||
several
|
||||
lines
|
||||
using
|
||||
a
|
||||
verse
|
||||
to
|
||||
push
|
||||
the
|
||||
next
|
||||
block
|
||||
to
|
||||
its
|
||||
breaking
|
||||
point.
|
||||
|
||||
[NOTE]
|
||||
.What happens if there is both a field and a method with the same name?
|
||||
====
|
||||
Back to the previous example, suppose that we have both a field and a method with the same name, as in:
|
||||
|
||||
.Java class with a field and method that share the same name
|
||||
[source,java]
|
||||
----
|
||||
public class Foo {
|
||||
public String bar;
|
||||
|
||||
public String bar() {
|
||||
return bar;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
*Golo resolves methods first, fields last.*
|
||||
Hence, the following Golo code will resolve the `bar()` method, not the `bar` field:
|
||||
|
||||
.Golo picks the method over the field with the same name
|
||||
[source,golo]
|
||||
----
|
||||
let foo = Foo()
|
||||
|
||||
foo: bar("baz") # <1>
|
||||
|
||||
println(foo: bar()) # <2>
|
||||
----
|
||||
<1> Writes the field
|
||||
<2> Calls the `bar()` method
|
||||
====
|
||||
|
||||
<<<
|
||||
|
||||
Here's a preview of how each heading level is rendered.
|
||||
|
||||
[discrete]
|
||||
= Heading 1 (Level 0)
|
||||
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
== Heading 2 (Level 1)
|
||||
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
=== Heading 3 (Level 2)
|
||||
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
==== Heading 4 (Level 3)
|
||||
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
===== Heading 5 (Level 4)
|
||||
|
||||
filler content
|
||||
|
||||
[discrete]
|
||||
====== Heading 6 (Level 5)
|
||||
|
||||
filler content
|
||||
|
||||
---
|
||||
|
||||
--
|
||||
Here's some content inside an open block.
|
||||
--
|
||||
|
||||
[appendix]
|
||||
== Credits
|
||||
|
||||
.Brought to you with icon:heart[set=fas,role=love] by OpenDevise
|
||||
[%header%footer,cols="2,2s,^4",grid=rows,frame=topbot,width=75%,caption=]
|
||||
|===
|
||||
|Name |Title |Alias
|
||||
|
||||
|Sarah White
|
||||
|President
|
||||
|http://twitter.com/carbonfray[@carbonfray]
|
||||
|
||||
|Dan Allen
|
||||
|Vice President
|
||||
|http://twitter.com/mojavelinux[@mojavelinux]
|
||||
|
||||
3+^.e|Powered by Open Source
|
||||
|===
|
||||
|
||||
[index]
|
||||
== Index
|
||||
@@ -0,0 +1,21 @@
|
||||
= Asciidoctor Changelog
|
||||
|
||||
http://asciidoctor.org[Asciidoctor] is an open source text processor and publishing toolchain for converting http://asciidoctor.org[AsciiDoc] markup into HTML, DocBook and custom formats.
|
||||
|
||||
This document provides a high-level view of the changes introduced in Asciidoctor by release.
|
||||
For a detailed view of what has changed, refer to the https://github.com/asciidoctor/asciidoctor/commits/master[commit history] on GitHub.
|
||||
|
||||
== 0.1.4 (2013-09-05) - @mojavelinux
|
||||
|
||||
Performance::
|
||||
|
||||
* 15% increase in speed compared to 0.1.3
|
||||
|
||||
Enhancements::
|
||||
|
||||
* updated xref inline macro to support inter-document references (#417)
|
||||
|
||||
|
||||
Bug Fixes::
|
||||
|
||||
* lowercase attribute names passed to API (#508)
|
||||
@@ -0,0 +1,28 @@
|
||||
= Simple Inventory API
|
||||
You <you@your-company.com>
|
||||
v1.0.0
|
||||
|
||||
== Overview
|
||||
This is a simple API
|
||||
|
||||
=== License
|
||||
[%hardbreaks]
|
||||
http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
|
||||
|
||||
== Servers
|
||||
* https://{username}.gigantic-server.com:{port}/{basePath}
|
||||
+
|
||||
The production API server
|
||||
+
|
||||
.Variables
|
||||
username:: *this* __value__ is assigned by the service provider, in this example `gigantic-server.com`
|
||||
Possible Values::: Any
|
||||
Default::: demo
|
||||
port::
|
||||
Possible Values:::
|
||||
- 8443
|
||||
- 443
|
||||
Default::: 8443
|
||||
basePath::
|
||||
Possible Values::: Any
|
||||
Default::: v2
|
||||
14
swagger2markup-asciidoc/src/test/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true">
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="io.github.swagger2markup" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
40
swagger2markup-bom/README.adoc
Normal file
@@ -0,0 +1,40 @@
|
||||
= swagger2markup-bom
|
||||
|
||||
generates BOM (Bill Of Materials) to control used version of swagger2markup projects in a single place.
|
||||
|
||||
.Maven's example:
|
||||
[source,xml]
|
||||
----
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- Import dependency management from Swagger2Markup -->
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup-bom</artifactId>
|
||||
<version>0.14.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
----
|
||||
|
||||
.Gradle example:
|
||||
[source,groovy]
|
||||
----
|
||||
dependencies {
|
||||
implementation 'io.github.swagger2markup:swagger2markup-bom:0.14.0'
|
||||
|
||||
implementation 'io.github.swagger2markup:swagger2markup-core'
|
||||
}
|
||||
----
|
||||
|
||||
== License
|
||||
|
||||
Copyright {docyear} Alexey Shirmanov
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
53
swagger2markup-bom/build.gradle
Normal file
@@ -0,0 +1,53 @@
|
||||
description = "swagger2markup bom"
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
def projectArtifactId = 'swagger2markup'
|
||||
def url = 'https://github.com/Swagger2Markup/swagger2markup'
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler',
|
||||
'austek': 'Ali Ustek']
|
||||
|
||||
asNode().appendNode('packaging', 'pom')
|
||||
|
||||
def license = asNode().appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt')
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
def root = asNode()
|
||||
|
||||
root.appendNode('name', "${projectArtifactId}")
|
||||
root.appendNode('url', "${url}")
|
||||
root.appendNode('description', project.description)
|
||||
|
||||
asNode().appendNode('scm').appendNode('url', 'https://github.com/Swagger2Markup/swagger2markup.git')
|
||||
|
||||
Node deps = asNode().appendNode('dependencyManagement').appendNode('dependencies')
|
||||
coreProjects.each {
|
||||
Node dep = deps.appendNode('dependency')
|
||||
dep.appendNode('groupId').value = it.group
|
||||
dep.appendNode('artifactId').value = it.name
|
||||
dep.appendNode('version').value = it.version
|
||||
}
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
def d = developers.appendNode('developer')
|
||||
d.appendNode('id', it.key)
|
||||
d.appendNode('name', it.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
122
swagger2markup-builder/README.adoc
Normal file
@@ -0,0 +1,122 @@
|
||||
= MarkupDocBuilder
|
||||
:author: Robert Winkler
|
||||
:version: 1.1.1
|
||||
:hardbreaks:
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Markup document builder (AsciiDoc, Markdown and ConfluenceWiki). The primary goal of this project is to simplify the creation of Markup documents. The builder is used by https://github.com/RobWin/swagger2markup[swagger2markup].
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
=== Usage
|
||||
=== Adding MarkupDocBuilder to your project
|
||||
The project is published in JCenter and Maven Central.
|
||||
|
||||
==== Maven
|
||||
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependency>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>markup-document-builder</artifactId>
|
||||
<version>{version}</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
==== Gradle
|
||||
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:markup-document-builder:{version}"
|
||||
----
|
||||
|
||||
=== Using MarkupDocBuilder
|
||||
|
||||
The MarkupDocBuilder allows to build an AsciiDoc or Markdown document via the Builder pattern.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableRowsInPSV = new ArrayList<>();
|
||||
tableRowsInPSV.add("Header 1 | Header 2 | Header2");
|
||||
tableRowsInPSV.add("Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3");
|
||||
tableRowsInPSV.add("Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToAsciiDocFile() throws IOException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.documentTitle("Test title")
|
||||
.sectionTitleLevel1("Section Level 1a")
|
||||
.sectionTitleLevel2("Section Level 2a")
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
.italicTextLine("Italic text line b")
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToMarkdownDocFile() throws IOException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.documentTitle("Test title")
|
||||
.sectionTitleLevel1("Section Level 1a")
|
||||
.sectionTitleLevel2("Section Level 2a")
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
.italicTextLine("Italic text line b")
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
=== Generated HTML using AsciidoctorJ
|
||||
You can generate your PDF or HTML documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/aalmiray/markdown-gradle-plugin[markdown-gradle-plugin].
|
||||
|
||||
image::images/asciidoc_html.jpg[asciidoc_html]
|
||||
|
||||
== License
|
||||
|
||||
Copyright {docyear} Robert Winkler
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
18
swagger2markup-builder/build.gradle
Normal file
@@ -0,0 +1,18 @@
|
||||
ext.moduleName='io.github.swagger2markup.markup-document-builder'
|
||||
|
||||
dependencies {
|
||||
configurations.all {
|
||||
resolutionStrategy.force dependencyOverrides.commonsIO
|
||||
resolutionStrategy.force dependencyOverrides.slf4j
|
||||
}
|
||||
implementation implLibraries.commonsCodec
|
||||
implementation implLibraries.commonsLang3
|
||||
implementation implLibraries.commonsIO
|
||||
implementation implLibraries.mark2Ascii
|
||||
implementation implLibraries.slf4j
|
||||
implementation implLibraries.pegdown
|
||||
testImplementation testLibraries.assertjDiff
|
||||
testImplementation testLibraries.junit
|
||||
testImplementation testLibraries.logback
|
||||
testImplementation testLibraries.mockito
|
||||
}
|
||||
BIN
swagger2markup-builder/images/asciidoc_html.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum LineSeparator {
|
||||
/**
|
||||
* Line separator for Unix systems (<code>\n</code>).
|
||||
*/
|
||||
UNIX("\n"),
|
||||
/**
|
||||
* Line separator for Windows systems (<code>\r\n</code>).
|
||||
*/
|
||||
WINDOWS("\r\n"),
|
||||
/**
|
||||
* Line separator for Macintosh systems (<code>\r</code>).
|
||||
*/
|
||||
MAC("\r");
|
||||
|
||||
private String lineSeparator;
|
||||
|
||||
LineSeparator(String lineSeparator) {
|
||||
this.lineSeparator = lineSeparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return lineSeparator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum MarkupAdmonition {
|
||||
NOTE,
|
||||
TIP,
|
||||
IMPORTANT,
|
||||
CAUTION,
|
||||
WARNING
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
public enum MarkupBlockStyle {
|
||||
SIDEBAR,
|
||||
EXAMPLE,
|
||||
LITERAL,
|
||||
LISTING,
|
||||
PASSTHROUGH
|
||||
}
|
||||
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface MarkupDocBuilder {
|
||||
|
||||
/**
|
||||
* Builds a document section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder documentTitle(String title);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel(int level, String title);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel(int, String, String) sectionTitleWithAnchorLevel(level, title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @param level section title level [1, 5]
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel1(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel1(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 1 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel1(String, String) sectionTitleWithAnchorLevel1(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel1(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel2(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel2(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 2 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel2(String, String) sectionTitleWithAnchorLevel2(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel2(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel3(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel3(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 3 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel3(String, String) sectionTitleWithAnchorLevel3(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel3(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel4(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel4(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 4 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel4(String, String) sectionTitleWithAnchorLevel4(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel4(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleLevel5(String title);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title} with a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param title title
|
||||
* @param anchor custom anchor. If null, auto-generate the anchor from the normalized title.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel5(String title, String anchor);
|
||||
|
||||
/**
|
||||
* Builds a level 5 section {@code title} with an auto-generated anchor from the normalized title, for later reference.<br>
|
||||
* This is an alias for {@link #sectionTitleWithAnchorLevel5(String, String) sectionTitleWithAnchorLevel5(title, null)}.
|
||||
*
|
||||
* @param title title
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder sectionTitleWithAnchorLevel5(String title);
|
||||
|
||||
/**
|
||||
* Builds a regular text line.<br>
|
||||
* This is an alias for {@link #textLine(String, boolean) textLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder textLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a regular text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder textLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a regular text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder text(String text);
|
||||
|
||||
/**
|
||||
* Builds a text paragraph.<br>
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @param hardbreaks force hardbreaks on all lines
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder paragraph(String text, boolean hardbreaks);
|
||||
|
||||
/**
|
||||
* Builds a text paragraph.<br>
|
||||
* This is an alias for {@link #paragraph(String, boolean) paragraph(text, false)}.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder paragraph(String text);
|
||||
|
||||
/**
|
||||
* Insert a page break
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder pageBreak();
|
||||
|
||||
/**
|
||||
* Builds a block of {@code text} with specified {@code style}.
|
||||
*
|
||||
* @param text text
|
||||
* @param style block style
|
||||
* @param title an optional title for the block. No title if null.
|
||||
* @param admonition an optional admonition for the block. No admonition if null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder block(String text, MarkupBlockStyle style, String title, MarkupAdmonition admonition);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a block of {@code text} with specified {@code style}.<br>
|
||||
* This is an alias for {@link #block(String, MarkupBlockStyle, String, MarkupAdmonition) block(String, MarkupBlockStyle, null, null)}.
|
||||
*
|
||||
* @param text text
|
||||
* @param style block style
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder block(String text, MarkupBlockStyle style);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a source code block using the specified {@code language}.<br>
|
||||
* Line breaks are respected.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @param language source code language. Simple listing if {@code language} == null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder listingBlock(String text, String language);
|
||||
|
||||
|
||||
/**
|
||||
* Builds a listing text block.<br>
|
||||
* This is an alias for {@link #listingBlock(String, String) listingBlock(String, null)}.
|
||||
*
|
||||
* @param text multi-line text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder listingBlock(String text);
|
||||
|
||||
/**
|
||||
* Builds a literal text line.<br>
|
||||
* This is an alias for {@link #literalTextLine(String, boolean) literalTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a literal text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a literal text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder literalText(String text);
|
||||
|
||||
/**
|
||||
* Builds a bold text line.<br>
|
||||
* This is an alias for {@link #boldTextLine(String, boolean) boldTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds a bold text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds a bold text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder boldText(String text);
|
||||
|
||||
/**
|
||||
* Builds an italic text line.<br>
|
||||
* This is an alias for {@link #italicTextLine(String, boolean) italicTextLine(text, false)}.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicTextLine(String text);
|
||||
|
||||
/**
|
||||
* Builds an italic text line.
|
||||
*
|
||||
* @param text text
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicTextLine(String text, boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Builds an italic text.
|
||||
*
|
||||
* @param text text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder italicText(String text);
|
||||
|
||||
/**
|
||||
* Builds an unordered item list
|
||||
*
|
||||
* @param list list of items
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder unorderedList(List<String> list);
|
||||
|
||||
/**
|
||||
* Builds a single list item
|
||||
*
|
||||
* @param item item
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder unorderedListItem(String item);
|
||||
|
||||
/**
|
||||
* Builds a table without column specifiers, using specified cell values.<br>
|
||||
* This is an alias for {@link #tableWithColumnSpecs(List, List) tableWithColumnSpecs(null, cells)}.<br>
|
||||
* Limited support : Markdown does not support table without headers.
|
||||
*
|
||||
* @param cells cell values
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder table(List<List<String>> cells);
|
||||
|
||||
/**
|
||||
* Builds a table with column specifiers, using specified cell values.
|
||||
*
|
||||
* @param columnSpecs list of column specifiers. Ignored if null.
|
||||
* @param cells cell values
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells);
|
||||
|
||||
/**
|
||||
* Builds a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.<br>
|
||||
* Limited support : Markdown does not support default text for anchors, and will ignore {@code text}.
|
||||
*
|
||||
* @param anchor custom anchor
|
||||
* @param text default text to display when a cross-reference does not have text itself. Ignored if null.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder anchor(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds a custom {@code anchor} for later reference.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor custom anchor
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder anchor(String anchor);
|
||||
|
||||
/**
|
||||
* Builds an inter-document cross-reference to {@code document}#{@code anchor} with specified {@code text}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String, String, String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param document document to point to. Reference becomes a simple cross-reference if null.
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor} with specified {@code text}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String, String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor}.<br>
|
||||
* This is the "raw anchor" version. Use the preferred method {@link #crossReference(String)} instead.<br>
|
||||
* Specified {@code anchor} is built as-is, without any normalization.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReferenceRaw(String anchor);
|
||||
|
||||
/**
|
||||
* Builds an inter-document cross-reference to {@code document}#{@code anchor} with specified {@code text}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param document document to point to. Reference becomes a simple cross-reference if null.
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String document, String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor} with specified {@code text}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @param text display text
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String anchor, String text);
|
||||
|
||||
/**
|
||||
* Builds an cross-reference to local document {@code anchor}.<br>
|
||||
* Specified {@code anchor} will be normalized anyway.
|
||||
*
|
||||
* @param anchor anchor to point to
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder crossReference(String anchor);
|
||||
|
||||
/**
|
||||
* Builds a newline using {@code System.getProperty("line.separator")}.<br>
|
||||
* This is an alias for {@link #newLine(boolean) newLine(false)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder newLine();
|
||||
|
||||
/**
|
||||
* Builds a newline using {@code System.getProperty("line.separator")}.
|
||||
*
|
||||
* @param forceLineBreak add an explicit line break if true.
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder newLine(boolean forceLineBreak);
|
||||
|
||||
/**
|
||||
* Import some markup text into this builder.<br>
|
||||
* This is an alias for {@link #importMarkup(Reader, MarkupLanguage, int) importMarkup(markupText, markupLanguage, 0)}.
|
||||
*
|
||||
* @param markupText markup reader to read data from
|
||||
* @param markupLanguage identify the imported markup language
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage);
|
||||
|
||||
/**
|
||||
* Import some markup text into this builder.<br>
|
||||
* If {@code markupLanguage} is different from current builder language, markupText is converted when supported, or conversion is just ignored.<br>
|
||||
* Currently supported conversions :
|
||||
* <ul>
|
||||
* <li> Markdown -> AsciiDoc </li>
|
||||
* </ul>
|
||||
* Newlines are normalized in the process.
|
||||
*
|
||||
* @param markupText markup reader to read data from
|
||||
* @param markupLanguage identify the imported markup language
|
||||
* @param levelOffset adapt section leveling by adding {@code levelOffset} [-5, 5]
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if levelOffset is too high for the imported markup
|
||||
*/
|
||||
MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset);
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Configure this builder to prefix all generated anchors with {@code prefix}.
|
||||
*
|
||||
* @param prefix anchor prefix
|
||||
* @return this builder
|
||||
*/
|
||||
MarkupDocBuilder withAnchorPrefix(String prefix);
|
||||
|
||||
/**
|
||||
* @return anchor prefix configuration
|
||||
*/
|
||||
String getAnchorPrefix();
|
||||
|
||||
/**
|
||||
* Builds a new instance of this builder with a state copy.
|
||||
*
|
||||
* @param copyBuffer copy current buffer into the new instance
|
||||
* @return new builder instance with a state copy
|
||||
*/
|
||||
MarkupDocBuilder copy(boolean copyBuffer);
|
||||
|
||||
/**
|
||||
* Add an extension to fileName depending on markup language.
|
||||
*
|
||||
* @param fileName without extension
|
||||
* @return fileName with an extension
|
||||
*/
|
||||
String addFileExtension(String fileName);
|
||||
|
||||
/**
|
||||
* Add an extension to file depending on markup language.
|
||||
*
|
||||
* @param file without extension
|
||||
* @return file with an extension
|
||||
*/
|
||||
Path addFileExtension(Path file);
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.<br>
|
||||
* An extension will be dynamically added to fileName depending on the markup language.
|
||||
*
|
||||
* @param file the generated file without extension
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
void writeToFile(Path file, Charset charset, OpenOption... options);
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.
|
||||
*
|
||||
* @param file the generated file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
void writeToFileWithoutExtension(Path file, Charset charset, OpenOption... options);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.asciidoc.AsciiDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.confluenceMarkup.ConfluenceMarkupBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.markdown.MarkdownBuilder;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public final class MarkupDocBuilders {
|
||||
|
||||
private MarkupDocBuilders() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MarkupDocBuilder which uses the system line separator.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return a MarkupDocBuilder
|
||||
*/
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage) {
|
||||
switch (markupLanguage) {
|
||||
case MARKDOWN:
|
||||
return new MarkdownBuilder();
|
||||
case ASCIIDOC:
|
||||
return new AsciiDocBuilder();
|
||||
case CONFLUENCE_MARKUP:
|
||||
return new ConfluenceMarkupBuilder();
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported markup language %s", markupLanguage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MarkupDocBuilder which uses a custom line separator.
|
||||
* If the custom line separator is null, it uses the system line separator.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param lineSeparator the line separator which should be used
|
||||
* @return a MarkupDocBuilder
|
||||
*/
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage, LineSeparator lineSeparator) {
|
||||
switch (markupLanguage) {
|
||||
case MARKDOWN:
|
||||
if (lineSeparator == null)
|
||||
return new MarkdownBuilder();
|
||||
else
|
||||
return new MarkdownBuilder(lineSeparator.toString());
|
||||
case ASCIIDOC:
|
||||
if (lineSeparator == null)
|
||||
return new AsciiDocBuilder();
|
||||
else
|
||||
return new AsciiDocBuilder(lineSeparator.toString());
|
||||
case CONFLUENCE_MARKUP:
|
||||
if (lineSeparator == null)
|
||||
return new ConfluenceMarkupBuilder();
|
||||
else
|
||||
return new ConfluenceMarkupBuilder(lineSeparator.toString());
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported markup language %s", markupLanguage));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a MarkupDocBuilder which uses a custom line separator.
|
||||
* If the custom line separator is null, it uses the system line separator.
|
||||
* There is a possibility asciidoc generator pegdown (<a href="https://github.com/sirthias/pegdown#parsing-timeouts">optional</a>) can
|
||||
* take more time. The default is set to two seconds. To override pass value greater than two seconds.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param lineSeparator the line separator which should be used
|
||||
* @param asciidocPegdownTimeoutMillis asciidoc generator timeout
|
||||
* @return a MarkupDocBuilder
|
||||
*/
|
||||
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage, LineSeparator lineSeparator, int asciidocPegdownTimeoutMillis) {
|
||||
switch (markupLanguage) {
|
||||
case MARKDOWN:
|
||||
if (lineSeparator == null)
|
||||
return new MarkdownBuilder();
|
||||
else
|
||||
return new MarkdownBuilder(lineSeparator.toString());
|
||||
case ASCIIDOC:
|
||||
if (lineSeparator == null)
|
||||
return new AsciiDocBuilder(asciidocPegdownTimeoutMillis);
|
||||
else
|
||||
return new AsciiDocBuilder(lineSeparator.toString(), asciidocPegdownTimeoutMillis);
|
||||
case CONFLUENCE_MARKUP:
|
||||
if (lineSeparator == null)
|
||||
return new ConfluenceMarkupBuilder();
|
||||
else
|
||||
return new ConfluenceMarkupBuilder(lineSeparator.toString());
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported markup language %s", markupLanguage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum MarkupLanguage {
|
||||
ASCIIDOC(".adoc,.asciidoc"),
|
||||
MARKDOWN(".md,.markdown"),
|
||||
CONFLUENCE_MARKUP(".txt");
|
||||
|
||||
private final String fileNameExtensions;
|
||||
|
||||
/**
|
||||
* @param fileNameExtensions file name suffix
|
||||
*/
|
||||
private MarkupLanguage(final String fileNameExtensions) {
|
||||
this.fileNameExtensions = fileNameExtensions;
|
||||
}
|
||||
|
||||
public List<String> getFileNameExtensions() {
|
||||
return Arrays.asList(fileNameExtensions.split(","));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MarkupTableColumn {
|
||||
public String header;
|
||||
public boolean headerColumn = false;
|
||||
public Integer widthRatio = 0;
|
||||
public Map<MarkupLanguage, String> markupSpecifiers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
public MarkupTableColumn() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Header constructor.
|
||||
*
|
||||
* @param header header name
|
||||
*/
|
||||
public MarkupTableColumn(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Header and specifiers constructor.
|
||||
*
|
||||
* @param header header
|
||||
* @param headerColumn set column as an header column.
|
||||
* @param widthRatio width ratio
|
||||
*/
|
||||
public MarkupTableColumn(String header, boolean headerColumn, Integer widthRatio) {
|
||||
this.header = header;
|
||||
this.headerColumn = headerColumn;
|
||||
this.widthRatio = widthRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set header name for this column.
|
||||
*
|
||||
* @param header header name
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withHeader(String header) {
|
||||
this.header = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column as an header column.<br>
|
||||
* Limited support : Markdown does not support header column and will ignore it.
|
||||
*
|
||||
* @param headerColumn configuration value
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withHeaderColumn(boolean headerColumn) {
|
||||
this.headerColumn = headerColumn;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column width ratio for this column.<br>
|
||||
* Limited support : Markdown does not support column width specifiers and will ignore {@code widthRatio}.
|
||||
*
|
||||
* @param widthRatio width ratio integer value [0-100]. Accept relative width specifiers (e.g.: 1, 2, 3, .. with sum of width ratios for all columns != 100).
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withWidthRatio(Integer widthRatio) {
|
||||
this.widthRatio = widthRatio;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides all other specifiers for the specified {@code language} with this language-dependent {@code specifiers} string.<br>
|
||||
* This method should be used as a last resort.
|
||||
*
|
||||
* @param language apply the {@code specifiers} to this language only
|
||||
* @param specifiers RAW language-dependent specifiers string for the column
|
||||
* @return this builder
|
||||
*/
|
||||
public MarkupTableColumn withMarkupSpecifiers(MarkupLanguage language, String specifiers) {
|
||||
this.markupSpecifiers.put(language, specifiers);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.text.Normalizer;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupBlockStyle;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.internal.asciidoc.AsciiDocConverterExtension;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
|
||||
/**
|
||||
* Explicit line break default behavior for line returns, when not specified. Please, change documentation accordingly.
|
||||
*/
|
||||
protected static final boolean LINE_BREAK_DEFAULT = false;
|
||||
|
||||
protected static final Pattern ANCHOR_UNIGNORABLE_PATTERN = Pattern.compile("[^0-9a-zA-Z-_]+");
|
||||
protected static final Pattern ANCHOR_IGNORABLE_PATTERN = Pattern.compile("[\\s@#&(){}\\[\\]!$*%+=/:.;,?\\\\<>|]+");
|
||||
protected static final String ANCHOR_SEPARATION_CHARACTERS = "_-";
|
||||
protected static final int MAX_TITLE_LEVEL = 5;
|
||||
protected static final String NEW_LINES = "\\r\\n|\\r|\\n";
|
||||
protected static final String WHITESPACE = " ";
|
||||
protected static final int ASCIIDOC_PEGDOWN_DEFUALT_MILLIS = 2000;
|
||||
|
||||
protected StringBuilder documentBuilder = new StringBuilder();
|
||||
protected String newLine;
|
||||
protected int asciidocPegdownTimeoutMillis;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected String anchorPrefix = null;
|
||||
|
||||
public AbstractMarkupDocBuilder() {
|
||||
this(System.getProperty("line.separator"), ASCIIDOC_PEGDOWN_DEFUALT_MILLIS);
|
||||
}
|
||||
|
||||
public AbstractMarkupDocBuilder(String newLine) {
|
||||
this(newLine, ASCIIDOC_PEGDOWN_DEFUALT_MILLIS);
|
||||
}
|
||||
|
||||
public AbstractMarkupDocBuilder(String newLine, int asciidocPegdownTimeoutMillis) {
|
||||
this.newLine = newLine;
|
||||
this.asciidocPegdownTimeoutMillis = asciidocPegdownTimeoutMillis;
|
||||
}
|
||||
|
||||
protected abstract MarkupLanguage getMarkupLanguage();
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder withAnchorPrefix(String prefix) {
|
||||
this.anchorPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnchorPrefix() {
|
||||
return this.anchorPrefix;
|
||||
}
|
||||
|
||||
protected void documentTitle(Markup markup, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
documentBuilder.append(markup).append(replaceNewLinesWithWhiteSpace(title)).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel(Markup markup, int level, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleWithAnchorLevel(Markup markup, int level, String title, String anchor) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
documentBuilder.append(newLine);
|
||||
if (anchor == null)
|
||||
anchor = title;
|
||||
anchor(replaceNewLinesWithWhiteSpace(anchor)).newLine();
|
||||
documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title) {
|
||||
return sectionTitleWithAnchorLevel(level, title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel1(String title) {
|
||||
return sectionTitleLevel(1, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel1(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(1, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel1(String title) {
|
||||
return sectionTitleWithAnchorLevel1(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel2(String title) {
|
||||
return sectionTitleLevel(2, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel2(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(2, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel2(String title) {
|
||||
return sectionTitleWithAnchorLevel2(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel3(String title) {
|
||||
return sectionTitleLevel(3, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel3(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(3, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel3(String title) {
|
||||
return sectionTitleWithAnchorLevel3(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel4(String title) {
|
||||
return sectionTitleLevel(4, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel4(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(4, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel4(String title) {
|
||||
return sectionTitleWithAnchorLevel4(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel5(String title) {
|
||||
return sectionTitleLevel(5, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel5(String title, String anchor) {
|
||||
return sectionTitleWithAnchorLevel(5, title, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel5(String title) {
|
||||
return sectionTitleWithAnchorLevel5(title, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text, boolean forceLineBreak) {
|
||||
Validate.notNull(text, "text must not be null");
|
||||
text(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder textLine(String text) {
|
||||
textLine(text, LINE_BREAK_DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder text(String text) {
|
||||
Validate.notNull(text, "text must not be null");
|
||||
documentBuilder.append(replaceNewLines(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text) {
|
||||
return paragraph(text, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, MarkupBlockStyle style) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
return block(replaceNewLines(text), style, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
return listingBlock(replaceNewLines(text), null);
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup begin, String text, Markup end, boolean skipLeadingNewline) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin);
|
||||
if (!skipLeadingNewline)
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine);
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end).append(newLine);
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup begin, String text, Markup end) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin).append(newLine);
|
||||
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine);
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end).append(newLine);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
protected void delimitedTextWithoutLineBreaks(Markup begin, String text, Markup end) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (!StringUtils.isBlank(begin.toString()))
|
||||
documentBuilder.append(begin);
|
||||
documentBuilder.append(replaceNewLines(text));
|
||||
if (!StringUtils.isBlank(end.toString()))
|
||||
documentBuilder.append(end);
|
||||
}
|
||||
|
||||
protected void delimitedBlockText(Markup markup, String text) {
|
||||
delimitedBlockText(markup, text, markup);
|
||||
}
|
||||
|
||||
protected void delimitedTextWithoutLineBreaks(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text, markup);
|
||||
}
|
||||
|
||||
protected void literalText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalTextLine(String text, boolean forceLineBreak) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
literalText(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalTextLine(String text) {
|
||||
return literalTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void boldText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text, boolean forceLineBreak) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
boldText(replaceNewLines(text));
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldTextLine(String text) {
|
||||
return boldTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void italicText(Markup markup, String text) {
|
||||
delimitedTextWithoutLineBreaks(markup, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text, boolean forceLineBreak) {
|
||||
italicText(text);
|
||||
newLine(forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicTextLine(String text) {
|
||||
return italicTextLine(text, LINE_BREAK_DEFAULT);
|
||||
}
|
||||
|
||||
protected void unorderedList(Markup markup, List<String> list) {
|
||||
Validate.notEmpty(list, "list must not be empty");
|
||||
documentBuilder.append(newLine);
|
||||
for (String listEntry : list) {
|
||||
unorderedListItem(markup, listEntry);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
protected void unorderedListItem(Markup markup, String item) {
|
||||
Validate.notBlank(item, "item must not be blank");
|
||||
documentBuilder.append(markup).append(item).append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor) {
|
||||
Validate.notBlank(anchor, "anchor must not be blank");
|
||||
return anchor(anchor, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic normalization algorithm for all markups (less common denominator character set).
|
||||
* Key points :
|
||||
* - Anchor is normalized (Normalized.Form.NFD)
|
||||
* - Punctuations (excluding [-_]) and spaces are replaced with escape character (depends on markup : Markup.E)
|
||||
* - Beginning, ending separation characters [-_] are ignored, repeating separation characters are simplified (keep first one)
|
||||
* - Anchor is trimmed and lower cased
|
||||
* - If the anchor still contains forbidden characters (non-ASCII, ...), replace the whole anchor with an hash (MD5).
|
||||
* - Add the anchor prefix if configured
|
||||
*/
|
||||
protected String normalizeAnchor(Markup spaceEscape, String anchor) {
|
||||
String normalizedAnchor = defaultString(anchorPrefix) + anchor.trim();
|
||||
normalizedAnchor = Normalizer.normalize(normalizedAnchor, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
normalizedAnchor = ANCHOR_IGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll(spaceEscape.toString());
|
||||
normalizedAnchor = normalizedAnchor.replaceAll(String.format("([%1$s])([%1$s]+)", ANCHOR_SEPARATION_CHARACTERS), "$1");
|
||||
normalizedAnchor = StringUtils.strip(normalizedAnchor, ANCHOR_SEPARATION_CHARACTERS);
|
||||
normalizedAnchor = normalizedAnchor.trim().toLowerCase();
|
||||
|
||||
String validAnchor = ANCHOR_UNIGNORABLE_PATTERN.matcher(normalizedAnchor).replaceAll("");
|
||||
if (validAnchor.length() != normalizedAnchor.length())
|
||||
normalizedAnchor = DigestUtils.md5Hex(normalizedAnchor);
|
||||
else
|
||||
normalizedAnchor = validAnchor;
|
||||
|
||||
return normalizedAnchor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String anchor, String text) {
|
||||
return crossReferenceRaw(null, anchor, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String anchor) {
|
||||
return crossReferenceRaw(null, anchor, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String anchor, String text) {
|
||||
return crossReference(null, anchor, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String anchor) {
|
||||
return crossReference(null, anchor, null);
|
||||
}
|
||||
|
||||
protected void newLine(Markup markup, boolean forceLineBreak) {
|
||||
if (forceLineBreak)
|
||||
documentBuilder.append(markup);
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine() {
|
||||
newLine(LINE_BREAK_DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupText, "markupText must not be null");
|
||||
Validate.notNull(markupLanguage, "markupLanguage must not be null");
|
||||
return importMarkup(markupText, markupLanguage, 0);
|
||||
}
|
||||
|
||||
protected String convert(String markupText, MarkupLanguage markupLanguage) {
|
||||
if (markupLanguage == getMarkupLanguage())
|
||||
return markupText;
|
||||
else {
|
||||
if (markupLanguage == MarkupLanguage.MARKDOWN && getMarkupLanguage() == MarkupLanguage.ASCIIDOC) {
|
||||
return AsciiDocConverterExtension.convertMarkdownToAsciiDoc(markupText, asciidocPegdownTimeoutMillis) + newLine;
|
||||
} else {
|
||||
return markupText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void importMarkupStyle1(Pattern titlePattern, Markup titlePrefix, Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
Validate.isTrue(levelOffset <= MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) > max levelOffset (%d)", levelOffset, MAX_TITLE_LEVEL));
|
||||
Validate.isTrue(levelOffset >= -MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) < min levelOffset (%d)", levelOffset, -MAX_TITLE_LEVEL));
|
||||
|
||||
StringBuffer leveledText = new StringBuffer();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(markupText)) {
|
||||
String readLine;
|
||||
while ((readLine = bufferedReader.readLine()) != null) {
|
||||
Matcher titleMatcher = titlePattern.matcher(readLine);
|
||||
|
||||
while (titleMatcher.find()) {
|
||||
int titleLevel = titleMatcher.group(1).length() - 1;
|
||||
String title = titleMatcher.group(2);
|
||||
|
||||
if (titleLevel + levelOffset > MAX_TITLE_LEVEL)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) > max title level (%d)", levelOffset, title, titleLevel, MAX_TITLE_LEVEL));
|
||||
if (titleLevel + levelOffset < 0)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) < 0", levelOffset, title, titleLevel));
|
||||
else
|
||||
titleMatcher.appendReplacement(leveledText, Matcher.quoteReplacement(String.format("%s %s", StringUtils.repeat(titlePrefix.toString(), 1 + titleLevel + levelOffset), title)));
|
||||
}
|
||||
titleMatcher.appendTail(leveledText);
|
||||
leveledText.append(newLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to import Markup", e);
|
||||
}
|
||||
|
||||
if (!StringUtils.isBlank(leveledText)) {
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(convert(leveledText.toString(), markupLanguage));
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
protected void importMarkupStyle2(Pattern titlePattern, String titleFormat, boolean startFrom0, Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
Validate.isTrue(levelOffset <= MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) > max levelOffset (%d)", levelOffset, MAX_TITLE_LEVEL));
|
||||
Validate.isTrue(levelOffset >= -MAX_TITLE_LEVEL, String.format("Specified levelOffset (%d) < min levelOffset (%d)", levelOffset, -MAX_TITLE_LEVEL));
|
||||
|
||||
StringBuffer leveledText = new StringBuffer();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(markupText)) {
|
||||
String readLine;
|
||||
while ((readLine = bufferedReader.readLine()) != null) {
|
||||
Matcher titleMatcher = titlePattern.matcher(readLine);
|
||||
|
||||
while (titleMatcher.find()) {
|
||||
int titleLevel = Integer.valueOf(titleMatcher.group(1)) - (startFrom0 ? 0 : 1);
|
||||
String title = titleMatcher.group(2);
|
||||
|
||||
if (titleLevel + levelOffset > MAX_TITLE_LEVEL)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) > max title level (%d)", levelOffset, title, titleLevel, MAX_TITLE_LEVEL));
|
||||
if (titleLevel + levelOffset < 0)
|
||||
throw new IllegalArgumentException(String.format("Specified levelOffset (%d) set title '%s' level (%d) < 0", levelOffset, title, titleLevel));
|
||||
else
|
||||
titleMatcher.appendReplacement(leveledText, Matcher.quoteReplacement(String.format(titleFormat, (startFrom0 ? 0 : 1) + titleLevel + levelOffset, title)));
|
||||
}
|
||||
titleMatcher.appendTail(leveledText);
|
||||
leveledText.append(newLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to import Markup", e);
|
||||
}
|
||||
|
||||
if (!StringUtils.isBlank(leveledText)) {
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(convert(leveledText.toString(), markupLanguage));
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder table(List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
return tableWithColumnSpecs(null, cells);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return documentBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path addFileExtension(Path file) {
|
||||
return file.resolveSibling(addFileExtension(file.getFileName().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 2 newLines are needed at the end of file for file to be included without protection.
|
||||
*/
|
||||
@Override
|
||||
public void writeToFileWithoutExtension(Path file, Charset charset, OpenOption... options) {
|
||||
// Support relative file names both of "filename" and "./filename"
|
||||
if (file.getParent() != null) {
|
||||
try {
|
||||
Files.createDirectories(file.getParent());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed create directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(file, charset, options)) {
|
||||
writer.write(toString());
|
||||
writer.write(newLine);
|
||||
writer.write(newLine);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to write file", e);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Markup document written to: {}", file);
|
||||
}
|
||||
}
|
||||
|
||||
public String replaceNewLines(String content, String replacement) {
|
||||
return content.replaceAll(NEW_LINES, Matcher.quoteReplacement(replacement));
|
||||
}
|
||||
|
||||
public String replaceNewLines(String content) {
|
||||
return replaceNewLines(content, newLine);
|
||||
}
|
||||
|
||||
public String replaceNewLinesWithWhiteSpace(String content) {
|
||||
return replaceNewLines(content, WHITESPACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(Path file, Charset charset, OpenOption... options) {
|
||||
writeToFileWithoutExtension(file.resolveSibling(addFileExtension(file.getFileName().toString())), charset, options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface Markup {
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.asciidoc;
|
||||
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum AsciiDoc implements Markup {
|
||||
ATTRIBUTE(":"),
|
||||
TABLE("|==="),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TITLE("="),
|
||||
DOCUMENT_TITLE("= "),
|
||||
LITERAL("`"),
|
||||
BOLD("**"),
|
||||
ITALIC("__"),
|
||||
LIST_ENTRY("* "),
|
||||
CROSS_REFERENCE_START("<<"),
|
||||
CROSS_REFERENCE_END(">>"),
|
||||
ANCHOR_START("[["),
|
||||
ANCHOR_END("]]"),
|
||||
SPACE_ESCAPE("_"),
|
||||
LINE_BREAK(" +");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
AsciiDoc(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.asciidoc;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile(String.format("^(%s{1,%d})\\s+(.*)$", AsciiDoc.TITLE, MAX_TITLE_LEVEL + 1));
|
||||
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, "====");
|
||||
put(MarkupBlockStyle.LISTING, "----");
|
||||
put(MarkupBlockStyle.LITERAL, "....");
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "++++");
|
||||
put(MarkupBlockStyle.SIDEBAR, "****");
|
||||
}};
|
||||
|
||||
public AsciiDocBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AsciiDocBuilder(int asciidocPegdownTimeoutMillis) {
|
||||
super(System.getProperty("line.separator"), asciidocPegdownTimeoutMillis);
|
||||
}
|
||||
|
||||
public AsciiDocBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
public AsciiDocBuilder(String newLine, int asciidocPegdownTimeoutMillis) {
|
||||
super(newLine, asciidocPegdownTimeoutMillis);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.ASCIIDOC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
AsciiDocBuilder builder = new AsciiDocBuilder(newLine, asciidocPegdownTimeoutMillis);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
sectionTitleLevel(AsciiDoc.TITLE, level, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
sectionTitleWithAnchorLevel(AsciiDoc.TITLE, level, title, anchor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
if (hardbreaks)
|
||||
documentBuilder.append("[%hardbreaks]").append(newLine);
|
||||
text = text.trim();
|
||||
documentBuilder.append(replaceNewLines(text)).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("<<<").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
if (admonition != null)
|
||||
documentBuilder.append("[").append(admonition).append("]").append(newLine);
|
||||
if (title != null)
|
||||
documentBuilder.append(".").append(title).append(newLine);
|
||||
|
||||
delimitedBlockText(new Markup() {
|
||||
public String toString() {
|
||||
return BLOCK_STYLE.get(style);
|
||||
}
|
||||
}, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(AsciiDoc.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(AsciiDoc.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(AsciiDoc.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(AsciiDoc.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(AsciiDoc.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, String language) {
|
||||
if (language != null)
|
||||
documentBuilder.append(String.format("[source,%s]", language)).append(newLine);
|
||||
block(text, MarkupBlockStyle.LISTING);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
String normalizedAnchor = "_" + normalizeAnchor(AsciiDoc.SPACE_ESCAPE, anchor);
|
||||
|
||||
if (normalizedAnchor.endsWith("-"))
|
||||
normalizedAnchor += "_";
|
||||
|
||||
return normalizedAnchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial workaround for https://github.com/asciidoctor/asciidoctor/issues/844
|
||||
*/
|
||||
private String normalizeDocument(String document) {
|
||||
if (document == null)
|
||||
return null;
|
||||
|
||||
return new File(document).toPath().normalize().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append(AsciiDoc.ANCHOR_START).append(normalizeAnchor(anchor));
|
||||
if (text != null)
|
||||
documentBuilder.append(",").append(text);
|
||||
documentBuilder.append(AsciiDoc.ANCHOR_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_START);
|
||||
if (document != null)
|
||||
documentBuilder.append(document).append("#");
|
||||
documentBuilder.append(anchor);
|
||||
if (text != null) {
|
||||
documentBuilder.append(",").append(text);
|
||||
if (text.endsWith(">"))
|
||||
documentBuilder.append(" ");
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
return crossReferenceRaw(normalizeDocument(document), normalizeAnchor(anchor), text);
|
||||
}
|
||||
|
||||
private String formatTableCell(String cell) {
|
||||
cell = replaceNewLines(cell.trim());
|
||||
return cell.replace(AsciiDoc.TABLE_COLUMN_DELIMITER.toString(), "\\" + AsciiDoc.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
Boolean hasHeader = false;
|
||||
List<String> options = new ArrayList<>();
|
||||
List<String> cols = new ArrayList<>();
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
for (MarkupTableColumn col : columnSpecs) {
|
||||
if (!hasHeader && isNotBlank(col.header)) {
|
||||
options.add("header");
|
||||
hasHeader = true;
|
||||
}
|
||||
String languageStyle = col.markupSpecifiers.get(MarkupLanguage.ASCIIDOC);
|
||||
if (languageStyle != null && isNoneBlank(languageStyle)) {
|
||||
cols.add(languageStyle);
|
||||
} else {
|
||||
cols.add(String.valueOf(col.widthRatio) + (col.headerColumn ? "h" : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newLine();
|
||||
documentBuilder.append("[options=\"").append(join(options, ",")).append("\", cols=\"").append(join(cols, ",")).append("\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
if (hasHeader) {
|
||||
Collection<String> headerList = columnSpecs.stream().map(header -> formatTableCell(defaultString(header.header))).collect(Collectors.toList());
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(join(headerList, AsciiDoc.TABLE_COLUMN_DELIMITER.toString())).append(newLine);
|
||||
|
||||
}
|
||||
for (List<String> row : cells) {
|
||||
Collection<String> cellList = row.stream().map(cell -> formatTableCell(defaultString(cell))).collect(Collectors.toList());
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(join(cellList, AsciiDoc.TABLE_COLUMN_DELIMITER.toString())).append(newLine);
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
newLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(AsciiDoc.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle1(TITLE_PATTERN, AsciiDoc.TITLE, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.ASCIIDOC.getFileNameExtensions().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.swagger2markup.markup.builder.internal.asciidoc;
|
||||
|
||||
import org.pegdown.Extensions;
|
||||
import org.pegdown.PegDownProcessor;
|
||||
import org.pegdown.ast.RootNode;
|
||||
|
||||
import nl.jworks.markdown_to_asciidoc.Converter;
|
||||
import nl.jworks.markdown_to_asciidoc.ToAsciiDocSerializer;
|
||||
|
||||
public class AsciiDocConverterExtension extends Converter {
|
||||
|
||||
/**
|
||||
* Converts markdown to asciidoc.
|
||||
*
|
||||
* @param markdown the markdown source to convert
|
||||
* @param timeoutMills parsing timeout
|
||||
* @return asciidoc format
|
||||
*/
|
||||
public static String convertMarkdownToAsciiDoc(String markdown, long timeoutMills) {
|
||||
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, timeoutMills);
|
||||
// insert blank line before fenced code block if necessary
|
||||
if (markdown.contains("```")) {
|
||||
markdown = markdown.replaceAll("(?m)(?<!\n\n)(\\s*)```(\\w*\n)((?:\\1[^\n]*\n)+)\\1```", "\n$1```$2$3$1```");
|
||||
}
|
||||
char[] markDown = markdown.toCharArray();
|
||||
RootNode rootNode = processor.parseMarkdown(markDown);
|
||||
return new ToAsciiDocSerializer(rootNode, markdown).toAsciiDoc();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.confluenceMarkup;
|
||||
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum ConfluenceMarkup implements Markup {
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
LITERAL("{noformat}"),
|
||||
BOLD("*"),
|
||||
ITALIC("_"),
|
||||
LIST_ENTRY("* "),
|
||||
ANCHOR_START("{anchor:"),
|
||||
ANCHOR_END("}"),
|
||||
SPACE_ESCAPE("_"),
|
||||
LINE_BREAK("\\\\ ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
ConfluenceMarkup(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.confluenceMarkup;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public final class ConfluenceMarkupBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile("^h([0-9])\\.\\s+(.*)$");
|
||||
private static final String TITLE_FORMAT = "h%d. %s";
|
||||
private static final Pattern ESCAPE_CELL_PIPE_PATTERN = Pattern.compile("((\\[.*?(?<!\\\\)\\])|(.))");
|
||||
|
||||
/**
|
||||
* Associate macro name to block style.<br>
|
||||
* ending ':' means the macro supports title attribute.<br>
|
||||
* '>ADMONITION_BLOCK' means value should refer to {@link #ADMONITION_BLOCK_STYLE}.
|
||||
*/
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, ">ADMONITION_BLOCK");
|
||||
put(MarkupBlockStyle.LISTING, "code:");
|
||||
put(MarkupBlockStyle.LITERAL, "noformat");
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "html");
|
||||
put(MarkupBlockStyle.SIDEBAR, ">ADMONITION_BLOCK");
|
||||
}};
|
||||
|
||||
private static final Map<MarkupAdmonition, String> ADMONITION_BLOCK_STYLE = new HashMap<MarkupAdmonition, String>() {{
|
||||
put(null, "panel:");
|
||||
put(MarkupAdmonition.CAUTION, "note:");
|
||||
put(MarkupAdmonition.IMPORTANT, "alert:");
|
||||
put(MarkupAdmonition.NOTE, "info:");
|
||||
put(MarkupAdmonition.TIP, "tip:");
|
||||
put(MarkupAdmonition.WARNING, "warning:");
|
||||
}};
|
||||
|
||||
public ConfluenceMarkupBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ConfluenceMarkupBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.CONFLUENCE_MARKUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
ConfluenceMarkupBuilder builder = new ConfluenceMarkupBuilder(newLine);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, 1, title));
|
||||
documentBuilder.append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, level + 1, replaceNewLinesWithWhiteSpace(title)));
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
Validate.notBlank(title, "title must not be blank");
|
||||
Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
documentBuilder.append(String.format(TITLE_FORMAT, level + 1, replaceNewLinesWithWhiteSpace(title)));
|
||||
if (isBlank(anchor))
|
||||
anchor = title;
|
||||
documentBuilder.append(" ");
|
||||
anchor(replaceNewLinesWithWhiteSpace(anchor));
|
||||
|
||||
documentBuilder.append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
|
||||
text = text.trim();
|
||||
if (hardbreaks)
|
||||
text = replaceNewLines(text, ConfluenceMarkup.LINE_BREAK + newLine);
|
||||
else
|
||||
text = replaceNewLines(text);
|
||||
documentBuilder.append(text).append(newLine).append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("<div style='page-break-before:always;'></div>").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
|
||||
String block = BLOCK_STYLE.get(style);
|
||||
|
||||
boolean admonitionBlock = block.equals(">ADMONITION_BLOCK");
|
||||
if (admonitionBlock) {
|
||||
block = ADMONITION_BLOCK_STYLE.get(admonition);
|
||||
}
|
||||
|
||||
boolean supportTitle = false;
|
||||
if (block.endsWith(":")) {
|
||||
supportTitle = true;
|
||||
block = StringUtils.stripEnd(block, ":");
|
||||
}
|
||||
|
||||
String titleString = null;
|
||||
if (admonition != null && !admonitionBlock) {
|
||||
titleString = StringUtils.capitalize(admonition.name().toLowerCase());
|
||||
}
|
||||
if (title != null) {
|
||||
titleString = (titleString == null ? "" : titleString + " | ") + title;
|
||||
}
|
||||
|
||||
final String finalBlock = block;
|
||||
Markup blockMarkup = new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{%s}", finalBlock);
|
||||
}
|
||||
};
|
||||
|
||||
if (!supportTitle) {
|
||||
if (titleString != null)
|
||||
documentBuilder.append(titleString).append(" : ").append(newLine);
|
||||
delimitedBlockText(blockMarkup, text);
|
||||
} else {
|
||||
final String finalTitleString = titleString;
|
||||
delimitedBlockText(new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (finalTitleString == null)
|
||||
return String.format("{%s}", finalBlock);
|
||||
else
|
||||
return String.format("{%s:title=%s}", finalBlock, finalTitleString);
|
||||
}
|
||||
}, text, blockMarkup);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, final String language) {
|
||||
Markup blockMarkup = new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{%s}", "code");
|
||||
}
|
||||
};
|
||||
|
||||
if (language != null) {
|
||||
delimitedBlockText(new Markup() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{code:language=%s}", language);
|
||||
}
|
||||
}, text, blockMarkup);
|
||||
} else {
|
||||
delimitedBlockText(blockMarkup, text);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(ConfluenceMarkup.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(ConfluenceMarkup.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(ConfluenceMarkup.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(ConfluenceMarkup.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(ConfluenceMarkup.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
documentBuilder.append(newLine);
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
documentBuilder.append("||");
|
||||
for (MarkupTableColumn column : columnSpecs) {
|
||||
documentBuilder.append(formatCellContent(defaultString(column.header))).append("||");
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
for (List<String> row : cells) {
|
||||
documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
ListIterator<String> cellIterator = row.listIterator();
|
||||
while (cellIterator.hasNext()) {
|
||||
int cellIndex = cellIterator.nextIndex();
|
||||
if (columnSpecs != null && columnSpecs.size() > cellIndex && columnSpecs.get(cellIndex).headerColumn)
|
||||
documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
|
||||
documentBuilder.append(formatCellContent(cellIterator.next())).append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String formatCellContent(String cell) {
|
||||
cell = replaceNewLines(cell.trim(), ConfluenceMarkup.LINE_BREAK.toString());
|
||||
if (isBlank(cell)) {
|
||||
return " ";
|
||||
}
|
||||
return escapeCellPipes(cell);
|
||||
}
|
||||
|
||||
private String escapeCellPipes(String cell) {
|
||||
Matcher m = ESCAPE_CELL_PIPE_PATTERN.matcher(cell);
|
||||
|
||||
StringBuffer res = new StringBuffer();
|
||||
while (m.find()) {
|
||||
String repl = m.group(1);
|
||||
if (repl.equals(ConfluenceMarkup.TABLE_COLUMN_DELIMITER.toString()))
|
||||
repl = "\\" + ConfluenceMarkup.TABLE_COLUMN_DELIMITER.toString();
|
||||
m.appendReplacement(res, Matcher.quoteReplacement(repl));
|
||||
}
|
||||
m.appendTail(res);
|
||||
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
return normalizeAnchor(ConfluenceMarkup.SPACE_ESCAPE, anchor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append(ConfluenceMarkup.ANCHOR_START).append(normalizeAnchor(anchor)).append(ConfluenceMarkup.ANCHOR_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
crossReferenceRaw(document, normalizeAnchor(anchor), text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
documentBuilder.append("[");
|
||||
if (isNotBlank(text)) {
|
||||
documentBuilder.append(text).append("|");
|
||||
}
|
||||
if (isNotBlank(document)) {
|
||||
documentBuilder.append(document);
|
||||
}
|
||||
documentBuilder.append("#").append(anchor);
|
||||
documentBuilder.append("]");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(ConfluenceMarkup.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle2(TITLE_PATTERN, TITLE_FORMAT, false, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.CONFLUENCE_MARKUP.getFileNameExtensions().get(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.markdown;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
TITLE("#"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
LITERAL("`"),
|
||||
BOLD("**"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* "),
|
||||
SPACE_ESCAPE("-"),
|
||||
LINE_BREAK(" ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private Markdown(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.internal.markdown;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.internal.Markup;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.join;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkdownBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
private static final Pattern TITLE_PATTERN = Pattern.compile(String.format("^(%s{1,%d})\\s+(.*)$", Markdown.TITLE, MAX_TITLE_LEVEL + 1));
|
||||
|
||||
private static final Map<MarkupBlockStyle, String> BLOCK_STYLE = new HashMap<MarkupBlockStyle, String>() {{
|
||||
put(MarkupBlockStyle.EXAMPLE, "");
|
||||
put(MarkupBlockStyle.LISTING, Markdown.LISTING.toString());
|
||||
put(MarkupBlockStyle.LITERAL, Markdown.LISTING.toString());
|
||||
put(MarkupBlockStyle.PASSTHROUGH, "");
|
||||
put(MarkupBlockStyle.SIDEBAR, "");
|
||||
}};
|
||||
|
||||
public MarkdownBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MarkdownBuilder(String newLine) {
|
||||
super(newLine);
|
||||
}
|
||||
|
||||
protected MarkupLanguage getMarkupLanguage() {
|
||||
return MarkupLanguage.MARKDOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder copy(boolean copyBuffer) {
|
||||
MarkdownBuilder builder = new MarkdownBuilder(newLine);
|
||||
|
||||
if (copyBuffer)
|
||||
builder.documentBuilder = new StringBuilder(this.documentBuilder);
|
||||
|
||||
return builder.withAnchorPrefix(anchorPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder documentTitle(String title) {
|
||||
documentTitle(Markdown.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleLevel(int level, String title) {
|
||||
sectionTitleLevel(Markdown.TITLE, level, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
|
||||
sectionTitleWithAnchorLevel(Markdown.TITLE, level, title, anchor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder paragraph(String text, boolean hardbreaks) {
|
||||
Validate.notBlank(text, "text must not be blank");
|
||||
|
||||
text = text.trim();
|
||||
if (hardbreaks)
|
||||
text = replaceNewLines(text, Markdown.LINE_BREAK + newLine);
|
||||
else
|
||||
text = replaceNewLines(text);
|
||||
documentBuilder.append(text).append(newLine).append(newLine);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder pageBreak() {
|
||||
documentBuilder.append(newLine).append("***").append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder block(String text, final MarkupBlockStyle style, String title, MarkupAdmonition admonition) {
|
||||
boolean multiline = text.contains(newLine);
|
||||
|
||||
if (admonition != null)
|
||||
documentBuilder.append(StringUtils.capitalize(admonition.name().toLowerCase()));
|
||||
if (title != null) {
|
||||
if (admonition != null)
|
||||
documentBuilder.append(" | ");
|
||||
documentBuilder.append(title);
|
||||
}
|
||||
if (admonition != null || title != null)
|
||||
documentBuilder.append(" : ").append(newLine);
|
||||
|
||||
Markup m = new Markup() {
|
||||
public String toString() {
|
||||
return BLOCK_STYLE.get(style);
|
||||
}
|
||||
};
|
||||
|
||||
if (style == MarkupBlockStyle.LISTING && multiline) {
|
||||
delimitedBlockText(m, text, m, true);
|
||||
} else {
|
||||
delimitedBlockText(m, text, m);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder listingBlock(String text, String language) {
|
||||
text = newLine + text;
|
||||
if (language != null) {
|
||||
text = language + text;
|
||||
}
|
||||
block(text, MarkupBlockStyle.LISTING);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder literalText(String text) {
|
||||
boldText(Markdown.LITERAL, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder boldText(String text) {
|
||||
boldText(Markdown.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder italicText(String text) {
|
||||
italicText(Markdown.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedList(List<String> list) {
|
||||
unorderedList(Markdown.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder unorderedListItem(String item) {
|
||||
unorderedListItem(Markdown.LIST_ENTRY, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String normalizeAnchor(String anchor) {
|
||||
return normalizeAnchor(Markdown.SPACE_ESCAPE, anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder anchor(String anchor, String text) {
|
||||
documentBuilder.append("<a name=\"").append(normalizeAnchor(anchor)).append("\"></a>");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReferenceRaw(String document, String anchor, String text) {
|
||||
if (text == null)
|
||||
text = anchor.trim();
|
||||
documentBuilder.append("[").append(text).append("]").append("(");
|
||||
if (document != null)
|
||||
documentBuilder.append(document);
|
||||
documentBuilder.append("#").append(anchor).append(")");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String document, String anchor, String text) {
|
||||
return crossReferenceRaw(document, normalizeAnchor(anchor), text);
|
||||
}
|
||||
|
||||
private String formatTableCell(String cell) {
|
||||
cell = replaceNewLines(cell.trim(), "<br>");
|
||||
return cell.replace(Markdown.TABLE_COLUMN_DELIMITER.toString(), "\\" + Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
|
||||
Validate.notEmpty(cells, "cells must not be null");
|
||||
newLine();
|
||||
if (columnSpecs != null && !columnSpecs.isEmpty()) {
|
||||
Collection<String> headerList = columnSpecs.stream().map(header -> formatTableCell(defaultString(header.header))).collect(Collectors.toList());
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER).append(join(headerList, Markdown.TABLE_COLUMN_DELIMITER.toString())).append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);
|
||||
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
|
||||
columnSpecs.forEach(col -> {
|
||||
documentBuilder.append(StringUtils.repeat(Markdown.TABLE_ROW.toString(), 3));
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
|
||||
});
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
for (List<String> row : cells) {
|
||||
Collection<String> cellList = row.stream().map(cell -> formatTableCell(defaultString(cell))).collect(Collectors.toList());
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER).append(join(cellList, Markdown.TABLE_COLUMN_DELIMITER.toString())).append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);
|
||||
}
|
||||
newLine();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder newLine(boolean forceLineBreak) {
|
||||
newLine(Markdown.LINE_BREAK, forceLineBreak);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder importMarkup(Reader markupText, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
importMarkupStyle1(TITLE_PATTERN, Markdown.TITLE, markupText, markupLanguage, levelOffset);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addFileExtension(String fileName) {
|
||||
return fileName + MarkupLanguage.MARKDOWN.getFileNameExtensions().get(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.assertions.DiffUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
private final String newLine = System.getProperty("line.separator");
|
||||
|
||||
private List<MarkupTableColumn> tableColumns;
|
||||
private List<List<String>> tableCells;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tableColumns = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
tableCells = new ArrayList<>();
|
||||
tableCells.add(Arrays.asList("Row 1 | Column 1", "Row 1 | Column 2", "Row 1 | Column 3"));
|
||||
tableCells.add(Arrays.asList("Row 2 | Column 1", "Row 2 | Column 2", "Row 2 | Column 3"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAsciiDoc() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.adoc", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.adoc", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/asciidoc/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/asciidoc/test.adoc").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testAsciiDoc.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsciiDocWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("[[_mdb_test-anchor,text]]<<_mdb_test-anchor,text>>", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdownCodeBlock() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
builder = builder.listingBlock("$o = new Thing();", "php");
|
||||
Path outputFile = Paths.get("build/test/markdown/test2");
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/test2.md").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testMarkdown2.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdown() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
//.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.md", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.md", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/markdown/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/test.md").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testMarkdown.html");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkdownWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("<a name=\"mdb-test-anchor\"></a>[text](#mdb-test-anchor)", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfluenceMarkup() throws IOException, URISyntaxException {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
|
||||
builder = builder.documentTitle("Test title")
|
||||
.sectionTitleLevel(1, "Section Level 1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a", "level-1a")
|
||||
.sectionTitleWithAnchorLevel(1, "Section with anchor Level 1a")
|
||||
.sectionTitleLevel(2, "Section Level 2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a", "level-2a")
|
||||
.sectionTitleWithAnchorLevel(2, "Section with anchor Level 2a")
|
||||
.sectionTitleLevel(3, "Section Level 3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a", "level-3a")
|
||||
.sectionTitleWithAnchorLevel(3, "Section with anchor Level 3a")
|
||||
.sectionTitleLevel(4, "Section Level 4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a", "level-4a")
|
||||
.sectionTitleWithAnchorLevel(4, "Section with anchor Level 4a")
|
||||
.sectionTitleLevel(5, "Section Level 5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a", "level-5a")
|
||||
.sectionTitleWithAnchorLevel(5, "Section with anchor Level 5a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.paragraph("\rLine1\nLine2\r\n", false)
|
||||
.paragraph("\rLine1\nLine2\r\n", true)
|
||||
.listingBlock("Source code listing")
|
||||
.listingBlock("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP)", "java")
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, "Example", null)
|
||||
.block("Example", MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.IMPORTANT)
|
||||
.block("Listing", MarkupBlockStyle.LISTING, null, MarkupAdmonition.CAUTION)
|
||||
.block("Literal", MarkupBlockStyle.LITERAL, null, MarkupAdmonition.NOTE)
|
||||
.block("Sidebar", MarkupBlockStyle.SIDEBAR, null, MarkupAdmonition.TIP)
|
||||
.block("Passthrough", MarkupBlockStyle.PASSTHROUGH, null, MarkupAdmonition.WARNING)
|
||||
.pageBreak()
|
||||
.table(tableCells)
|
||||
.tableWithColumnSpecs(tableColumns, tableCells)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.textLine("text line", true)
|
||||
.literalTextLine("Literal text line", true)
|
||||
.boldTextLine("Bold text line", true)
|
||||
.italicTextLine("Italic text line", true)
|
||||
.boldText("bold").italicText("italic").text("regular").newLine(true)
|
||||
.unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
|
||||
.anchor("anchor", "text").newLine()
|
||||
.anchor(" Simple anchor").newLine()
|
||||
.anchor(" \u0240 µ&|ù This .:/-_# ").newLine()
|
||||
.crossReferenceRaw("./document.txt", "anchor", "text").newLine(true)
|
||||
.crossReferenceRaw(" \u0240 µ&|ù This .:/-_ ").newLine(true)
|
||||
.crossReference("./document.txt", "anchor", "text").newLine(true)
|
||||
.crossReference(" \u0240 µ&|ù This .:/-_ ").newLine(true);
|
||||
|
||||
Path outputFile = Paths.get("build/test/confluenceMarkup/test");
|
||||
|
||||
builder.writeToFileWithoutExtension(builder.addFileExtension(outputFile), StandardCharsets.UTF_8);
|
||||
builder.writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
Path expectedFile = Paths.get(MarkupDocBuilderTest.class.getResource("/expected/confluenceMarkup/test.txt").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, builder.addFileExtension(outputFile), "testConfluenceMarkup.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfluenceMarkupWithAnchorPrefix() {
|
||||
MarkupDocBuilder builderWithConfig = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP).withAnchorPrefix(" mdb test- ");
|
||||
String prefixMarkup = builderWithConfig.anchor("anchor", "text")
|
||||
.crossReference("anchor", "text")
|
||||
.toString();
|
||||
|
||||
assertEquals("{anchor:mdb_test-anchor}[text|#mdb_test-anchor]", prefixMarkup);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceNewLinesWithSystemNewLine() {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.paragraph("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla" + newLine + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.text("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.textLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.italicText("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("*Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla*", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.italicTextLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("*Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla*" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.boldText("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("**Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla**", builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
builder.boldTextLine("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("**Long text " + newLine + " bla bla " + newLine + " bla " + newLine + " bla**" + newLine, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceTitleNewLinesWithWhiteSpace() {
|
||||
String whitespace = " ";
|
||||
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.documentTitle("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("= Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.sectionTitleLevel1("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals(newLine + "== Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine, builder.toString());
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
builder.sectionTitleLevel2("Long title \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals(newLine + "=== Long title " + whitespace + " bla bla " + whitespace + " bla " + whitespace + " bla" + newLine, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseProvidedLineSeparator() {
|
||||
String lineSeparator = LineSeparator.UNIX.toString();
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.paragraph("Long text \n bla bla \r bla \r\n bla");
|
||||
Assert.assertEquals("Long text " + lineSeparator + " bla bla " + lineSeparator + " bla " + lineSeparator + " bla" + lineSeparator + lineSeparator, builder.toString());
|
||||
}
|
||||
|
||||
private void assertImportMarkup(String expected, String text, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(markupLanguage, LineSeparator.UNIX);
|
||||
|
||||
builder.importMarkup(new StringReader(text), markupLanguage, levelOffset);
|
||||
|
||||
Assert.assertEquals(expected, builder.toString());
|
||||
}
|
||||
|
||||
private void assertImportMarkupException(String expected, String text, MarkupLanguage markupLanguage, int levelOffset) {
|
||||
try {
|
||||
assertImportMarkup(expected, text, markupLanguage, levelOffset);
|
||||
fail("IllegalArgumentException expected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assert.assertEquals(expected, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupAsciiDoc() {
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, 4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.ASCIIDOC, 6);
|
||||
assertImportMarkup("", "", MarkupLanguage.ASCIIDOC, -4);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.ASCIIDOC, -6);
|
||||
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n\n", "= title\r\nline 1\r\nline 2", MarkupLanguage.ASCIIDOC, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.ASCIIDOC, 4);
|
||||
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n= title 2\nline 3\n\n", "= title\nline 1\nline 2\n= title 2\nline 3", MarkupLanguage.ASCIIDOC, 0);
|
||||
assertImportMarkup("\n===== title\nline 1\nline 2\n\n", "= title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, 4);
|
||||
assertImportMarkup("\n= title\nline 1\nline 2\n\n", "===== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "= title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "== title\nline 1\nline 2", MarkupLanguage.ASCIIDOC, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupMarkdown() {
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, 4);
|
||||
assertImportMarkup("", "", MarkupLanguage.MARKDOWN, -4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.MARKDOWN, 6);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.MARKDOWN, -6);
|
||||
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n\n", "# title\r\nline 1\r\nline 2", MarkupLanguage.MARKDOWN, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.MARKDOWN, 4);
|
||||
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n# title 2\nline 3\n\n", "# title\nline 1\nline 2\n# title 2\nline 3", MarkupLanguage.MARKDOWN, 0);
|
||||
assertImportMarkup("\n##### title\nline 1\nline 2\n\n", "# title\nline 1\nline 2", MarkupLanguage.MARKDOWN, 4);
|
||||
assertImportMarkup("\n# title\nline 1\nline 2\n\n", "##### title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "## title\nline 1\nline 2", MarkupLanguage.MARKDOWN, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "# title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "## title\nline 1\nline 2", MarkupLanguage.MARKDOWN, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportMarkupConfluenceMarkup() {
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
assertImportMarkup("", "", MarkupLanguage.CONFLUENCE_MARKUP, -4);
|
||||
assertImportMarkupException("Specified levelOffset (6) > max levelOffset (5)", "", MarkupLanguage.CONFLUENCE_MARKUP, 6);
|
||||
assertImportMarkupException("Specified levelOffset (-6) < min levelOffset (-5)", "", MarkupLanguage.CONFLUENCE_MARKUP, -6);
|
||||
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\n\n", "h1. title\r\nline 1\r\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("\nline 1\nline 2\n\n", "line 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\nh1. title 2\nline 3\n\n", "h1. title\nline 1\nline 2\nh1. title 2\nline 3", MarkupLanguage.CONFLUENCE_MARKUP, 0);
|
||||
assertImportMarkup("\nh5. title\nline 1\nline 2\n\n", "h1. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 4);
|
||||
assertImportMarkup("\nh1. title\nline 1\nline 2\n\n", "h5. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -4);
|
||||
|
||||
assertImportMarkupException("Specified levelOffset (5) set title 'title' level (1) > max title level (5)", "h2. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, 5);
|
||||
assertImportMarkupException("Specified levelOffset (-1) set title 'title' level (0) < 0", "h1. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -1);
|
||||
assertImportMarkupException("Specified levelOffset (-3) set title 'title' level (1) < 0", "h2. title\nline 1\nline 2", MarkupLanguage.CONFLUENCE_MARKUP, -3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importMarkupConversion() {
|
||||
// ASCIIDOC -> ASCIIDOC
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// ASCIIDOC -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
// Assert.assertEquals("\n# Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// ASCIIDOC -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("= Title"), MarkupLanguage.ASCIIDOC);
|
||||
// Assert.assertEquals("\nh1. Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> ASCIIDOC
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
Assert.assertEquals("\n= Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
Assert.assertEquals("\n# Title\n\n", builder.toString());
|
||||
|
||||
// MARKDOWN -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("# Title"), MarkupLanguage.MARKDOWN);
|
||||
// Assert.assertEquals("\nh1. Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\n# Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> ASCIIDOC
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
// Assert.assertEquals("\n= Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> MARKDOWN
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
// Assert.assertEquals("\n# Title\n\n", builder.toString()); // Unsupported
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
|
||||
// CONFLUENCE_MARKUP -> CONFLUENCE_MARKUP
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP, LineSeparator.UNIX);
|
||||
builder.importMarkup(new StringReader("h1. Title"), MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
Assert.assertEquals("\nh1. Title\n\n", builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatAsciiDoc() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/asciidoc/tableFormat.adoc");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/asciidoc/tableFormat.adoc").toURI()), outputFile, "tableFormatAsciiDoc.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatMarkdown() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/markdown/tableFormat.md");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/markdown/tableFormat.md").toURI()), outputFile, "tableFormatMarkdown.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableFormatConfluenceMarkup() throws URISyntaxException, IOException {
|
||||
Path outputFile = Paths.get("build/test/confluenceMarkup/tableFormat.txt");
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP);
|
||||
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn().withHeader("Header1\nfirst one"),
|
||||
new MarkupTableColumn().withWidthRatio(2),
|
||||
new MarkupTableColumn().withHeader("Header3").withWidthRatio(1).withHeaderColumn(true));
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
cells.add(Arrays.asList("Row 1 [Title|Page#Anchor] | Column 1", "Row 1 [Title1|Page#Anchor][Title2|Page#Anchor] [Title3|Page#Anchor] | Column [Title|Page#Anchor] 2", "Row 1 [Ti\\|t\\]\\[le|Page#Anchor] | Column 3"));
|
||||
cells.add(Arrays.asList("[Title|Page#Anchor]Row 1 | Column 1[Title|Page#Anchor]", "|[Title1|Page#Anchor]Row1 Column2|[Title1|Page#Anchor]", "|Row 1 Column 3|"));
|
||||
cells.add(Arrays.asList("\nRow 2 \\| Column \r\n1\r", "Row 2 || Column 2", "Row 2 | | Column 3"));
|
||||
|
||||
builder = builder.tableWithColumnSpecs(cols, cells);
|
||||
builder.writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
|
||||
DiffUtils.assertThatFileIsEqual(Paths.get(MarkupDocBuilderTest.class.getResource("/expected/confluenceMarkup/tableFormat.txt").toURI()), outputFile, "tableFormatConfluenceMarkup.html");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.swagger2markup.markup.builder.assertions;
|
||||
|
||||
import io.github.robwin.diff.DiffAssertions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class DiffUtils {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);
|
||||
|
||||
public static void assertThatAllFilesAreEqual(Path expectedDirectory, Path actualDirectory, String reportName) {
|
||||
Path reportPath = Paths.get("build/diff-report/", reportName);
|
||||
try {
|
||||
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(expectedDirectory)) {
|
||||
for (Path expectedFile : directoryStream) {
|
||||
Path actualFile = actualDirectory.resolve(expectedFile.getFileName());
|
||||
LOGGER.info("Diffing file {} with {}", actualFile, expectedFile);
|
||||
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to assert that all files are equal", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertThatFileIsEqual(Path expectedFile, Path actualFile, String reportName) {
|
||||
Path reportPath = Paths.get("build/diff-report/", reportName);
|
||||
LOGGER.info("Diffing file {} with {}", actualFile, expectedFile);
|
||||
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package io.github.swagger2markup.markup.builder.internal;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilders;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.internal.asciidoc.AsciiDoc;
|
||||
import io.github.swagger2markup.markup.builder.internal.markdown.Markdown;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class AbstractMarkupDocBuilderTest {
|
||||
|
||||
AbstractMarkupDocBuilder builder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
builder = mock(AbstractMarkupDocBuilder.class, Mockito.CALLS_REAL_METHODS);
|
||||
builder.newLine = "\n";
|
||||
builder.documentBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
private String normalize(Markup markup, String anchor) {
|
||||
return builder.normalizeAnchor(markup, anchor);
|
||||
}
|
||||
|
||||
private void assertNormalization(Markup markup, String result, String anchor) {
|
||||
assertEquals(result, normalize(markup, anchor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeAnchorAsciiDoc() throws Exception {
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "", "");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "anchor");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "aNcHoR");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "_ anchor _");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "- anchor -");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "a_n-c_h_o-r", "_-a _ - n-_-_-c_-_-_h___o---r_-");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "classic-simple_anchor", "classic-simple_anchor");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "an_chor", " an chor ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "anchor", "# anchor &");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, DigestUtils.md5Hex("\u0240"), "\u0240");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, normalize(AsciiDoc.SPACE_ESCAPE, "\u0240"), " \u0240 ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, DigestUtils.md5Hex("µ_u_\u0240this"), " µ&|ù \u0240This .:/-_# ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "this_is_a_really_funky_string", "Tĥïŝ ĩš â really fůňķŷ Šťŕĭńġ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "", " @#&(){}[]!$*%+=/:.;,?\\<>| ");
|
||||
assertNormalization(AsciiDoc.SPACE_ESCAPE, "sub_action_html_query_value", " /sub/action.html/?query=value ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeAnchorMarkdown() throws Exception {
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "", "");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "anchor");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "aNcHoR");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "_ anchor _");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "- anchor -");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "a-n-c_h_o-r", "_-a _ - n-_-_-c_-_-_h___o---r_-");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "classic-simple_anchor", "classic-simple_anchor");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "an-chor", " an chor ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "anchor", "# anchor &");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, DigestUtils.md5Hex("\u0240"), "\u0240");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, normalize(Markdown.SPACE_ESCAPE, "\u0240"), " \u0240 ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, DigestUtils.md5Hex("µ-u-\u0240this"), " µ&|ù \u0240This .:/-_# ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "this-is-a-really-funky-string", "Tĥïŝ ĩš â really fůňķŷ Šťŕĭńġ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "", " @#&(){}[]!$*%+=/:.;,?\\<>| ");
|
||||
assertNormalization(Markdown.SPACE_ESCAPE, "sub-action-html-query-value", " /sub/action.html/?query=value ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX).withAnchorPrefix("anchor-");
|
||||
MarkupDocBuilder copy = builder.copy(false);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
AbstractMarkupDocBuilder internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.UNIX.toString(), internalCopy.newLine);
|
||||
Assert.assertEquals("anchor-", internalCopy.anchorPrefix);
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.WINDOWS);
|
||||
copy = builder.copy(false);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.WINDOWS.toString(), internalCopy.newLine);
|
||||
Assert.assertNull(internalCopy.anchorPrefix);
|
||||
|
||||
builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC, LineSeparator.UNIX);
|
||||
builder.text("This is text");
|
||||
copy = builder.copy(true);
|
||||
|
||||
Assert.assertTrue(copy instanceof AbstractMarkupDocBuilder);
|
||||
internalCopy = (AbstractMarkupDocBuilder) copy;
|
||||
Assert.assertEquals(LineSeparator.UNIX.toString(), internalCopy.newLine);
|
||||
Assert.assertNull(internalCopy.anchorPrefix);
|
||||
Assert.assertEquals("This is text", internalCopy.documentBuilder.toString());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
[options="header", cols="0,2,1h"]
|
||||
|===
|
||||
|Header1
|
||||
first one||Header3
|
||||
|Row 2 \\| Column
|
||||
1|Row 2 \|\| Column 2|Row 2 \| \| Column 3
|
||||
|===
|
||||
|
||||
|
||||
|
||||