-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Implement 1356 #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement 1356 #1572
Changes from all commits
aebe493
0ad5e6c
59b8af8
0f6e0a6
8f2f36f
11eb5f0
89a34fd
ab003b0
7c1afff
cf781bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package net.sf.jabref.logic.formatter.bibtexfields; | ||
|
|
||
| import net.sf.jabref.logic.formatter.Formatter; | ||
| import net.sf.jabref.logic.l10n.Localization; | ||
| import net.sf.jabref.logic.layout.LayoutFormatter; | ||
|
|
||
| import org.apache.commons.lang3.StringEscapeUtils; | ||
|
|
||
| public class HtmlToUnicodeFormatter implements LayoutFormatter, Formatter { | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "HTML to Unicode"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getKey() { | ||
| return "html_to_unicode"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return Localization.lang("Converts HTML code to Unicode."); | ||
| } | ||
|
|
||
| @Override | ||
| public String getExampleInput() { | ||
| return "<b>bread</b> & butter"; | ||
| } | ||
|
|
||
| @Override | ||
| public String format(String fieldText) { | ||
| // StringEscapeUtils converts characters and regex kills tags | ||
| return StringEscapeUtils.unescapeHtml4(fieldText).replaceAll("\\<[^>]*>",""); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,3 +1705,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1607,3 +1607,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2393,3 +2393,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1626,3 +1626,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1726,3 +1726,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2371,3 +2371,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2402,3 +2402,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2798,3 +2798,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1620,3 +1620,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2370,3 +2370,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1639,3 +1639,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2394,3 +2394,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1633,3 +1633,5 @@ The_link_has_been_copied_to_the_clipboard.= | |
| Online_help_forum= | ||
|
|
||
| Custom= | ||
|
|
||
| Converts_HTML_code_to_Unicode.= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package net.sf.jabref.logic.formatter.bibtexfields; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class HtmlToUnicodeFormatterTest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this formatter also to the parametrized FormatterTest class (not sure about the exact name)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. And |
||
|
|
||
| private HtmlToUnicodeFormatter formatter; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| formatter = new HtmlToUnicodeFormatter(); | ||
| } | ||
|
|
||
| @Test | ||
| public void formatWithoutHtmlCharactersReturnsSameString() { | ||
| assertEquals("abc", formatter.format("abc")); | ||
| } | ||
|
|
||
| @Test | ||
| public void formatMultipleHtmlCharacters() { | ||
| assertEquals("åäö", formatter.format("åäö")); | ||
| } | ||
|
|
||
| @Test | ||
| public void formatCombinedAccent() { | ||
| assertEquals("í", formatter.format("í")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBasic() { | ||
| assertEquals("aaa", formatter.format("aaa")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUmlauts() { | ||
| assertEquals("ä", formatter.format("ä")); | ||
| assertEquals("ä", formatter.format("ä")); | ||
| assertEquals("ä", formatter.format("ä")); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testGreekLetter() { | ||
| assertEquals("Ε", formatter.format("Ε")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHTMLRemoveTags() { | ||
| assertEquals("aaa", formatter.format("<p>aaa</p>")); | ||
| } | ||
|
|
||
| @Test | ||
| public void formatExample() { | ||
| assertEquals("bread & butter", formatter.format(formatter.getExampleInput())); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add a corresponding entry in the help file (for LayoutFormatter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refs: #8 None of the current formatters are documented and I won't build documentation for all as part of this PR. This has to go separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant http://help.jabref.org/en/CustomExports under
Built-in export formatterssince the class is implementing LayoutFormatter and thus can be used for the exports too, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not a single class of the package
net.sf.jabref.logic.formatter.*is listed in this section. I don't think a patchwork solution, where I document just one of those, would be a good idea. The whole page desperately needs updating.