Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions aesh/src/main/java/org/aesh/command/man/parser/ManFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,42 @@ else if (line.isEmpty() && foundEmptyLine) {
}

private void processHeader(List<String> header, int columns) throws IOException {
if (header.size() != 4)
throw new IOException("File did not include the correct header.");
name = header.get(0);
if (!header.get(2).equals(":doctype: manpage"))
boolean foundTitle = false;
boolean foundDoctype = false;

// Process header lines to find title and doctype
for (int i = 0; i < header.size(); i++) {
String line = header.get(i);
String trimmed = line.trim();

// Extract title from = progname(volume) format
if (trimmed.startsWith("=") && !trimmed.startsWith("==")) {
name = trimmed.substring(1).trim();
foundTitle = true;
}
// Extract title from underline format (title\n====)
else if (!foundTitle && i + 1 < header.size() &&
header.get(i + 1).trim().matches("^=+$") &&
header.get(i + 1).trim().length() == trimmed.length()) {
name = trimmed;
foundTitle = true;
}
// Check for doctype attribute
else if (trimmed.equals(":doctype: manpage")) {
foundDoctype = true;
}
// Reject wrong doctype
else if (trimmed.startsWith(":doctype:") && !trimmed.equals(":doctype: manpage")) {
throw new IOException("File did not include the correct header: \":doctype: manpage\". Found: " + trimmed);
}
}

if (!foundTitle) {
throw new IOException("File did not include a valid title in format: = progname(volume) or title with underline");
}
if (!foundDoctype) {
throw new IOException("File did not include the correct header: \":doctype: manpage\"");
}
}

public List<ManSection> getSections() {
Expand Down
28 changes: 19 additions & 9 deletions aesh/src/main/java/org/aesh/command/man/parser/ManSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,28 @@ public ManSection parseSection(List<String> input, int columns) {
//we ignore the links atm
if (input.get(0).startsWith("[["))
input.remove(0);
//first line should be the name
name = input.get(0);
input.remove(0);
//the first section, ignoring it for now
//starting a new section
if (input.get(0).startsWith("-") &&
input.get(0).trim().length() == name.length()) {

//check for == Section syntax (standard asciidoctor format)
if (input.get(0).startsWith("== ")) {
name = input.get(0).substring(3).trim();
input.remove(0);
}
//check for underline format (legacy format)
else {
//first line should be the name
name = input.get(0);
input.remove(0);
//check if next line is the underline
if (!input.isEmpty() && input.get(0).startsWith("-") &&
input.get(0).trim().length() == name.length()) {
input.remove(0);
}
}

//parse parameters if this is an OPTIONS-style section
if (!input.isEmpty()) {
//a new param
List<String> newOption = new ArrayList<String>();
boolean startingNewOption = false;
boolean paramName = false;
for (String in : input) {
if (in.trim().length() > 0)
newOption.add(in);
Expand Down
Loading
Loading