-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Keep {} in Markdown rendering #11196
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
Conversation
|
@koppor, in your comment you say the following.
Do you want me to also cover this in this current PR, or does this deserve another one ? Also, the original issue mentions that Markdown rendering also swallows new lines, but removing the following lines in // workaround HTMLChars transforming "\n" into <br> by returning a one liner
return html.replaceAll("\\r\\n|\\r|\\n", " ").trim();The only drawback is that it seems to add more newlines than necessary, which may come from the external parser used. Do we keep the old version with no newlines ?
|
koppor
left a comment
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.
Small comments regarding the test
src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java
Outdated
Show resolved
Hide resolved
| assertEquals("'", layout.format("{\\textquotesingle}")); | ||
| assertEquals("'", layout.format("\\textquotesingle")); |
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.
The code change is OK. Reason: { is not used as parameter for a LaTeX command.
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.
Since the existing layouter is tested now, please add this back.
src/test/java/org/jabref/logic/layout/format/HTMLCharsTest.java
Outdated
Show resolved
Hide resolved
|
Since you went deep into fixing |
Without going deep into the code, I cannot follow. Can you add test cases to Remember that modern Java allows to use |
This is fixed now.
I should have thought about this before, my bad.
Ok ! I'll do this in a separate PR then. You're right it will be experimentation, since I don't really see the border between |
Current behavior is shown using the following test. @Test
void formatWhenFormattingComplexMarkupThenReturnsOnlyOneLine() {
assertFalse(markdownFormatter.format("Markup\n\n* list item one\n* list item 2\n\n rest").contains("\n"));
}The formatter only removes every new line. |
|
Now I have to adapt every |
Yeah, you are right. - I first thought LaTeXToUnicode is executed first and then some Unicode-to-HTML conversion. italics unicode back to However, LaTeX has a stable syntax, maybe, we leave everything as is. |
Not quote. Please use USe String input = """
test
some more
"""This is more readable for the human reader than reading |
This is a nightmare for backward compatiblity :) Thinking aloud:
OK, the default preview of JabRef needs to be adapted maybe... The normal latex2unicode should be able to handle most cases, thus I think, there probably is no adaption necessary? |
I agree with you. Since the current syntax is working properly and changes are not simply LaTeXToUnicode and then Unicode-to-HTML, but far more complex, we can leave everything as is. The issue about Markdown rendering with braces is now solved. In any case, perhaps the thymeleaf template engine will fill all these gaps this summer ? ;)
Understood, I implemented a test with multiline quotes in |
Your idea of an |
Add a constructor accepting the mode. The default constructor calls the other one with Then add some ifs in the code covering the two cases. - The places should be easy to find as they are the places of your modifications. Modifying the tests will be more hard, but required, too. Note: I am aware this is not OO style at all. However, rewriting in OO-style would make the class even more complex and not help IMHO.
Yes! |
| assertEquals("'", layout.format("{\\textquotesingle}")); | ||
| assertEquals("'", layout.format("\\textquotesingle")); |
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.
Since the existing layouter is tested now, please add this back.
| } | ||
|
|
||
| @Test | ||
| void formatWhenFormattingHeaderThenReturnsHeaderInHtml() { |
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.
You could convert all of them to ParameterizedTests!
All the tests seems to test some markdown-to-html functionality, which JabRef does not implement by itself, but through a library.
I would remove them and keep formatWhenFormattingCodeBlockThenReturnsCodeBlockInHtml() { only.
And then add some tests with empty lines to see how the converter deals with blocks. Are they also removed - or is only the code block the issue?
What about code blocks "recommended" by MD031 of markdown-lint?
"""
First line
Second line
```java
String test;
```
"""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.
After having written some tests I get what's going on about new line formatting. The current formatter uses HTML <p> tags for each line. By default, HTML inserts a new line between each <p> tag, which is why in MarkdownFormatter we remove the \n before returning formatted strings, to avoid jumping two lines instead of one. But in <pre> tags which include the code in Mardown, there are no such <p> tags to indicate the new lines. When JabRef removes the \n before returning the final string, we lose track of those new lines in code blocks.
… preferences migrations and made keep braces mode name more clear in HTMLChars
…e equality for braces keep mode in HTMLChars

This PR modifies the formatter
HTMLCharsused alongside the formatterMarkdownto avoid the useless swallow of chars{and}. It adapts tests accordingly and addsRemoveBracketsformatter in relevant*.layoutfiles to maintain previous behavior for non-Markdown fields.See this comment.
*.layoutfilesCloses #10928
Now, Markdown rendering keeps braces, see following screenshot.
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)