Skip to content

Commit

Permalink
fix: passing filter context (#1195)
Browse files Browse the repository at this point in the history
* fix: passing filter context

Signed-off-by: Hiroshi Miura <[email protected]>

* fix: revert removeTags detection change

Signed-off-by: Hiroshi Miura <[email protected]>

---------

Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr authored Feb 23, 2025
1 parent 4490a2e commit 94fd724
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/org/omegat/filters2/hhc/HHCFilter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/org/omegat/filters2/hhc/HHCFilterVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

// ///////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion src/org/omegat/filters2/html2/FilterVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -79,6 +82,7 @@ public FilterVisitor(HTMLFilter2 htmlfilter, BufferedWriter bufwriter, HTMLOptio
this.options = new HTMLOptions(new TreeMap<>());
}
this.writer = bufwriter;
filterContext = fc;
}

// ///////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/filters2/html2/HTMLFilter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 94fd724

Please sign in to comment.