in html-convert/src/main/java/org/netbeans/tools/tutorials/AsciidocPostProcessor.java [73:124]
private static void cleanUpAndGetTitle(File file, HashMap<File, String> titles) throws IOException {
File temporaryFile = new File(file.getParentFile(), file.getName() + ".tmp");
ContentSectionState state = ContentSectionState.BEFORE_CONTENT_SECTION;
String title = null;
try (BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(temporaryFile), StandardCharsets.UTF_8))) {
do {
String line = input.readLine();
if (line == null) {
break;
}
if (title == null) {
Matcher m = TITLE_PATTERN.matcher(line);
if (m.matches()) {
title = m.group(1);
}
}
switch (state) {
case BEFORE_CONTENT_SECTION:
if (isContentsHeader(line)) {
state = ContentSectionState.INSIDE_CONTENT_SECTION;
break;
}
output.println(line);
break;
case INSIDE_CONTENT_SECTION:
if (line.startsWith("* <")
|| line.startsWith("* link:")) {
// Ignore bullet lists with cross references or external links
} else {
output.println(line);
}
if (line.startsWith("=")) {
state = ContentSectionState.AFTER_CONTENT_SECTION;
}
break;
case AFTER_CONTENT_SECTION:
output.println(line);
break;
}
} while (true);
}
Files.move(temporaryFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
if (title != null) {
titles.put(file, title);
}
}