Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: link converting table columns width to 'auto' with 'Fit to page' property #123

Merged
merged 2 commits into from
Aug 6, 2024
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
22 changes: 11 additions & 11 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,10 @@
"swaggerUiUrl" : {
"type" : "string"
},
"baseUrl" : {
"restUrl" : {
"type" : "string"
},
"restUrl" : {
"baseUrl" : {
"type" : "string"
}
}
Expand Down Expand Up @@ -1296,10 +1296,10 @@
"type" : "string"
}
},
"wildcardSubtype" : {
"wildcardType" : {
"type" : "boolean"
},
"wildcardType" : {
"wildcardSubtype" : {
"type" : "boolean"
}
}
Expand Down Expand Up @@ -1390,10 +1390,10 @@
"type" : "string"
}
},
"wildcardSubtype" : {
"wildcardType" : {
"type" : "boolean"
},
"wildcardType" : {
"wildcardSubtype" : {
"type" : "boolean"
}
}
Expand All @@ -1413,12 +1413,12 @@
"value" : {
"type" : "string"
},
"simple" : {
"type" : "boolean"
},
"formDataContentDisposition" : {
"$ref" : "#/components/schemas/FormDataContentDisposition"
},
"simple" : {
"type" : "boolean"
},
"parameterizedHeaders" : {
"type" : "object",
"additionalProperties" : {
Expand Down Expand Up @@ -1502,10 +1502,10 @@
"type" : "string"
}
},
"wildcardSubtype" : {
"wildcardType" : {
"type" : "boolean"
},
"wildcardType" : {
"wildcardSubtype" : {
"type" : "boolean"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams expo
html = cutEmptyChapters(html);
}

html = adjustCellWidth(html);
html = adjustCellWidth(html, exportParams);
html = html.replace(">\n ", "> ");
html = html.replace("\n</", "</");
if (exportParams.getChapters() != null) {
Expand Down Expand Up @@ -557,12 +557,14 @@ String properTableHeads(@NotNull String html) {
@NotNull
@VisibleForTesting
@SuppressWarnings("java:S5852") //regex checked
String adjustCellWidth(@NotNull String html) {
// This regexp searches for <td> or <th> elements of regular tables which width in styles specified in pixels ("px").
// <td> or <th> element till "width:" in styles matched into first unnamed group and width value - into second unnamed group.
// Then we replace matched content by first group content plus "auto" instead of value in pixels.
html = RegexMatcher.get("(<t[dh].+?width:.*?)(\\d+px)")
.replace(html, regexEngine -> regexEngine.group(1) + "auto");
String adjustCellWidth(@NotNull String html, @NotNull ExportParams exportParams) {
if (exportParams.isFitToPage()) {
// This regexp searches for <td> or <th> elements of regular tables which width in styles specified in pixels ("px").
// <td> or <th> element till "width:" in styles matched into first unnamed group and width value - into second unnamed group.
// Then we replace matched content by first group content plus "auto" instead of value in pixels.
html = RegexMatcher.get("(<t[dh].+?width:.*?)(\\d+px)")
.replace(html, regexEngine -> regexEngine.group(1) + "auto");
}

// Next step we look for tables which represent WorkItem attributes and force them to take 100% of available width
html = RegexMatcher.get("(class=\"polarion-dle-workitem-fields-end-table\")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void adjustCellWidthTest() {
String invalidHtml = new String(isInvalidHtml.readAllBytes(), StandardCharsets.UTF_8);

// Spaces and new lines are removed to exclude difference in space characters
String fixedHtml = processor.adjustCellWidth(invalidHtml);
String fixedHtml = processor.adjustCellWidth(invalidHtml, new ExportParams());
String validHtml = new String(isValidHtml.readAllBytes(), StandardCharsets.UTF_8);
assertEquals(TestStringUtils.removeNonsensicalSymbols(validHtml), TestStringUtils.removeNonsensicalSymbols(fixedHtml));
}
Expand Down Expand Up @@ -348,9 +348,9 @@ void processHtmlForPDFTestCutEmptyWorkItemAttributesDisabled() {
String html = new String(isHtml.readAllBytes(), StandardCharsets.UTF_8);

HtmlProcessor spyHtmlProcessor = spy(processor);
// to avoid changing input html and check with regular equals
when(spyHtmlProcessor.adjustCellWidth(html)).thenReturn(html);
ExportParams exportParams = getExportParams();
// to avoid changing input html and check with regular equals
when(spyHtmlProcessor.adjustCellWidth(html, exportParams)).thenReturn(html);
exportParams.setCutEmptyChapters(false);

// Spaces, new lines & nbsp symbols are removed to exclude difference in space characters
Expand Down
Loading