Code Monkey home page Code Monkey logo

markup-document-builder's Introduction

MarkupDocBuilder

Build Status Coverage Status Codacy code quality download Apache License 2 Twitter

Overview

This project is a Markup document builder (AsciiDoc, Markdown and ConfluenceWiki). The primary goal of this project is to simplify the creation of Markup documents. The builder is used by swagger2markup.

The project requires at least JDK 7.

Usage

Adding MarkupDocBuilder to your project

The project is published in JCenter and Maven Central.

Maven

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>
<dependency>
    <groupId>io.github.swagger2markup</groupId>
    <artifactId>markup-document-builder</artifactId>
    <version>1.1.1</version>
</dependency>

Gradle

repositories {
    jcenter()
}

compile "io.github.swagger2markup:markup-document-builder:1.1.1"

Using MarkupDocBuilder

The MarkupDocBuilder allows to build an AsciiDoc or Markdown document via the Builder pattern.

public class MarkupDocBuilderTest {

    List<String> tableRowsInPSV;

    @Before
    public void setUp(){
        tableRowsInPSV = new ArrayList<>();
        tableRowsInPSV.add("Header 1 | Header 2 | Header2");
        tableRowsInPSV.add("Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3");
        tableRowsInPSV.add("Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3");
    }


    @Test
    public void testToAsciiDocFile() throws IOException {
        MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC);
        builder.documentTitle("Test title")
                .sectionTitleLevel1("Section Level 1a")
                .sectionTitleLevel2("Section Level 2a")
                .sectionTitleLevel3("Section Level 3a")
                .paragraph("Paragraph with long text bla bla bla bla bla")
                .listing("Source code listing")
                .source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
                .tableWithHeaderRow(tableRowsInPSV)
                .sectionTitleLevel1("Section Level 1b")
                .sectionTitleLevel2("Section Level 2b")
                .boldTextLine("Bold text line b")
                .italicTextLine("Italic text line b")
                .unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
                .writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
    }

    @Test
     public void testToMarkdownDocFile() throws IOException {
        MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN);
        builder.documentTitle("Test title")
                .sectionTitleLevel1("Section Level 1a")
                .sectionTitleLevel2("Section Level 2a")
                .sectionTitleLevel3("Section Level 3a")
                .paragraph("Paragraph with long text bla bla bla bla bla")
                .listing("Source code listing")
                .source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
                .tableWithHeaderRow(tableRowsInPSV)
                .sectionTitleLevel1("Section Level 1b")
                .sectionTitleLevel2("Section Level 2b")
                .boldTextLine("Bold text line b")
                .italicTextLine("Italic text line b")
                .unorderedList(Arrays.asList("Entry1", "Entry2", "Entry 2"))
                .writeToFile("build/tmp", "test", StandardCharsets.UTF_8);
    }

}

Generated HTML using AsciidoctorJ

You can generate your PDF or HTML documentation via asciidoctorj or even better via the asciidoctor-gradle-plugin or markdown-gradle-plugin.

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.

markup-document-builder's People

Contributors

2bad4u avatar austek avatar bujo avatar cascer1 avatar johanhammar avatar kabhal avatar robwin avatar sjonnalagadda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

markup-document-builder's Issues

Not able to generate asciidoc with custom pojo

Hi I am trying to create a pdf document for my API's using 'swagger2markup-maven-plugin' and 'asciidoctor-maven-plugin'. I am getting following error "Failed to execute goal 'convertSwagger2markup': text must not be blank" . It fails when trying to validate boldTextLine text. Here is how my api documentation looks like

@ApiOperation(value = “Fetch User details.”,
 notes = "Return user details as a key-value pair.",
 response = User.class,
 httpMethod = "GET"
)
 @RequestMapping(value=“/users/{id}”, method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public User<String, Object> fetchDetails(@PathVariable final String id,
 final HttpServletRequest request, final HttpServletResponse response){ 
 return new User<>();
 }

Incorrect dependency example 1.0.0 in readme

The readme contains:

<dependency>
    <groupId>io.github.robwin</groupId>
    <artifactId>markup-document-builder</artifactId>
    <version>1.0.0</version>
</dependency>

this version does not exist in maven central. Perhaps it is useful to update the readme to:

    <dependency>
        <groupId>io.github.swagger2markup</groupId>
        <artifactId>markup-document-builder</artifactId>
        <version>1.1.1</version>
    </dependency>

Too bad the nl.jworks.markdown_to_asciidoc dependency is not in maven central.
Swagger2Markup/swagger2markup-maven-plugin#25

Splitting the descriptions

Hi Robert,

In addition to the definitions.adoc that gets generated, I would like to generate individual files for each object (ex: person.adoc, address.adoc, purchase.adoc...). I'd like to reference the model from a separate document that I've written, but I would like to include the object definitions individually in specific sections rather than in a single section. Do you think this would be something useful? I haven't dived into the code yet, but I'd be willing to take a stab at it. Do you think it would be something horribly difficult as the design stands, and would it be something possibly useful to others?

Thanks!

Sebastien

Allow usage of additional markup builders

Hi,
Due to factory using a concrete enum as input it is not possible to add builders for additional markup-languages without modifiying your code. I'd like to use your tool to generate output for Confluence/Jira and it would be really cool to have a simple plugin mechanism.

I've sketched a possible solution (which should not break your existing interface) in 7e0d5bc, what do you think?

Regards
André

Refactor anchor and cross-reference interface and implementation

Context :

  • Many limitations on supported characters in MD and ADOC anchors, and HTML generated ids.
  • Different normalization rules when cross-referencing titles over custom anchors
  • We should always cross-reference a stable id instead of a moving title
  • Partial AsciiDoctor support for title cross-referencing (does not work with inter-document cross-references)

Solution :

  • We decide to genericize the anchor/sections/cross-references system in markup-document-builder to a LCD character set for anchors (narrower than the AsciiDoc|Markdown specification).
  • No more distinct crossReferenceTitle() : only crossReference and crossReferenceRaw (no filtering, you put what you want in anchor if you know what you do)
  • Each section generated with the tool will have an explicit id with anchor = normalized(title)
  • All anchors are normalized this way :
- current <- trim()
- input <- current
- current <- Normalizer.normalize(Normalizer.Form.NFD)
- current <- replaceAll("\\p{Punct}+", "")
- current <- lowercase()
- current <- replaceAll("\\s+", ADOC("_") | MD("-") )
- base <- current
- current <- replaceAll("[^a-z0-9-_]+", "")
if (current.size() != base.size())
  - current <- hash(input) // use input to maximize uniqueness
end

if (ADOC)
  - current <- prefix with "_"
  - current <- suffix with "_" if endsWith("-") 
end

Notes

When a section has an explicit custom anchor, AsciiDoctor reuse it as-is for HTML id generation.

Anchors rules for documentation purpose

Markdown

Sections :

  • trim
  • supports UTF-8
  • only lower cases
  • no spaces (replaced with - )
  • supported punctuation : [-] ... to be continued

Manual anchors :

  • <=> HTML ids

AsciiDoc

Sections :

  • no limitations

Manual anchors :

  • trim
  • support upper cases
  • no UTF-8
  • no space (replaced with _ )
  • can't start with a digit
  • can't end with '-' ( <> : parse error)
  • supported punctuation : [:-_.] ... to be continued
  • ...

HTML

HTML 4
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters (UTF-8), digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

HTML 5 :
The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.
An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragment identifiers, as a way to target an element when scripting, and as a way to style a specific element from CSS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.