Skip to content

Commit

Permalink
fix: passing filter context
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Nov 20, 2024
1 parent c12d959 commit b19f659
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 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
9 changes: 6 additions & 3 deletions 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 Expand Up @@ -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) {
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 b19f659

Please sign in to comment.