You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "tballison (via GitHub)" <gi...@apache.org> on 2026/10/10 13:03:16 UTC

[PR] TIKA-4996: apply font formatting styles in docx [tika]

tballison opened a new pull request, #3316:
URL: https://github.com/apache/tika/pull/3316

   <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you 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.
   -->
   
   Thanks for your contribution to [Apache Tika](https://tika.apache.org/)! Your help is appreciated!
   
   Before opening the pull request, please verify that
   * there is an open issue on the [Tika issue tracker](https://issues.apache.org/jira/projects/TIKA) which describes the problem or the improvement. We cannot accept pull requests without an issue because the change wouldn't be listed in the release notes.
   * the issue ID (`TIKA-XXXX`)
     - is referenced in the title of the pull request
     - and placed in front of your commit messages surrounded by square brackets (`[TIKA-XXXX] Issue or pull request title`)
   * commits are squashed into a single one (or few commits for larger changes)
   * Tika builds and unit tests pass with `./mvnw clean install` (`clean test` alone cannot resolve the pipes plugin zips)
   * if you used a generative AI tool: follow the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) (`Generated-by: <tool>` in the commit message), and consider running the pre-flight in `.skills/devs/pr-review/SKILL.md` — fix what it finds; don't paste its report here
   * there should be no conflicts when merging the pull request branch into the *recent* `main` branch. If there are conflicts, please try to rebase the pull request branch on top of a freshly pulled `main` branch
   * if you add new module that downstream users will depend upon add it to relevant group in `tika-bom/pom.xml`.
   
   We will be able to faster integrate your pull request if these conditions are met. If you have any questions how to fix your problem or about using Tika in general, please sign up for the [Tika mailing list](http://tika.apache.org/mail-lists.html). Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] TIKA-4996: apply font formatting styles in docx [tika]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3316:
URL: https://github.com/apache/tika/pull/3316#discussion_r4238337625


##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/WordExtractor.java:
##########
@@ -170,14 +173,27 @@ public static TagAndStyle buildParagraphTagAndStyle(String styleName, boolean is
             // Turn it into a H1 - H6 (H7+ isn't valid!)
             tag = "h" + Math.min(num, 6);
         } else {
-            styleClass = styleName.replace(' ', '_');
-            styleClass =
-                    styleClass.substring(0, 1).toLowerCase(Locale.ROOT) + styleClass.substring(1);
+            styleClass = toStyleClass(styleName);
         }
 
         return new TagAndStyle(tag, styleClass);
     }
 
+    /**
+     * @return the XHTML class for a style name, e.g. "List Bullet" -&gt; "list_Bullet",
+     * or null for an empty name. Anything but letters, digits, '_' and '-' becomes '_',
+     * so a style name can never yield more than one class token.
+     */
+    public static String toStyleClass(String styleName) {
+        if (styleName == null || styleName.isEmpty()) {
+            return null;
+        }
+        String styleClass = styleName.length() > MAX_STYLE_CLASS_LENGTH
+                ? styleName.substring(0, MAX_STYLE_CLASS_LENGTH) : styleName;
+        styleClass = NON_STYLE_CLASS_CHARS.matcher(styleClass).replaceAll("_");
+        return styleClass.substring(0, 1).toLowerCase(Locale.ROOT) + styleClass.substring(1);

Review Comment:
   Sanitization happens before lowercasing, but Unicode lowercasing can expand a permitted letter (for example, `İ` becomes `i` plus a combining mark). That reintroduces a disallowed character and can make a 128-character result 129 characters long, contradicting both this method's contract and the release note. Lowercase the first code point before sanitizing and applying a code-point-safe length cap.



##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/ooxml/xwpf/XWPFStylesShim.java:
##########
@@ -72,7 +75,45 @@ public String getStyleName(String styleId) {
         if (styleId == null) {
             return null;
         }
-        return styles.get(styleId);
+        StyleInfo info = styles.get(styleId);
+        return info == null ? null : info.name;
+    }
+
+    /**
+     * @return whether the style, or the nearest style it is based on that says
+     * either way, sets bold; false if none does
+     */
+    public boolean isBold(String styleId) {
+        StyleInfo info = styles.get(styleId);
+        for (int i = 0; info != null && i < MAX_BASED_ON_DEPTH; i++) {
+            if (info.bold != null) {
+                return info.bold;

Review Comment:
   OOXML run-style bold is a toggle property, not a nearest-value override. A derived style containing `<w:b/>` must invert inherited bold, while `<w:b w:val="false"/>` leaves the inherited state unchanged; this method returns the opposite result in both cases. Resolve the chain by accumulating true toggles (and ignoring false values), and update the fixture expectations accordingly.
   
   This issue also appears on line 104 of the same file.



##########
CHANGES.txt:
##########
@@ -1,5 +1,13 @@
 Release 4.2.0 - unreleased
 
+   * The docx parser now applies bold and italics set by a run's character style
+     (e.g. Word's built-in Strong and Emphasis), following basedOn chains; previously
+     only direct formatting was emitted. The new OfficeParserConfig option
+     includeCharacterStyleClasses wraps such runs in <span class="..."> named after
+     the style. Style-derived classes (paragraph and character) now replace every
+     character other than letters, digits, '_' and '-' with '_' and are capped at 128
+     characters, so a style name can no longer yield extra class tokens (TIKA-4966).

Review Comment:
   This entry references TIKA-4966, but the pull request and feature are tracked as TIKA-4996. Using the wrong issue ID prevents the release note from linking this change to its actual ticket.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] TIKA-4966: apply font formatting styles in docx [tika]

Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison merged PR #3316:
URL: https://github.com/apache/tika/pull/3316


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org