Compare commits

...

165 Commits

Author SHA1 Message Date
Robert Winkler
6afe41b7a9 Prepare release 1.1.2 2017-12-04 10:49:06 +01:00
Cas Eliëns
f5aadc2319 Improve code blocks in markdown (#28) 2017-10-10 15:24:28 +02:00
Robert Winkler
0730b94c24 Updated README 2017-10-05 13:11:01 +02:00
Robert Winkler
59c63e8ac0 Released v1.1.1 2017-01-05 14:15:33 +01:00
Robert Winkler
c404740bf1 Updated version from 1.1.0 to 1.1.1-SNAPSHOT 2017-01-02 11:18:24 +01:00
Cas Eliëns
23c72721ad Add page breaks to unit tests 2016-12-23 13:17:26 +01:00
Cas Eliëns
67b5698a16 Add support for page breaks 2016-12-23 13:17:26 +01:00
Robert Winkler
6662eb6e9d Updated docs 2016-12-23 08:16:54 +01:00
Robert Winkler
d712b615d1 Updated bintray badge 2016-12-01 09:17:24 +01:00
Robert Winkler
393fd48d2f Release v1.0.0 2016-11-18 12:56:11 +01:00
Robert Winkler
e5aea526cd Updated version to 1.1.0-SNAPSHOT 2016-11-10 12:18:06 +01:00
Robert Winkler
83d3ee5a50 Changed bold to ** and italic to __ so that special chars in the text are possible 2016-11-10 12:17:33 +01:00
Robert Winkler
fec017886f Updated readme 2016-05-02 12:58:08 +02:00
Robert Winkler
6ee11e2876 Updated readme 2016-04-29 14:17:50 +02:00
Robert Winkler
4ba4b962e5 Updated readme 2016-04-29 14:15:15 +02:00
Robert Winkler
71710a4ba6 Updated readme 2016-04-29 14:11:44 +02:00
Robert Winkler
f8bc0d38e7 Updated readme 2016-04-29 14:10:50 +02:00
Robert Winkler
1ae72d99d1 Merge remote-tracking branch 'origin/master' 2016-04-29 14:03:11 +02:00
Robert Winkler
7b8c5e76bf Released v1.0.0 2016-04-29 14:03:04 +02:00
Hugo de Paix de Coeur
9e03544f8c supports for blank value for text and textLine only to support adding simple spaces to document 2016-04-12 18:13:24 +02:00
Hugo de Paix de Coeur
c246352b59 fixed sectionTitleWithAnchor and auto-generated anchor (and fixed tests)
fixed ConfluenceBuilder : missing replaceNewLinesWithWhiteSpace on title/anchor, removed extra newLine
2016-04-08 17:08:51 +02:00
Hugo de Paix de Coeur
962d934f2c Support <> in cross-reference texts in AsciiDoc 2016-04-08 11:50:40 +02:00
Hugo de Paix de Coeur
706eeb3d64 reintroduce literalTextLine(text)
rename listing -> listingBlock
2016-04-05 12:38:21 +02:00
Robert Winkler
d081d64fc5 Updated readme 2016-04-01 10:25:19 +02:00
Robert Winkler
05f217d2a4 Updated readme 2016-04-01 10:24:42 +02:00
Robert Winkler
539c5e5191 Fixed JavaDoc
Removed commons-collection by using Java8 Streams
2016-04-01 09:29:03 +02:00
Robert Winkler
c53d38c148 Fixed JavaDoc 2016-03-31 16:31:03 +02:00
Robert Winkler
21b1568dfc Upgrade to Java8 2016-03-31 16:25:43 +02:00
Robert Winkler
9bc01c9665 Merge remote-tracking branch 'origin/master' 2016-03-29 16:12:07 +02:00
Robert Winkler
f7e84d840f ImportMarkup, writeToFile and writeToFileWithoutExtension don't throw IOExceptions anymore, but RuntimeExceptions. 2016-03-29 16:11:14 +02:00
Hugo de Paix de Coeur
6c86494091 introduced paragraph(text, hardbreaks), force line breaks on each line for Markdown and ConfluenceMarkup 2016-03-18 11:53:02 +01:00
Robert Winkler
7caa2c5894 Adapted group id, versioning and root package to other swagger2markup projects 2016-03-18 10:36:17 +01:00
Robert Winkler
e37627e92f Fixed MarkupDocBuilderTests on windows by fixing line separator to LineSeparator.UNIX 2016-03-18 09:01:55 +01:00
Robert Winkler
bf0b218616 Merge branch 'master' of https://github.com/Swagger2Markup/markup-document-builder 2016-03-18 08:28:43 +01:00
Hugo de Paix de Coeur
7583d369e0 added OpenOption parameter in writeToFile() 2016-03-17 16:43:27 +01:00
Hugo de Paix de Coeur
4dd49e0fb8 fixed pipe escaping management in ConfluenceMarkup cell formatter (does not escape pipe in links in cells)
fixed corner cases in Regexp replacements (quoting)
2016-03-17 15:22:58 +01:00
Hugo de Paix de Coeur
a483e7e713 better cell formatting : content trimming and newLines management 2016-03-17 12:51:35 +01:00
Hugo de Paix de Coeur
e81c273828 fixed tests after removing hardbreaks 2016-03-16 18:27:07 +01:00
Hugo de Paix de Coeur
f5999f31d7 removed hardbreaks from AsciiDoc paragraph() 2016-03-16 18:18:47 +01:00
Hugo de Paix de Coeur
56f5db0634 remove unnecessary newlines when importMarkup text is blank 2016-03-16 17:41:04 +01:00
Hugo de Paix de Coeur
5758aa056a Introduce MarkupLanguage conversion in importMarkup. Currently support Markdown -> AsciiDoc. 2016-03-16 15:30:09 +01:00
Robert Winkler
15dfd7edca Merge branch 'master' of https://github.com/Swagger2Markup/markup-document-builder 2016-03-16 14:34:52 +01:00
Hugo de Paix de Coeur
48127855f6 Use DiffAssertions to check generated markup result in tests 2016-03-16 14:14:28 +01:00
Robert Winkler
f52ec1a63c Merge branch 'master' of https://github.com/Swagger2Markup/markup-document-builder 2016-03-16 12:47:43 +01:00
Hugo de Paix de Coeur
2a5d9a4e5c Support column headers style generically in MarkupTableColumn 2016-03-16 12:08:10 +01:00
Hugo de Paix de Coeur
60b73ac3e9 removed deprecated writeToFile* 2016-03-15 19:48:31 +01:00
Hugo de Paix de Coeur
81ad4f78dd cleanups 2016-03-15 19:40:59 +01:00
Hugo de Paix de Coeur
0e6620260b fixed crossReferences for ConfluenceMarkupBuilder 2016-03-15 19:33:06 +01:00
Hugo de Paix de Coeur
72bc8134c8 fixed empty cells for ConfluenceMarkupBuilder 2016-03-15 19:14:40 +01:00
Hugo de Paix de Coeur
78f0629514 fixed LINE_BREAK for ConfluenceMarkupBuilder 2016-03-15 19:08:07 +01:00
Hugo de Paix de Coeur
cc4a5b729b fixed documentTitle level for ConfluenceMarkupBuilder 2016-03-15 19:05:47 +01:00
Hugo de Paix de Coeur
ca172a2cd7 remove FILE_EXTENSION from Markups, use MarkupLanguage::getFileNameExtensions instead 2016-03-15 18:27:56 +01:00
Hugo de Paix de Coeur
e7f52fe7a4 fixing ConfluenceMarkupBuilder
fixed MarkdownBuilder with null block styles
2016-03-15 17:54:44 +01:00
Robert Winkler
6bb076e1b6 Added assertj-diff. 2016-03-15 08:21:52 +01:00
Hugo de Paix de Coeur
0c056c7b87 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/main/java/io/github/robwin/markup/builder/MarkupDocBuilders.java
#	src/main/java/io/github/robwin/markup/builder/atlassian/AtlassianWikiMarkupBuilder.java
#	src/main/java/io/github/robwin/markup/builder/confluenceMarkup/ConfluenceMarkupBuilder.java
#	src/main/java/io/github/robwin/markup/builder/internal/atlassian/AtlassianWikiMarkupBuilder.java
#	src/main/java/io/github/robwin/markup/builder/internal/markdown/MarkdownBuilder.java
2016-03-14 19:10:16 +01:00
Hugo de Paix de Coeur
0e87a0a6f6 copy with optional copyBuffer 2016-03-14 18:52:37 +01:00
Hugo de Paix de Coeur
c697fde3d1 factored importMarkupStyle1/2 + Style2 tests
removed deprecated tableWithHeaderRow
refactored ConfluenceMarkupBuilder
2016-03-14 18:37:18 +01:00
Hugo de Paix de Coeur
cd152f9154 simplify empty constructors
added missing copyright headers
2016-03-14 17:36:43 +01:00
Hugo de Paix de Coeur
fd72686689 Copy newLine in copy() method + non regression test 2016-03-14 17:10:10 +01:00
Robert Winkler
599b0857c4 Moved source code which does not belong to the external API into an internal package. 2016-03-14 13:34:07 +01:00
Robert Winkler
60000737c0 Updated publishing gradle script. 2016-03-14 10:55:20 +01:00
Robert Winkler
5db9da3f11 Updated publishing and coverage gradle scripts. 2016-03-14 10:51:06 +01:00
Robert Winkler
90dd731b4c Renamed ATLASSIAN to ATLASSIAN_WIKI 2016-03-14 10:04:40 +01:00
Robert Winkler
ef9d453ccf Merge remote-tracking branch 'origin/master' 2016-03-14 10:03:38 +01:00
Robert Winkler
32cd13e379 Updated README. 2016-03-14 10:03:20 +01:00
Robert Winkler
7bcc6dbab0 Merge pull request #23 from 2bad4u/master
Add Atlassian wiki as additonal markup language.
2016-03-13 16:08:53 +01:00
2bad4u
14184423b9 Adds a markup builder for Atlassian's Jira/Confluence wiki markup. 2016-03-13 14:10:26 +01:00
2bad4u
f527e33264 Make changes Java 1.7 compatible. 2016-03-13 09:14:13 +01:00
2bad4u
7e0d5bcb31 Opens MarkupDocBuilders for additional/external markup builders (includes an example for Confluence wiki markup) 2016-03-13 08:56:17 +01:00
Robert Winkler
9ce6fc6a80 New lines in Table headers are replaced by a whitespace
New lines in Table cells are replaced by the configured line separator.
2016-03-09 15:16:36 +01:00
Robert Winkler
4cac8a5d3b Removed Guava library. 2016-03-09 10:00:55 +01:00
Robert Winkler
495b8dd8af Updated versions of commons-collection, commons-lang3, commons-codec and slf4j-api. 2016-03-09 08:48:53 +01:00
Robert Winkler
e7bdd0774d Added default line separator if provided lineSeparator is null. 2016-03-04 15:08:14 +01:00
Robert Winkler
935ab9e4e2 Removed io.spring.gradle:dependency-management-plugin 2016-03-04 14:53:54 +01:00
Robert Winkler
7895b8008d Added Mac line separator. 2016-03-04 14:33:01 +01:00
Robert Winkler
b00a7f4ecf Added the functionality to provide a custom line separator which should be used. 2016-03-04 14:26:06 +01:00
Robert Winkler
cd8074a78f Added validation that input values are not null and empty. 2016-03-03 14:59:12 +01:00
Robert Winkler
c8fc1e0fdc Fixed AbstractMarkupDocBuilderTest on windows machines by setting newLine to a fixed value. 2016-03-03 14:52:02 +01:00
Robert Winkler
2dd33a73ec Removed source folder mainpjava. 2016-03-03 14:51:27 +01:00
Robert Winkler
9a70f7b668 Line separators (Mac, Windows, Linux) of input data are replaced by the system line separator. 2016-03-03 14:08:45 +01:00
Robert Winkler
71dead5b52 Merge pull request #21 from Kabhal/master
Support level 5 titles
2016-02-29 17:37:08 +01:00
Hugo de Paix de Coeur
3509f735e3 Support level 5 titles.
Added sectionTitleLevel(int level, String title) for convenience.
2016-02-29 14:59:26 +01:00
Hugo de Paix de Coeur
d8431b4cc5 logging fix 2016-02-29 10:56:18 +01:00
Robert Winkler
9cb1e4d1d4 Merge pull request #20 from Kabhal/master
Added new block methods (supporting title and admonitions)
2016-02-26 16:31:31 +01:00
Robert Winkler
e43e4f15da Renamed addfileExtension to addFileExtension 2016-02-26 16:14:57 +01:00
Hugo de Paix de Coeur
b7bdb1aea3 Added new block methods (supporting title and admonitions)
Refactored listing() and method() methods
Does not flush buffer anymore when writeToFile
2016-02-26 16:14:35 +01:00
Robert Winkler
8b6694d789 Merge pull request #19 from Kabhal/master
Added new interface methods to support java.nio.file.Path parameters
2016-02-25 21:03:02 +01:00
Hugo de Paix de Coeur
f45d2f3f6e Added new interface methods to support java.nio.file.Path parameters 2016-02-25 20:05:55 +01:00
Hugo de Paix de Coeur
85a98f2fbf MAX_TITLE_LEVEL = 4 -> 5 2016-02-23 15:59:12 +01:00
Robert Winkler
d46f784b78 Merge pull request #18 from Kabhal/master
Added importMarkup(markupText, levelOffset)
2016-02-23 14:13:11 +01:00
Hugo de Paix de Coeur
c9d7f701e7 Use Reader in importMarkup instead of a String 2016-02-23 13:55:37 +01:00
Hugo de Paix de Coeur
913b100f6b Support for levelOffset < 0 in importMarkup 2016-02-23 12:42:54 +01:00
Hugo de Paix de Coeur
689505e0d7 Check for levelOffset < 0 in importMarkup(markupText, levelOffset) 2016-02-22 20:42:12 +01:00
Hugo de Paix de Coeur
038edb8d94 Added importMarkup(markupText, levelOffset) 2016-02-22 20:36:50 +01:00
Hugo de Paix de Coeur
dddd5fc75c MarkupTableColumn documentation enhancements 2016-02-22 13:47:13 +01:00
Robert Winkler
1596fd5daf Merge pull request #17 from Kabhal/master
Public interface complete documentation
2016-02-22 13:31:10 +01:00
Hugo de Paix de Coeur
0666af6e1f Added 2 newlines at the end of generated output when output are files. This protect the final AsciiDoc when you later include these files. 2016-02-22 13:25:23 +01:00
Hugo de Paix de Coeur
8413192332 Added public interface complete documentation 2016-02-22 13:22:01 +01:00
Robert Winkler
1e43d3a140 Merge pull request #16 from Kabhal/master
Introduce Markup-dependent specifiers on tables
2016-02-19 16:58:37 +01:00
Hugo de Paix de Coeur
778e8bf4af Introduce Markup-dependent specifiers on tables 2016-02-19 16:20:27 +01:00
Robert Winkler
8c7015757f Merge pull request #15 from Kabhal/master
Added builder configuration .withAnchorPrefix
2016-02-18 19:30:45 +01:00
Hugo de Paix de Coeur
c69948c78a Introduce global builder configuration .withAnchorPrefix
Introduce copy() method to easily duplicate builders with configuration
2016-02-18 19:00:41 +01:00
Hugo de Paix de Coeur
52639d9907 sectionTitleWithAnchor* consistency fix when anchor == null => auto-generate anchor 2016-02-18 17:09:29 +01:00
Robert Winkler
bbb957c91d Merge pull request #14 from Kabhal/master
Introduce new sectionTitleWithAnchor* to allow more flexibility with title anchors
2016-02-18 16:43:46 +01:00
Hugo de Paix de Coeur
80ce77826e Introduce new sectionTitleWithAnchor* to allow users to create titles without anchor, with a custom anchor (will be normalized anyway), or with an auto-generated anchor. 2016-02-18 16:25:30 +01:00
Robert Winkler
04fb517fa0 Merge pull request #13 from Kabhal/master
new italic/bold/text methods, manage line breaks
2016-02-18 15:21:12 +01:00
Hugo de Paix de Coeur
3c4ccc8eae introduce forceLineBreak on all *Line methods 2016-02-18 15:12:49 +01:00
Hugo de Paix de Coeur
4c1a64b20c Create a builder instance from another builder instance, for easier composition 2016-02-18 15:12:49 +01:00
Hugo de Paix de Coeur
577c0a4f94 introduce text, italicText, boldText
remove *AsString builders, use a new MarkupDocBuilder with toString() method instead
2016-02-18 15:12:49 +01:00
Hugo de Paix de Coeur
f3d797c1a9 anchor normalization better manages beginning and ending escape characters, and intermediate punctuation 2016-02-17 13:52:39 +01:00
Robert Winkler
bff7be0714 Merge pull request #12 from Kabhal/normalization
Normalization + hardbreaks fixes
2016-02-16 12:43:30 +01:00
Hugo de Paix de Coeur
3d31f71f69 missing Mockito in Gradle
fixed tests
2016-02-16 11:11:55 +01:00
Hugo de Paix de Coeur
9f4d384221 fixed normalization and provided tests for normalization (finally) ! 2016-02-15 20:03:43 +01:00
Hugo de Paix de Coeur
730d4bfc19 Use paragrah local hardbreaks instead of global attribute 2016-02-15 14:51:42 +01:00
Robert Winkler
d26789dd8b Merge pull request #11 from Kabhal/normalization
Ignore punctuation in normalizeAnchor
2016-02-12 17:23:25 +01:00
Hugo de Paix de Coeur
60cba6d2b8 Ignore punctuation in normalizeAnchor
Added new functions to create sections with a custom anchor not directly derived from the title
2016-02-12 16:37:25 +01:00
Robert Winkler
882c673a0e [Bug] The document title must not have a anchor in front of it. 2016-02-12 11:28:26 +01:00
Robert Winkler
8097b3ad21 Updated asciidoctor-gradle-plugin: and asciidoctorj-pdf Gradle plugins to newer versions. 2016-02-12 11:27:36 +01:00
Robert Winkler
260dc04a61 Merge pull request #10 from Kabhal/normalization
fixed #9 Refactor anchor and cross-references
2016-02-11 19:40:54 +01:00
Hugo de Paix de Coeur
4719827fac fixed #9 Refactor anchor and cross-reference interface and implementation 2016-02-11 19:09:18 +01:00
Hugo de Paix de Coeur
050f600598 Support for inter-document cross-references in Markdown 2016-02-11 19:09:18 +01:00
Robert Winkler
8233565b6b Merge pull request #8 from Kabhal/master
Fixed inter-document cross-references
2016-02-10 13:08:43 +01:00
Hugo de Paix de Coeur
337c8ba403 renamed crossReference -> crossReferenceAnchor and crossReferenceTitle -> crossReference as it's the default behavior
introduced addFilenameExtension (e.g. needed for inter-document cross-references)
fixed anchor normalization (support for ASCII characters in AsciiDoc)
Several workarounds with inter-document cross-references
Removed documentTitleWithAttributes as it's no use as-is
2016-02-10 12:13:32 +01:00
Hugo de Paix de Coeur
5b5a58ee7f Fixed inter-document cross-references 2016-02-08 16:01:08 +01:00
Robert Winkler
3799cf362c Merge pull request #7 from johanhammar/master
Update dependency-management-plugin to work with Gradle versions newer than 2.5 and Gradle Wrapper to 2.10
2016-02-07 11:16:58 +01:00
Johan Hammar
c6d9d074cd Update Gradle wrapper to 2.10 2016-02-07 10:47:09 +01:00
Johan Hammar
2b4e085de0 Update dependency-management-plugin to work with Gradle versions newer than 2.5 2016-02-07 09:55:12 +01:00
Robert Winkler
14652f7d0f Merge pull request #6 from Kabhal/master
fixed anchor normalization
2016-02-04 19:26:32 +01:00
Hugo de Paix de Coeur
9077a1d422 fixed tests compilation 2016-02-04 17:24:43 +01:00
Hugo de Paix de Coeur
6ef0f8d28c fixed anchor normalization (again). Asciidoc anchor normalization differs between title and custom anchors => introducted crossReferenceTitle 2016-02-04 17:18:05 +01:00
Robert Winkler
732eeca873 Fixed travis.yml 2016-02-04 13:54:28 +01:00
Robert Winkler
11dfce66a5 Fixed travis.yml 2016-02-04 12:58:26 +01:00
Robert Winkler
517504a030 Travis Secure Environment variables must be escaped 2016-02-04 12:55:07 +01:00
Robert Winkler
ba6126087d Merge pull request #5 from Kabhal/master
Correct anchor normalization & cleanups
2016-02-03 19:47:55 +01:00
Hugo de Paix de Coeur
b7187f4d83 Merge branch 'master' of https://github.com/Kabhal/markup-document-builder 2016-02-03 19:38:42 +01:00
Hugo de Paix de Coeur
1d62c72512 Renamed TableColumnSpec to MarkupTableColumn 2016-02-03 19:34:52 +01:00
Hugo de Paix de Coeur
885a43fa89 Fixed replacing error 2016-02-03 19:34:33 +01:00
Hugo de Paix de Coeur
1d06f41be8 Cleanups 2016-02-03 19:26:00 +01:00
Hugo de Paix de Coeur
816df10aca Cleanups 2016-02-03 19:23:20 +01:00
Hugo de Paix de Coeur
ded602de20 Fixed anchor normalization 2016-02-03 19:15:33 +01:00
Robert Winkler
ba7089cf05 Updated readme 2016-02-03 19:00:24 +01:00
Robert Winkler
7d8fb9e494 Merge pull request #4 from Kabhal/master
Implemented anchors and crossReferences for Markdown (GFM style)
2016-02-03 18:32:16 +01:00
Robert Winkler
c48ed138fd Merge pull request #3 from Kabhal/master
Anchor and enhanced table support
2016-02-03 18:20:49 +01:00
Hugo de Paix de Coeur
ff085c43f7 Implemented anchors and crossReferences for Markdown (GFM style) 2016-02-03 18:19:28 +01:00
Hugo de Paix de Coeur
c7fb29902f Renamed inline* to *AsString 2016-02-03 17:46:34 +01:00
Hugo de Paix de Coeur
51a1eb2805 More tests 2016-02-03 17:46:34 +01:00
Hugo de Paix de Coeur
0c136c2987 Introduce inline commands : inlineAnchor, inlineCrossReference for easier markup composition 2016-02-03 17:46:34 +01:00
Hugo de Paix de Coeur
74bd2b0d2e Enhanced support for tables 2016-02-03 17:46:34 +01:00
Hugo de Paix de Coeur
48c48ba56b Introduced new commands : anchor(anchor), crossReference(anchor, text)
Refactored writeToFile for robustness
Cleanups and fixes
2016-02-03 17:46:34 +01:00
Robert Winkler
6293b6a996 Fixed coveralls badge 2016-02-03 16:01:24 +01:00
Robert Winkler
6093d4ab92 Added artifactoryPublish task to TravisCI to publish SNAPSHOTS to OSS Artifactory 2016-02-03 16:00:56 +01:00
Robert Winkler
119abf008d Added Artifactory Gradle Plugin in order to deploy snapshots to oss.jfrog.org 2016-02-03 13:25:22 +01:00
Robert Winkler
609dcbc7d5 Merge remote-tracking branch 'origin/master' 2015-11-12 10:57:49 +01:00
Robert Winkler
4e61063106 Added method sectionTitleLevel4 2015-11-12 10:57:40 +01:00
Robert Winkler
b7cad8a7c8 Updated documentation 2015-07-09 08:11:01 +02:00
Robert Winkler
97b068150d Added twitter batch 2015-06-16 08:31:27 +02:00
Robert Winkler
c1327e6b90 Fixed SECTION_TITLE_LEVEL3 in Markdown enum 2015-05-18 12:32:17 +02:00
Robert Winkler
68c101fced Merge pull request #1 from BuJo/markdown-level3
Fix Markdown level 3 title
2015-05-15 22:10:28 +02:00
Jonathan Buch
02ea0f4e54 Fix Markdown level 3 title 2015-05-15 17:33:07 +02:00
Robert Winkler
3933836290 Updates documentation 2015-05-01 19:48:20 +02:00
Robert Winkler
9471093dce Updated documentation 2015-04-30 18:10:27 +02:00
Robert Winkler
15a96a7338 Updated documentation 2015-04-24 12:53:02 +02:00
Robert Winkler
e6dc1b63d0 Added Apache2 Copyright Header 2015-04-24 08:25:17 +02:00
Robert Winkler
1dd8dd2d25 New version number 2015-04-20 09:01:29 +02:00
Robert Winkler
2657b03de0 Merge branch 'release/0.1.2' 2015-04-15 16:08:20 +02:00
45 changed files with 3873 additions and 824 deletions

View File

@@ -1,7 +1,12 @@
language: java
jdk:
- oraclejdk7
- oraclejdk8
before_install:
- chmod +x gradlew
- chmod +x gradlew
after_success:
- ./gradlew jacocoTestReport coveralls
- ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
env:
global:
- secure: Gw8S2a4VumGXAWAmGAh0jOU3WxiG54mKPEI/XZVc+CjcYyb5MtcgzDi0snmfXOAcjME2vJDqi+6tYF8jjQFkb2Tm5qCSVZxbRPeyPv8d9lJL2ZIDpz7TAgBiWJiJmVMFjo0FGzWp7csJwl1KMJUlH18Sz4tgmLA4YgxoLf70Gtk=
- secure: CIcQiSraUwXtbE3dAZ61xITqYL4kORjN37NfDz747ceaFn4u4Mui7dJ7k8GhujW3Cm/N8NalJ/MwlbK0sHIv0bGmi/CNwn15xE2ymJXoSHEihAUiKm2ql6k/hHp7T5LkUafLWbrIGQc4ch4jJRqsNaK1ouLpZLTzHromiiQZXZw=

View File

@@ -1,13 +1,13 @@
= MarkupDocBuilder
:author: Robert Winkler
:version: 0.1.2
:version: 1.1.1
:hardbreaks:
image:https://travis-ci.org/RobWin/markup-document-builder.svg["Build Status", link="https://travis-ci.org/RobWin/markup-document-builder"] image:https://coveralls.io/repos/RobWin/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/markup-document-builder"] image:https://api.bintray.com/packages/robwin/maven/markup-document-builder/images/download.svg[link="https://bintray.com/robwin/maven/markup-document-builder/_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/markup-document-builder.svg?branch=master["Build Status", link="https://travis-ci.org/Swagger2Markup/markup-document-builder"] image:https://coveralls.io/repos/Swagger2Markup/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/Swagger2Markup/markup-document-builder"] image:https://api.codacy.com/project/badge/grade/c56a372454164f21b1b2eec8eb48b370["Codacy code quality", link="https://www.codacy.com/app/robwin/markup-document-builder"] image:https://api.bintray.com/packages/swagger2markup/Maven/io.github.swagger2markup%3Amarkup-document-builder/images/download.svg[link="https://bintray.com/swagger2markup/Maven/io.github.swagger2markup%3Amarkup-document-builder/_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"]
== Overview
This project is a Markup document builder (AsciiDoc and Markdown). The primary goal of this project is to simplify the creation of Markup documents.
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.
@@ -17,7 +17,7 @@ The project is published in JCenter and Maven Central.
==== Maven
[source,xml]
[source,xml, subs="specialcharacters,attributes"]
----
<repositories>
<repository>
@@ -29,23 +29,22 @@ The project is published in JCenter and Maven Central.
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<dependency>
<groupId>io.github.robwin</groupId>
<groupId>io.github.swagger2markup</groupId>
<artifactId>markup-document-builder</artifactId>
<version>0.1.2</version>
<version>{version}</version>
</dependency>
----
==== Gradle
[source,groovy]
[source,groovy, subs="attributes"]
----
repositories {
jcenter()
}
compile "io.github.robwin:markup-document-builder:0.1.2"
compile "io.github.swagger2markup:markup-document-builder:{version}"
----
=== Using MarkupDocBuilder
@@ -113,3 +112,13 @@ You can generate your PDF or HTML documentation via https://github.com/asciidoct
image::images/asciidoc_html.jpg[asciidoc_html]
== 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.

View File

@@ -5,3 +5,25 @@
=== 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 1.1.0
* Changed bold to ** and italic to __ so that special chars in the text are possible
== Version 1.1.1
* Added a method to add page breaks.
== Version 1.1.2
* Improve code blocks in markdown

View File

@@ -4,33 +4,29 @@ buildscript {
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.3.1.RELEASE'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11'
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'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
}
}
description = 'A Markup (Markdown, AsciiDoc) document builder'
version = '0.1.2'
group = 'io.github.robwin'
version = '1.1.2'
group = 'io.github.swagger2markup'
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'
apply from: 'gradle/coverage.gradle'
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
options.deprecation = true
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
options.compilerArgs << "-Xdoclint:none"
}
repositories {
@@ -39,32 +35,17 @@ repositories {
}
dependencies {
compile 'commons-io:commons-io'
compile 'ch.qos.logback:logback-classic'
testCompile 'junit:junit'
}
dependencyManagement {
dependencies {
"commons-io:commons-io" "2.4"
"ch.qos.logback:logback-classic" "1.1.2"
"junit:junit" "4.11"
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
compile 'org.slf4j:slf4j-api:1.7.18'
//compile 'org.apache.commons:commons-collections4:4.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile "commons-io:commons-io:2.4"
compile "commons-codec:commons-codec:1.10"
compile "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.0"
testCompile 'junit:junit:4.11'
testCompile 'io.github.robwin:assertj-diff:0.1.1'
testCompile "org.mockito:mockito-core:1.9.5"
testCompile 'ch.qos.logback:logback-classic:1.1.6'
testCompile 'io.github.robwin:assertj-diff:0.1.1'
}
asciidoctor {
@@ -78,21 +59,10 @@ asciidoctor {
sourceDir "build/tmp"
}
jacocoTestReport {
reports {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
}
}
tasks.coveralls {
dependsOn 'check'
}
tasks.asciidoctor {
dependsOn 'check'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
gradleVersion = '4.3.1'
}

13
gradle/coverage.gradle Normal file
View File

@@ -0,0 +1,13 @@
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
jacocoTestReport {
reports {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
}
}
tasks.coveralls {
dependsOn 'check'
}

View File

@@ -1,24 +1,44 @@
import java.text.SimpleDateFormat
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
apply plugin: "com.jfrog.artifactory"
Date buildTimeAndDate = new Date()
ext {
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
projectUrl = 'https://github.com/Swagger2Markup/markup-document-builder'
licenseUrl = 'https://github.com/Swagger2Markup/markup-document-builder/blob/master/LICENSE.txt'
scmUrl = 'https://github.com/Swagger2Markup/markup-document-builder.git'
issuesUrl = 'https://github.com/Swagger2Markup/markup-document-builder/issues'
}
def projectArtifactId = 'markup-document-builder'
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
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
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
'Build-Time': "${new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")}",
'Specification-Title': "${project.name}",
'Specification-Version': project.version.toString(),
'Implementation-Title': "${project.name}",
'Implementation-Version': project.version.toString()
)
}
}
@@ -29,35 +49,6 @@ 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 = 'markup-document-builder'
websiteUrl = 'https://github.com/RobWin/markup-document-builder'
issueTrackerUrl = 'https://github.com/RobWin/markup-document-builder/issues'
vcsUrl = 'https://github.com/RobWin/markup-document-builder.git'
desc = 'A Markup (Markdown, AsciiDoc) document builder.'
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) {
@@ -74,17 +65,17 @@ publishing {
it.scope*.value = 'compile'
}
root.appendNode('name', 'markup-document-builder')
root.appendNode('name', project.name)
root.appendNode('packaging', 'jar')
root.appendNode('url', 'https://github.com/RobWin/markup-document-builder')
root.appendNode('description', 'A Markup (Markdown, AsciiDoc) document builder.')
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', 'https://github.com/RobWin/markup-document-builder/blob/master/LICENSE.txt')
license.appendNode('url', licenseUrl)
license.appendNode('distribution', 'repo')
root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/markup-document-builder.git')
root.appendNode('scm').appendNode('url', scmUrl)
def developers = root.appendNode('developers')
devs.each {
@@ -98,3 +89,63 @@ publishing {
}
}
}
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 = 'io.github.swagger2markup:markup-document-builder'
userOrg = 'swagger2markup'
websiteUrl = projectUrl
issueTrackerUrl = issuesUrl
vcsUrl = scmUrl
desc = rootProject.description
licenses = ['Apache-2.0']
version {
vcsTag = rootProject.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
}
}
}
}
artifactory {
contextUrl = 'https://oss.jfrog.org'
resolve {
repository {
repoKey = 'libs-release'
}
}
publish {
repository {
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
//when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in
//~/.gradle/gradle.properties, otherwise to be set in the build server
username = project.hasProperty('bintrayUsername') ? project.bintrayUsername : System.getenv('BINTRAY_USER')
password = project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : System.getenv('BINTRAY_KEY')
}
defaults {
publications('mavenJava')
}
}
if (System.properties['https.proxyHost']) {
clientConfig.proxy.host = System.properties['https.proxyHost']
clientConfig.proxy.port = System.properties['https.proxyPort'].toInteger()
}
}
tasks.artifactoryPublish {
dependsOn 'check'
}

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Thu Feb 19 15:49:46 CET 2015
#Mon Dec 04 10:31:36 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip

74
gradlew vendored Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -6,12 +6,30 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
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"
@@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=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"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -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" "$@"

14
gradlew.bat vendored
View File

@@ -8,14 +8,14 @@
@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 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
@@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows 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.
@@ -60,11 +59,6 @@ set _SKIP=2
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

View File

@@ -1,106 +0,0 @@
package io.github.robwin.markup.builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
/**
* @author Robert Winkler
*/
public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
protected StringBuilder documentBuilder = new StringBuilder();
protected String newLine = System.getProperty("line.separator");
protected Logger logger = LoggerFactory.getLogger(getClass());
protected void documentTitle(Markup markup, String title){
documentBuilder.append(markup).append(title).append(newLine).append(newLine);
}
protected void documentTitleWithAttributes(Markup markup, String title){
documentBuilder.append(markup).append(title).append(newLine);
}
protected void sectionTitleLevel1(Markup markup, String title){
documentBuilder.append(markup).append(title).append(newLine);
}
protected void sectionTitleLevel2(Markup markup, String title){
documentBuilder.append(markup).append(title).append(newLine);
}
protected void sectionTitleLevel3(Markup markup, String title){
documentBuilder.append(markup).append(title).append(newLine);
}
@Override
public MarkupDocBuilder textLine(String text){
documentBuilder.append(text).append(newLine);
return this;
}
protected void paragraph(Markup markup, String text){
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(newLine);
}
protected void listing(Markup markup, String text){
delimitedTextLine(markup, text);
}
protected void delimitedTextLine(Markup markup, String text){
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(markup).append(newLine).append(newLine);
}
protected void delimitedTextLineWithoutLineBreaks(Markup markup, String text){
documentBuilder.append(markup).append(text).append(markup).append(newLine);
}
protected void preserveLineBreaks(Markup markup){
documentBuilder.append(markup).append(newLine);
}
protected void boldTextLine(Markup markup, String text){
delimitedTextLineWithoutLineBreaks(markup, text);
}
protected void italicTextLine(Markup markup, String text){
delimitedTextLineWithoutLineBreaks(markup, text);
}
protected void unorderedList(Markup markup, List<String> list){
documentBuilder.append(newLine);
for(String listEntry : list){
documentBuilder.append(markup).append(listEntry).append(newLine);
}
documentBuilder.append(newLine);
}
@Override
public MarkupDocBuilder newLine(){
documentBuilder.append(newLine);
return this;
}
@Override
public String toString(){
return documentBuilder.toString();
}
@Override
public void writeToFile(String directory, String fileNameWithExtension, Charset charset) throws IOException {
Files.createDirectories(Paths.get(directory));
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(directory, fileNameWithExtension), charset)){
writer.write(documentBuilder.toString());
}
if (logger.isInfoEnabled()) {
logger.info("{} was written to: {}", fileNameWithExtension, directory);
}
documentBuilder = new StringBuilder();
}
}

View File

@@ -1,8 +0,0 @@
package io.github.robwin.markup.builder;
/**
* @author Robert Winkler
*/
public interface Markup {
public String toString();
}

View File

@@ -1,55 +0,0 @@
package io.github.robwin.markup.builder;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
/**
* @author Robert Winkler
*/
public interface MarkupDocBuilder {
MarkupDocBuilder documentTitle(String title);
MarkupDocBuilder documentTitleWithAttributes(String title);
MarkupDocBuilder sectionTitleLevel1(String title);
MarkupDocBuilder sectionTitleLevel2(String title);
MarkupDocBuilder sectionTitleLevel3(String title);
MarkupDocBuilder textLine(String text);
MarkupDocBuilder paragraph(String text);
MarkupDocBuilder listing(String text);
MarkupDocBuilder source(String text, String language);
MarkupDocBuilder boldTextLine(String text);
MarkupDocBuilder italicTextLine(String text);
MarkupDocBuilder unorderedList(List<String> list);
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV);
MarkupDocBuilder crossReference(String text);
MarkupDocBuilder newLine();
/**
* Returns a string representation of the document.
*/
String 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 java.io.IOException if the file cannot be written
*/
void writeToFile(String directory, String fileName, Charset charset) throws IOException;
}

View File

@@ -1,22 +0,0 @@
package io.github.robwin.markup.builder;
import io.github.robwin.markup.builder.asciidoc.AsciiDocBuilder;
import io.github.robwin.markup.builder.markdown.MarkdownBuilder;
/**
* @author Robert Winkler
*/
public final class MarkupDocBuilders {
private MarkupDocBuilders(){};
public static MarkupDocBuilder documentBuilder(MarkupLanguage markupLanguage){
switch(markupLanguage){
case MARKDOWN: return new MarkdownBuilder();
case ASCIIDOC: return new AsciiDocBuilder();
default: return new AsciiDocBuilder();
}
}
}

View File

@@ -1,25 +0,0 @@
package io.github.robwin.markup.builder;
import java.util.Arrays;
import java.util.List;
/**
* @author Robert Winkler
*/
public enum MarkupLanguage {
ASCIIDOC(".adoc,.asciidoc"),
MARKDOWN(".md,.markdown");
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(","));
}
}

View File

@@ -1,41 +0,0 @@
package io.github.robwin.markup.builder.asciidoc;
import io.github.robwin.markup.builder.Markup;
/**
* @author Robert Winkler
*/
public enum AsciiDoc implements Markup {
LABELED(":: "),
TABLE("|==="),
TABLE_COLUMN_DELIMITER("|"),
LISTING("----"),
HARDBREAKS(":hardbreaks:"),
DOCUMENT_TITLE("= "),
SECTION_TITLE_LEVEL1("== "),
SECTION_TITLE_LEVEL2("=== "),
SECTION_TITLE_LEVEL3("==== "),
BOLD("*"),
ITALIC("_"),
LIST_ENTRY("* "),
CROSS_REFERENCE_START("<<"),
CROSS_REFERENCE_END(">>");
private final String markup;
/**
* @param markup AsciiDoc markup
*/
private AsciiDoc(final String markup) {
this.markup = markup;
}
/* (non-Javadoc)
* @see java.lang.Enum#toString()
*/
@Override
public String toString() {
return markup;
}
}

View File

@@ -1,105 +0,0 @@
package io.github.robwin.markup.builder.asciidoc;
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
import io.github.robwin.markup.builder.MarkupDocBuilder;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
/**
* @author Robert Winkler
*/
public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
@Override
public MarkupDocBuilder documentTitle(String title){
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
return this;
}
@Override
public MarkupDocBuilder documentTitleWithAttributes(String title) {
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel1(String title){
sectionTitleLevel1(AsciiDoc.SECTION_TITLE_LEVEL1, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel2(String title){
sectionTitleLevel2(AsciiDoc.SECTION_TITLE_LEVEL2, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel3(String title){
sectionTitleLevel3(AsciiDoc.SECTION_TITLE_LEVEL3, title);
return this;
}
@Override
public MarkupDocBuilder paragraph(String text){
paragraph(AsciiDoc.HARDBREAKS, text);
return this;
}
@Override
public MarkupDocBuilder listing(String text){
listing(AsciiDoc.LISTING, text);
return this;
}
@Override
public MarkupDocBuilder boldTextLine(String text){
boldTextLine(AsciiDoc.BOLD, text);
return this;
}
@Override
public MarkupDocBuilder italicTextLine(String text) {
italicTextLine(AsciiDoc.ITALIC, text);
return this;
}
@Override
public MarkupDocBuilder unorderedList(List<String> list){
unorderedList(AsciiDoc.LIST_ENTRY, list);
return this;
}
@Override
public MarkupDocBuilder source(String text, String language){
documentBuilder.append(String.format("[source,%s]", language)).append(newLine);
listing(AsciiDoc.LISTING, text);
return this;
}
@Override
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
documentBuilder.append("[options=\"header\"]").append(newLine);
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
for(String row : rowsInPSV){
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(row).append(newLine);
}
documentBuilder.append(AsciiDoc.TABLE).append(newLine).append(newLine);
return this;
}
@Override
public MarkupDocBuilder crossReference(String text) {
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_START).append(text).append(AsciiDoc.CROSS_REFERENCE_END);
return this;
}
@Override
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
String fileNameWithExtension = fileName + ".adoc";
super.writeToFile(directory, fileNameWithExtension, charset);
}
}

View File

@@ -1,37 +0,0 @@
package io.github.robwin.markup.builder.markdown;
import io.github.robwin.markup.builder.Markup;
/**
* @author Robert Winkler
*/
public enum Markdown implements Markup {
HARDBREAKS(""),
TABLE_COLUMN_DELIMITER("|"),
TABLE_ROW("-"),
LISTING("```"),
DOCUMENT_TITLE("# "),
SECTION_TITLE_LEVEL1("## "),
SECTION_TITLE_LEVEL2("### "),
SECTION_TITLE_LEVEL3("### "),
BOLD("**"),
ITALIC("*"),
LIST_ENTRY("* ");
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;
}
}

View File

@@ -1,126 +0,0 @@
package io.github.robwin.markup.builder.markdown;
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
import io.github.robwin.markup.builder.MarkupDocBuilder;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
/**
* @author Robert Winkler
*/
public class MarkdownBuilder extends AbstractMarkupDocBuilder
{
@Override
public MarkupDocBuilder documentTitle(String title){
documentTitle(Markdown.DOCUMENT_TITLE, title);
return this;
}
@Override
public MarkupDocBuilder documentTitleWithAttributes(String title) {
documentTitle(Markdown.DOCUMENT_TITLE, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel1(String title){
sectionTitleLevel1(Markdown.SECTION_TITLE_LEVEL1, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel2(String title){
sectionTitleLevel2(Markdown.SECTION_TITLE_LEVEL2, title);
return this;
}
@Override
public MarkupDocBuilder sectionTitleLevel3(String title){
sectionTitleLevel3(Markdown.SECTION_TITLE_LEVEL3, title);
return this;
}
@Override
public MarkupDocBuilder paragraph(String text){
paragraph(Markdown.HARDBREAKS, text);
return this;
}
@Override
public MarkupDocBuilder listing(String text){
listing(Markdown.LISTING, text);
return this;
}
@Override
public MarkupDocBuilder source(String text, String language){
documentBuilder.append(Markdown.LISTING).append(language).append(newLine).
append(text).append(newLine).
append(Markdown.LISTING).append(newLine).append(newLine);
return this;
}
@Override
public MarkupDocBuilder boldTextLine(String text){
boldTextLine(Markdown.BOLD, text);
return this;
}
@Override
public MarkupDocBuilder italicTextLine(String text) {
italicTextLine(Markdown.ITALIC, text);
return this;
}
@Override
public MarkupDocBuilder unorderedList(List<String> list){
unorderedList(Markdown.LIST_ENTRY, list);
return this;
}
@Override
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
String headersInPSV = rowsInPSV.get(0);
List<String> contentRowsInPSV = rowsInPSV.subList(1, rowsInPSV.size());
String[] headersAsArray = headersInPSV.split(String.format("\\%s", Markdown.TABLE_COLUMN_DELIMITER.toString()));
List<String> headers = Arrays.asList(headersAsArray);
// Header
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
documentBuilder.append(headersInPSV);
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
newLine();
// Header/Content separator
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
for(String header : headers){
for(int i = 1; i<5; i++) {
documentBuilder.append(Markdown.TABLE_ROW);
}
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
}
newLine();
// Content
for(String contentRowInPSV : contentRowsInPSV){
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
documentBuilder.append(contentRowInPSV);
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
newLine();
}
newLine().newLine();
return this;
}
@Override
// TODO
public MarkupDocBuilder crossReference(String text) {
throw new UnsupportedOperationException("Not yet supported");
}
@Override
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
String fileNameWithExtension = fileName + ".md";
super.writeToFile(directory, fileNameWithExtension, charset);
}
}

View File

@@ -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 (<tt>\n</tt>).
*/
UNIX("\n"),
/**
* Line separator for Windows systems (<tt>\r\n</tt>).
*/
WINDOWS("\r\n"),
/**
* Line separator for Macintosh systems (<tt>\r</tt>).
*/
MAC("\r");
private String lineSeparator;
LineSeparator(String lineSeparator) {
this.lineSeparator = lineSeparator;
}
@Override
public String toString() {
return lineSeparator;
}
}

View File

@@ -0,0 +1,9 @@
package io.github.swagger2markup.markup.builder;
public enum MarkupAdmonition {
NOTE,
TIP,
IMPORTANT,
CAUTION,
WARNING
}

View File

@@ -0,0 +1,9 @@
package io.github.swagger2markup.markup.builder;
public enum MarkupBlockStyle {
SIDEBAR,
EXAMPLE,
LITERAL,
LISTING,
PASSTHROUGH
}

View File

@@ -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 -&gt; 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);
}

View File

@@ -0,0 +1,81 @@
/*
*
* 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));
}
}
}

View File

@@ -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(","));
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,546 @@
/*
*
* 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 io.github.swagger2markup.markup.builder.MarkupBlockStyle;
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import nl.jworks.markdown_to_asciidoc.Converter;
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 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 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 StringBuilder documentBuilder = new StringBuilder();
protected String newLine;
protected Logger logger = LoggerFactory.getLogger(getClass());
protected String anchorPrefix = null;
public AbstractMarkupDocBuilder() {
this(System.getProperty("line.separator"));
}
public AbstractMarkupDocBuilder(String newLine) {
this.newLine = newLine;
}
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 Converter.convertMarkdownToAsciiDoc(markupText) + 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) {
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);
}
}

View File

@@ -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();
}

View File

@@ -0,0 +1,59 @@
/*
*
* 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 {
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;
}
}

View File

@@ -0,0 +1,266 @@
/*
*
* 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(String newLine) {
super(newLine);
}
protected MarkupLanguage getMarkupLanguage() {
return MarkupLanguage.ASCIIDOC;
}
@Override
public MarkupDocBuilder copy(boolean copyBuffer) {
AsciiDocBuilder builder = new AsciiDocBuilder(newLine);
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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -1,66 +0,0 @@
package io.github.robwin.markup.builder;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Robert Winkler
*/
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);
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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
|===

View File

@@ -0,0 +1,134 @@
= Test title
== Section Level 1a
[[_level-1a]]
== Section with anchor Level 1a
[[_section_with_anchor_level_1a]]
== Section with anchor Level 1a
=== Section Level 2a
[[_level-2a]]
=== Section with anchor Level 2a
[[_section_with_anchor_level_2a]]
=== Section with anchor Level 2a
==== Section Level 3a
[[_level-3a]]
==== Section with anchor Level 3a
[[_section_with_anchor_level_3a]]
==== Section with anchor Level 3a
===== Section Level 4a
[[_level-4a]]
===== Section with anchor Level 4a
[[_section_with_anchor_level_4a]]
===== Section with anchor Level 4a
====== Section Level 5a
[[_level-5a]]
====== Section with anchor Level 5a
[[_section_with_anchor_level_5a]]
====== Section with anchor Level 5a
Paragraph with long text bla bla bla bla bla
Line1
Line2
[%hardbreaks]
Line1
Line2
----
Source code listing
----
[source,java]
----
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)
----
====
Example
====
.Example
====
Example
====
[IMPORTANT]
====
Example
====
[CAUTION]
----
Listing
----
[NOTE]
....
Literal
....
[TIP]
****
Sidebar
****
[WARNING]
++++
Passthrough
++++
<<<
[options="", cols=""]
|===
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3
|===
[options="header", cols="0,2,1h"]
|===
|Header1||Header3
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3
|===
== Section Level 1b
=== Section Level 2b
text line +
`Literal text line` +
**Bold text line** +
__Italic text line__ +
**bold**__italic__regular +
* Entry1
* Entry2
* Entry 2
[[_anchor,text]]
[[_simple_anchor]]
[[_8be261a9de7ce958fe46548a62609aeb]]
<<./document.adoc#anchor,text>> +
<< ɀ µ&|ù This .:/-_ >> +
<<document.adoc#_anchor,text>> +
<<_8be261a9de7ce958fe46548a62609aeb>> +

View File

@@ -0,0 +1,8 @@
||Header1\\ first one|| ||Header3||
|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|
|[Title|Page#Anchor]Row 1 \| Column 1[Title|Page#Anchor]|\|[Title1|Page#Anchor]Row1 Column2\|[Title1|Page#Anchor]||\|Row 1 Column 3\||
|Row 2 \\| Column \\ 1|Row 2 \|\| Column 2||Row 2 \| \| Column 3|

View File

@@ -0,0 +1,112 @@
h1. Test title
h2. Section Level 1a
h2. Section with anchor Level 1a {anchor:level-1a}
h2. Section with anchor Level 1a {anchor:section_with_anchor_level_1a}
h3. Section Level 2a
h3. Section with anchor Level 2a {anchor:level-2a}
h3. Section with anchor Level 2a {anchor:section_with_anchor_level_2a}
h4. Section Level 3a
h4. Section with anchor Level 3a {anchor:level-3a}
h4. Section with anchor Level 3a {anchor:section_with_anchor_level_3a}
h5. Section Level 4a
h5. Section with anchor Level 4a {anchor:level-4a}
h5. Section with anchor Level 4a {anchor:section_with_anchor_level_4a}
h6. Section Level 5a
h6. Section with anchor Level 5a {anchor:level-5a}
h6. Section with anchor Level 5a {anchor:section_with_anchor_level_5a}
Paragraph with long text bla bla bla bla bla
Line1
Line2
Line1\\
Line2
{code}
Source code listing
{code}
{code:language=java}
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.CONFLUENCE_MARKUP)
{code}
{panel}
Example
{panel}
{panel:title=Example}
Example
{panel}
{alert}
Example
{alert}
{code:title=Caution}
Listing
{code}
Note :
{noformat}
Literal
{noformat}
{tip}
Sidebar
{tip}
Warning :
{html}
Passthrough
{html}
<div style='page-break-before:always;'></div>
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3|
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3|
||Header1|| ||Header3||
|Row 1 \| Column 1|Row 1 \| Column 2||Row 1 \| Column 3|
|Row 2 \| Column 1|Row 2 \| Column 2||Row 2 \| Column 3|
h2. Section Level 1b
h3. Section Level 2b
text line\\
{noformat}Literal text line{noformat}\\
*Bold text line*\\
_Italic text line_\\
*bold*_italic_regular\\
* Entry1
* Entry2
* Entry 2
{anchor:anchor}
{anchor:simple_anchor}
{anchor:8be261a9de7ce958fe46548a62609aeb}
[text|./document.txt#anchor]\\
[# ɀ µ&|ù This .:/-_ ]\\
[text|./document.txt#anchor]\\
[#8be261a9de7ce958fe46548a62609aeb]\\

View File

@@ -0,0 +1,7 @@
|Header1<br>first one||Header3|
|---|---|---|
|Row 2 \\| Column <br>1|Row 2 \|\| Column 2|Row 2 \| \| Column 3|

View File

@@ -0,0 +1,113 @@
# Test title
## Section Level 1a
<a name="level-1a"></a>
## Section with anchor Level 1a
<a name="section-with-anchor-level-1a"></a>
## Section with anchor Level 1a
### Section Level 2a
<a name="level-2a"></a>
### Section with anchor Level 2a
<a name="section-with-anchor-level-2a"></a>
### Section with anchor Level 2a
#### Section Level 3a
<a name="level-3a"></a>
#### Section with anchor Level 3a
<a name="section-with-anchor-level-3a"></a>
#### Section with anchor Level 3a
##### Section Level 4a
<a name="level-4a"></a>
##### Section with anchor Level 4a
<a name="section-with-anchor-level-4a"></a>
##### Section with anchor Level 4a
###### Section Level 5a
<a name="level-5a"></a>
###### Section with anchor Level 5a
<a name="section-with-anchor-level-5a"></a>
###### Section with anchor Level 5a
Paragraph with long text bla bla bla bla bla
Line1
Line2
Line1
Line2
```
Source code listing
```
```java
MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)
```
Example
Example :
Example
Important :
Example
Caution :
```
Listing
```
Note :
```
Literal
```
Tip :
Sidebar
Warning :
Passthrough
***
|Header1||Header3|
|---|---|---|
|Row 1 \| Column 1|Row 1 \| Column 2|Row 1 \| Column 3|
|Row 2 \| Column 1|Row 2 \| Column 2|Row 2 \| Column 3|
## Section Level 1b
### Section Level 2b
text line
`Literal text line`
**Bold text line**
*Italic text line*
**bold***italic*regular
* Entry1
* Entry2
* Entry 2
<a name="anchor"></a>
<a name="simple-anchor"></a>
<a name="313af8b99da5a524603837deb119d273"></a>
[text](./document.md#anchor)
[ɀ µ&|ù This .:/-_](# ɀ µ&|ù This .:/-_ )
[text](./document.md#anchor)
[313af8b99da5a524603837deb119d273](#313af8b99da5a524603837deb119d273)

View File

@@ -0,0 +1,6 @@
```php
$o = new Thing();
```