forked from wildfly-extras/adoc-maven-plugin-descriptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wildfly-extras#1] Support more formatting options for the generated …
…asciidoc.
- Loading branch information
Showing
13 changed files
with
672 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/main/java/org/wildfly/tool/plugin/formatter/AbstractNodeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2016-2020 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.tool.plugin.formatter; | ||
|
||
import org.jsoup.nodes.Node; | ||
import org.jsoup.nodes.TextNode; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
abstract class AbstractNodeVisitor implements AppendableNodeVisitor { | ||
private final StringBuilder builder; | ||
|
||
AbstractNodeVisitor(final StringBuilder builder) { | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public AbstractNodeVisitor append(final CharSequence csq) { | ||
builder.append(csq); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AbstractNodeVisitor append(final CharSequence csq, final int start, final int end) { | ||
builder.append(csq, start, end); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AbstractNodeVisitor append(final char c) { | ||
builder.append(c); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AppendableNodeVisitor appendNewLine() { | ||
builder.append(System.lineSeparator()); | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return builder.toString(); | ||
} | ||
|
||
/** | ||
* Gets the possible text for a node. If the node is not a {@link TextNode} and empty string is returned. | ||
* | ||
* @param node the node to get the text from | ||
* | ||
* @return the text for the node or an empty string | ||
*/ | ||
String getText(final Node node) { | ||
if (node instanceof TextNode) { | ||
final TextNode textNode = (TextNode) node; | ||
return textNode.getWholeText(); | ||
} | ||
return ""; | ||
} | ||
|
||
/** | ||
* Gets the possible text for the first child node. If the child node is not a {@link TextNode} and empty string is | ||
* returned. | ||
* | ||
* @param node the node to get the first child from | ||
* | ||
* @return the text for the first child node or an empty string | ||
*/ | ||
String getChildText(final Node node) { | ||
if (node.childNodeSize() > 0) { | ||
return getText(node.childNode(0)); | ||
} | ||
return ""; | ||
} | ||
|
||
/** | ||
* Checks the node name against the names and returns {@code true} if one of the names matches the nodes name. | ||
* | ||
* @param node the node to check | ||
* @param names the names that may match | ||
* | ||
* @return {@code true} if the node name matches one of the names, otherwise {@code false} | ||
*/ | ||
boolean nodeNameMatches(final Node node, final String... names) { | ||
final String nodeName = node.nodeName(); | ||
for (String name : names) { | ||
if (name.equals(nodeName)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/wildfly/tool/plugin/formatter/AppendableNodeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2016-2020 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.tool.plugin.formatter; | ||
|
||
import org.jsoup.nodes.Node; | ||
import org.jsoup.select.NodeVisitor; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
interface AppendableNodeVisitor extends Appendable, NodeVisitor { | ||
|
||
|
||
@Override | ||
AppendableNodeVisitor append(CharSequence csq); | ||
|
||
@Override | ||
AppendableNodeVisitor append(CharSequence csq, int start, int end); | ||
|
||
@Override | ||
AppendableNodeVisitor append(char c); | ||
|
||
/** | ||
* Appends the platforms {@linkplain System#lineSeparator() line separator}. | ||
* | ||
* @return this appender | ||
*/ | ||
AppendableNodeVisitor appendNewLine(); | ||
|
||
/** | ||
* Indicates whether or not this visitor can process the node. | ||
* | ||
* @param node the node to check | ||
* | ||
* @return {@code true} if this visitor can process the node, otherwise {@code null} | ||
*/ | ||
boolean canProcess(Node node); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/wildfly/tool/plugin/formatter/BoldNodeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016-2020 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.tool.plugin.formatter; | ||
|
||
import org.jsoup.nodes.Node; | ||
import org.jsoup.select.NodeVisitor; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
class BoldNodeVisitor extends AbstractNodeVisitor implements NodeVisitor { | ||
|
||
BoldNodeVisitor(final StringBuilder builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public void head(final Node node, final int depth) { | ||
append('*'); | ||
} | ||
|
||
@Override | ||
public void tail(final Node node, final int depth) { | ||
append("* "); | ||
} | ||
|
||
@Override | ||
public boolean canProcess(final Node node) { | ||
return nodeNameMatches(node, "b", "strong"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/wildfly/tool/plugin/formatter/BreakNodeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016-2020 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* 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 org.wildfly.tool.plugin.formatter; | ||
|
||
import org.jsoup.nodes.Node; | ||
import org.jsoup.select.NodeVisitor; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
class BreakNodeVisitor extends AbstractNodeVisitor implements NodeVisitor { | ||
|
||
BreakNodeVisitor(final StringBuilder builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public void head(final Node node, final int depth) { | ||
append(" +"); | ||
} | ||
|
||
@Override | ||
public void tail(final Node node, final int depth) { | ||
appendNewLine(); | ||
} | ||
|
||
@Override | ||
public boolean canProcess(final Node node) { | ||
return nodeNameMatches(node, "br"); | ||
} | ||
} |
Oops, something went wrong.