-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/correct handling of wovn ignore (#164)
* Fixed comment insertion. * Bump up patch version. * Fixed test: new behavior for `restore()` makes that it always returns a valid HTML. * Re-implemented following WOVN.php's design. * Changed handling of <input>: only value is commented.
- Loading branch information
Showing
4 changed files
with
78 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/wovnio/wovnjava/HtmlReplaceMarker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.wovnio.wovnjava; | ||
|
||
import java.util.HashMap; | ||
|
||
class HtmlReplaceMarker { | ||
private final String WOVN_MARKER_PREFIX = "wovn-marker-"; | ||
private final HashMap<String, String> mappedValues; | ||
private int keyCount; | ||
|
||
HtmlReplaceMarker() { | ||
this.mappedValues = new HashMap<String, String>(); | ||
this.keyCount = 0; | ||
} | ||
|
||
public String addCommentValue(String original) { | ||
String key = generateKey(); | ||
String commentHtml = String.format("<!--%s-->", key); | ||
mappedValues.put(commentHtml, original); | ||
return key; | ||
} | ||
|
||
public void addValue(String key, String original) { | ||
mappedValues.put(key, original); | ||
} | ||
|
||
public String revert(String markedHTML) { | ||
for (String key: mappedValues.keySet()) { | ||
String original = mappedValues.get(key); | ||
markedHTML = markedHTML.replace(key, original); | ||
} | ||
return markedHTML; | ||
} | ||
|
||
public String generateKey() { | ||
String key = WOVN_MARKER_PREFIX + String.valueOf(keyCount); | ||
keyCount++; | ||
return key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters