Java源码示例:net.steppschuh.markdowngenerator.text.heading.Heading
示例1
private static void buildResult(BufferedWriter writer, List<ResultDes> result) throws IOException {
writer.newLine();
writer.newLine();
writer.write(new Heading("返回值", 4).toString());
if (result == null) {
writer.newLine();
writer.write("无返回值");
return;
}
Table.Builder tableBuilder = new Table.Builder()
.withAlignments(Table.ALIGN_LEFT, Table.ALIGN_CENTER, Table.ALIGN_LEFT)
.addRow("字段名", "字段类型", "参数描述");
buildResult(tableBuilder, result, 0);
writer.newLine();
writer.write(tableBuilder.build().toString());
}
示例2
private static void buildParam(BufferedWriter writer, List<ResultDes> parameters, boolean jsonrpc) throws IOException {
if(!jsonrpc) {
parameters.forEach(des -> {
if(des.formJsonOfRestful != null) {
try {
writer.newLine();
writer.write(new Heading("Form json data: ", 4).toString());
writer.newLine();
writer.newLine();
writer.write(new Text("```json").toString());
writer.newLine();
writer.write(new Text(des.formJsonOfRestful).toString());
writer.newLine();
writer.write(new Text("```").toString());
writer.newLine();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
writer.newLine();
writer.write(new Heading("参数列表", 4).toString());
if (parameters == null || parameters.isEmpty()) {
writer.newLine();
writer.write("无参数");
return;
}
Table.Builder tableBuilder = new Table.Builder()
.withAlignments(Table.ALIGN_LEFT, Table.ALIGN_CENTER, Table.ALIGN_LEFT, Table.ALIGN_CENTER)
.addRow("参数名", "参数类型", "参数描述", "是否必填");
buildParam(tableBuilder, parameters, 0, jsonrpc);
writer.newLine();
writer.write(tableBuilder.build().toString());
}
示例3
@Test
public void example2() throws Exception {
for (int level = Heading.MINIMUM_LEVEL; level <= Heading.MAXIMUM_LEVEL; level++) {
Text text = new Heading("I am a heading with level " + level, level);
System.out.println(text);
}
}
示例4
@Test
public void example3() throws Exception {
StringBuilder sb = new StringBuilder()
.append(new Heading("Heading with level 1", 1)).append(System.lineSeparator())
.append(new Heading("Heading with level 2", 2)).append(System.lineSeparator())
.append(new Heading("Heading with level 3", 3)).append(System.lineSeparator())
.append(new Heading("Heading with level 4", 4)).append(System.lineSeparator())
.append(new Heading("Heading with level 5", 5)).append(System.lineSeparator())
.append(new Heading("Heading with level 6", 6));
System.out.println(sb);
}
示例5
@Override
public String format(String sequenceNum, APIDoc apiDoc) {
StringBuilder apiContent=new StringBuilder();
String head;
if(apiDoc.getDesc()!=null&&apiDoc.getDesc().length()>0){
String desc=apiDoc.getDesc();
int spitStart= desc.indexOf(",");
if(spitStart>0){
desc=desc.substring(0,spitStart);
}
head=desc;
}else{
head=apiDoc.getMethod();
}
head=sequenceNum+"."+head;
Text h2=new Heading(head,2);
String pathLine=path+apiDoc.getPath();
String methodLine=method+apiDoc.getHttpMethod();
String descLine=description+(apiDoc.getDesc()!=null?apiDoc.getDesc():"无");
String paramLine=parameter+(apiDoc.getParams()==null?"无":"");
List<String> items = Arrays.asList(pathLine, methodLine, descLine,paramLine);
UnorderedList list = new UnorderedList<>(items);
apiContent.append(h2).append("\n");
apiContent.append(list).append("\n\n");
if(apiDoc.getParams()!=null&&apiDoc.getParams().size()>0) {
List<TableRow> rows = new ArrayList();
rows.add(new TableRow(Arrays.asList(
paramName,
paramType,
paramDesc
)));
for (Param p : apiDoc.getParams()) {
rows.add(new TableRow(Arrays.asList(
p.getName(),
p.getType(),
p.getComment()
)));
}
List<Integer> alignments = Arrays.asList(
Table.ALIGN_CENTER,
Table.ALIGN_CENTER,
Table.ALIGN_CENTER
);
Table table = new Table(rows, alignments);
apiContent.append(table);
}
apiContent.append("\n");
apiContent.append(example);
if(apiDoc.getiDemo()!=null) {
apiContent.append(request).append("\n");
apiContent.append(new CodeBlock(apiDoc.getiDemo()));
apiContent.append("\n");
}
if(apiDoc.getoDemo()!=null) {
apiContent.append(response).append("\n");
apiContent.append(new CodeBlock(apiDoc.getoDemo()));
}
apiContent.append("\n");
return apiContent.toString();
}
示例6
public static Heading heading(String value, int level) {
return new Heading(value, level);
}
示例7
public static Heading heading(String value) {
return heading(value, 1);
}
示例8
public static Heading subHeading(String value) {
return heading(value, 2);
}
示例9
@Test
public void example1() throws Exception {
Text text = new Heading("I am a heading");
System.out.println(text);
}
示例10
public String getMarkDown() {
try {
StringBuilder sb = new StringBuilder();
sb.append(new Heading("OPENID CONNECT CLIENTS DETAILS", 2)).append("\n");
List<Object> items = new ArrayList<Object>();
if (client.getDisplayName() != null && !client.getDisplayName().isEmpty()) {
items.add("**Name:** " + client.getDisplayName());
}
if (client.getDescription() != null && !client.getDescription().isEmpty()) {
items.add("**Description:** " + client.getDescription());
}
if (client.getInum() != null && !client.getInum().isEmpty()) {
items.add("**Client ID:** " + client.getInum());
}
if (client.getSubjectType() != null && !client.getSubjectType().name().isEmpty()) {
items.add("**Subject Type:** " + client.getSubjectType());
}
if (client.getExp() != null && !client.getExp().toString().isEmpty()) {
items.add("**Expirattion date:** " + client.getExp());
}
if (client.getOxAuthClientSecret() != null && !client.getOxAuthClientSecret().toString().isEmpty()) {
items.add("**ClientSecret:** XXXXXXXXXXX");
}
if (client.getClientUri() != null && !client.getClientUri().toString().isEmpty()) {
items.add("**Client Uri:** " + client.getClientUri());
}
if (client.getIdTokenTokenBindingCnf() != null
&& !client.getIdTokenTokenBindingCnf().toString().isEmpty()) {
items.add("**TokenTokenBindingCnf:** " + client.getIdTokenTokenBindingCnf());
}
if (client.getOxAuthAppType() != null) {
items.add("**Application Type:** " + client.getOxAuthAppType().getValue());
}
items.add("**Persist Client Authorizations:** " + client.getOxAuthPersistClientAuthorizations());
items.add("**Pre-Authorization:** " + client.getOxAuthTrustedClient());
items.add("**Authentication method for the Token Endpoint:** " + client.getTokenEndpointAuthMethod());
items.add("**Logout Session Required:** " + client.getLogoutSessionRequired());
items.add("**Include Claims In Id Token:** " + client.getOxIncludeClaimsInIdToken());
items.add("**Disabled:** " + client.isDisabled());
if (client.getLogoutUri() != null && !client.getLogoutUri().isEmpty()) {
items.add("**Logout Uri:** " + client.getLogoutUri().toString());
}
if (client.getOxAuthPostLogoutRedirectURIs() != null
&& !client.getOxAuthPostLogoutRedirectURIs().isEmpty()) {
items.add("**Logout Redirect URIs:** " + client.getOxAuthPostLogoutRedirectURIs().toString());
}
if (client.getOxAuthRedirectURIs() != null && !client.getOxAuthRedirectURIs().isEmpty()) {
items.add("**Login Redirect URIs:** " + client.getOxAuthRedirectURIs().toString());
}
if (client.getOxAuthClaims() != null && !client.getOxAuthClaims().isEmpty()) {
items.add("**Claims:** " + client.getOxAuthClaims().toString());
}
if (client.getAccessTokenSigningAlg() != null && !client.getAccessTokenSigningAlg().name().isEmpty()) {
items.add("**AccessTokenSigningAlg:** " + client.getAccessTokenSigningAlg().name().toString());
}
if (client.getOxAuthScopes() != null && !client.getOxAuthScopes().isEmpty()) {
List<String> scopes = new ArrayList<String>();
for (Scope scope : this.scopes) {
scopes.add(scope.getId());
}
items.add("**Scopes:** " + scopes.toString());
}
if (client.getGrantTypes() != null && client.getGrantTypes().length > 0) {
items.add("**Grant types:** " + this.grantTypes.toString());
}
if (client.getResponseTypes() != null && client.getResponseTypes().length > 0) {
items.add("**Response types:** " + this.responseTypes.toString());
}
if (client.getContacts() != null && !client.getContacts().toString().isEmpty()) {
items.add("**Contacts:** " + this.contacts.toString());
}
if (client.getDefaultAcrValues() != null && client.getDefaultAcrValues().length > 0) {
items.add("**DefaultAcrValues:** " + Arrays.asList(client.getDefaultAcrValues()).toString());
}
sb.append(new UnorderedList<Object>(items)).append("\n");
markDown = sb.toString();
} catch (Exception e) {
log.error("Error computing markdown", e);
}
return markDown;
}
示例11
/**
* Appends a {@link Heading} element to the root {@link MarkdownBuilder#markdownElement}.
*
* @param value value for the new element
* @param level the heading level
* @return the builder instance
* @see Heading#Heading(Object, int)
*/
public T heading(String value, int level) {
newParagraphIfRequired();
append(new Heading(value, level));
return newParagraph();
}