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
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ static List<String> extractTable_new(JsonNode contentItem) {
String cellText = extractCellContent(cellNode);

// rowspan과 colspan 값 가져오기 (기본값 1)
int rowspan = cellNode.has("rowspan") ? cellNode.path("rowspan").asInt(1) : 1;
int colspan = cellNode.has("colspan") ? cellNode.path("colspan").asInt(1) : 1;
int rowspan = resolveSpanValue(cellNode, "rowspan", "rowSpan");
int colspan = resolveSpanValue(cellNode, "colspan", "colSpan");

// colspan 범위 확인
if (colIndex + colspan > columnCount) {
Expand Down Expand Up @@ -286,4 +286,14 @@ static String joinNonBlank(List<String> partsList, String separator) {
}
return result;
}

private static int resolveSpanValue(JsonNode cellNode, String lowerKey, String camelKey) {
if (cellNode.has(lowerKey)) {
return Math.max(1, cellNode.path(lowerKey).asInt(1));
}
if (cellNode.has(camelKey)) {
return Math.max(1, cellNode.path(camelKey).asInt(1));
}
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ void extractPlainText_fromContentArray() {
"{\"type\":\"image\",\"caption\":\"cap\"}," +
"{\"type\":\"table\",\"columns\":[{\"width\":100},{\"width\":200}]," +
"\"rows\":[" +
"[{\"content\":[{\"type\":\"text\",\"value\":\"1\"}],\"rowSpan\":1,\"colSpan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"2\"}],\"rowSpan\":1,\"colSpan\":1}]," +
"[{\"content\":[{\"type\":\"text\",\"value\":\"3\"}],\"rowSpan\":1,\"colSpan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"4\"}],\"rowSpan\":1,\"colSpan\":1}]" +
"[{\"content\":[{\"type\":\"text\",\"value\":\"1\"}],\"rowspan\":1,\"colspan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"2\"}],\"rowspan\":1,\"colspan\":1}]," +
"[{\"content\":[{\"type\":\"text\",\"value\":\"3\"}],\"rowspan\":1,\"colspan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"4\"}],\"rowspan\":1,\"colspan\":1}]" +
"]" +
"}" +
"]}";
Expand Down Expand Up @@ -67,5 +67,48 @@ void extractPlainText_imageWithoutCaption() {
void extractPlainText_invalidJson_throws() {
assertThrows(IllegalArgumentException.class, () -> PlainTextExtractUtils.extractPlainText(mapper, "not-json"));
}
}

@Test
@DisplayName("테이블 셀에서 rowspan/colspan (lowercase) 지원")
void extractPlainText_tableWithLowercaseSpans() {
String json = "{" +
"\"content\":[" +
"{\"type\":\"table\",\"columns\":[{\"width\":100},{\"width\":200}]," +
"\"rows\":[" +
"[{\"content\":[{\"type\":\"text\",\"value\":\"A\"}],\"rowspan\":2,\"colspan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"B\"}],\"rowspan\":1,\"colspan\":1}]," +
"[]" +
"]" +
"}" +
"]}";

String result = PlainTextExtractUtils.extractPlainText(mapper, json);

assertThat(result).isEqualTo(String.join("\n",
"[2 columns]",
"[\"A\", \"B\"]",
"[\"\", \"\"]"));
}

@Test
@DisplayName("테이블 셀에서 rowSpan/colSpan (camelCase) 지원")
void extractPlainText_tableWithCamelCaseSpans() {
String json = "{" +
"\"content\":[" +
"{\"type\":\"table\",\"columns\":[{\"width\":100},{\"width\":200}]," +
"\"rows\":[" +
"[{\"content\":[{\"type\":\"text\",\"value\":\"X\"}],\"rowSpan\":2,\"colSpan\":1}," +
"{\"content\":[{\"type\":\"text\",\"value\":\"Y\"}],\"rowSpan\":1,\"colSpan\":1}]," +
"[{\"content\":[{\"type\":\"text\",\"value\":\"C\"}],\"rowSpan\":1,\"colSpan\":1}]" +
"]" +
"}" +
"]}";

String result = PlainTextExtractUtils.extractPlainText(mapper, json);

assertThat(result).isEqualTo(String.join("\n",
"[2 columns]",
"[\"X\", \"Y\"]",
"[\"\", \"C\"]"));
}
}
Loading
Loading