From d3cf2ff5a4565e65bf1eb850e88880f0897bcb25 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 21 Nov 2024 07:43:13 +0900 Subject: [PATCH 1/2] fix: passing filter context Signed-off-by: Hiroshi Miura --- src/org/omegat/filters2/hhc/HHCFilter2.java | 2 +- src/org/omegat/filters2/hhc/HHCFilterVisitor.java | 6 ++++-- src/org/omegat/filters2/html2/FilterVisitor.java | 9 ++++++--- src/org/omegat/filters2/html2/HTMLFilter2.java | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/org/omegat/filters2/hhc/HHCFilter2.java b/src/org/omegat/filters2/hhc/HHCFilter2.java index 69f6a24f7f..47bc2cd20f 100644 --- a/src/org/omegat/filters2/hhc/HHCFilter2.java +++ b/src/org/omegat/filters2/hhc/HHCFilter2.java @@ -85,7 +85,7 @@ public void processFile(BufferedReader infile, BufferedWriter outfile, FilterCon Parser parser = new Parser(); try { parser.setInputHTML(all.toString()); - parser.visitAllNodesWith(new HHCFilterVisitor(this, outfile)); + parser.visitAllNodesWith(new HHCFilterVisitor(this, outfile, fc)); } catch (ParserException pe) { System.out.println(pe); } diff --git a/src/org/omegat/filters2/hhc/HHCFilterVisitor.java b/src/org/omegat/filters2/hhc/HHCFilterVisitor.java index 47ffdad7c2..086df51b82 100644 --- a/src/org/omegat/filters2/hhc/HHCFilterVisitor.java +++ b/src/org/omegat/filters2/hhc/HHCFilterVisitor.java @@ -29,6 +29,8 @@ import java.io.BufferedWriter; import org.htmlparser.Tag; + +import org.omegat.filters2.FilterContext; import org.omegat.filters2.html2.FilterVisitor; import org.omegat.util.HTMLUtils; @@ -40,8 +42,8 @@ * @author Didier Briel */ class HHCFilterVisitor extends FilterVisitor { - HHCFilterVisitor(HHCFilter2 hhcfilter, BufferedWriter bufwriter) { - super(hhcfilter, bufwriter, null); + HHCFilterVisitor(HHCFilter2 hhcfilter, BufferedWriter bufwriter, FilterContext fc) { + super(hhcfilter, bufwriter, null, fc); } // /////////////////////////////////////////////////////////////////////// diff --git a/src/org/omegat/filters2/html2/FilterVisitor.java b/src/org/omegat/filters2/html2/FilterVisitor.java index 05cc6fefa3..832eefd634 100644 --- a/src/org/omegat/filters2/html2/FilterVisitor.java +++ b/src/org/omegat/filters2/html2/FilterVisitor.java @@ -48,6 +48,7 @@ import org.htmlparser.nodes.TextNode; import org.htmlparser.visitors.NodeVisitor; import org.omegat.core.Core; +import org.omegat.filters2.FilterContext; import org.omegat.util.HTMLUtils; import org.omegat.util.Log; import org.omegat.util.OStrings; @@ -67,8 +68,10 @@ public class FilterVisitor extends NodeVisitor { protected HTMLFilter2 filter; private BufferedWriter writer; private HTMLOptions options; + private FilterContext filterContext; - public FilterVisitor(HTMLFilter2 htmlfilter, BufferedWriter bufwriter, HTMLOptions opts) { + public FilterVisitor(HTMLFilter2 htmlfilter, BufferedWriter bufwriter, HTMLOptions opts, + FilterContext fc) { this.filter = htmlfilter; // HHC filter has no options if (opts != null) { @@ -79,6 +82,7 @@ public FilterVisitor(HTMLFilter2 htmlfilter, BufferedWriter bufwriter, HTMLOptio this.options = new HTMLOptions(new TreeMap<>()); } this.writer = bufwriter; + filterContext = fc; } // /////////////////////////////////////////////////////////////////////// @@ -540,8 +544,7 @@ protected void endup() { boolean changed = true; while (changed) { changed = false; - boolean removeTags = Core.getFilterMaster().getConfig().isRemoveTags(); - if (!removeTags) { + if (!filterContext.isRemoveAllTags()) { for (int i = 0; i < firstTagToIncludeFromPreceding; i++) { Node node = allNodesInParagraph.get(i); if (node instanceof Tag) { diff --git a/src/org/omegat/filters2/html2/HTMLFilter2.java b/src/org/omegat/filters2/html2/HTMLFilter2.java index 2f802d6907..9af1d36274 100644 --- a/src/org/omegat/filters2/html2/HTMLFilter2.java +++ b/src/org/omegat/filters2/html2/HTMLFilter2.java @@ -200,7 +200,7 @@ public void processFile(BufferedReader infile, BufferedWriter outfile, Parser parser = new Parser(); try { parser.setInputHTML(all.toString()); - parser.visitAllNodesWith(new FilterVisitor(this, outfile, options)); + parser.visitAllNodesWith(new FilterVisitor(this, outfile, options, fc)); } catch (ParserException pe) { Log.logErrorRB(pe, "HTML_EXCEPTION_PARSER"); } catch (StringIndexOutOfBoundsException se) { From 8cb7a9a1992cca51ab089a27df786a77e4822b04 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 21 Nov 2024 09:49:58 +0900 Subject: [PATCH 2/2] fix: revert removeTags detection change Signed-off-by: Hiroshi Miura --- src/org/omegat/filters2/html2/FilterVisitor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/omegat/filters2/html2/FilterVisitor.java b/src/org/omegat/filters2/html2/FilterVisitor.java index 832eefd634..c04e399b36 100644 --- a/src/org/omegat/filters2/html2/FilterVisitor.java +++ b/src/org/omegat/filters2/html2/FilterVisitor.java @@ -544,7 +544,8 @@ protected void endup() { boolean changed = true; while (changed) { changed = false; - if (!filterContext.isRemoveAllTags()) { + boolean removeTags = Core.getFilterMaster().getConfig().isRemoveTags(); + if (!removeTags) { for (int i = 0; i < firstTagToIncludeFromPreceding; i++) { Node node = allNodesInParagraph.get(i); if (node instanceof Tag) {