-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add Copy markdown to copy citation #13387
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
Open
tushar-2320
wants to merge
23
commits into
JabRef:main
Choose a base branch
from
tushar-2320:fix-for-issue-12552
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−2
Open
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b9ab287
fix:Added copy Markdown to copy citation #12552.
tushar-panto 9de6531
Merge branch 'main' into fix-for-issue-12552
tushar-2320 ad09503
Merge branch 'main' into fix-for-issue-12552
tushar-2320 84a1dd1
Merge branch 'main' into fix-for-issue-12552
tushar-2320 8bed13b
Merge branch 'main' into fix-for-issue-12552
tushar-2320 fae3c18
Merge branch 'main' into fix-for-issue-12552
tushar-2320 49b035b
fix:Added copy Markdown to copy citation #12552.
tushar-panto 8654adc
Merge branch 'main' into fix-for-issue-12552
tushar-2320 d582566
fix:Added copy Markdown to copy citation #12552.
tushar-panto 9c32813
Merge remote-tracking branch 'origin/fix-for-issue-12552' into fix-fo…
tushar-panto 508b93d
fix:Added @visibleForTesting in method processMarkdown #12552.
tushar-panto d131b92
Merge branch 'main' into fix-for-issue-12552
koppor 0553179
Merge branch 'main' into fix-for-issue-12552
tushar-2320 529c9f0
Merge remote-tracking branch 'origin/fix-for-issue-12552' into fix-fo…
tushar-panto e805e7e
fix:submodule removal
tushar-panto 7b3fbf7
fix:Added @visibleForTesting in method processMarkdown #12552.
tushar-panto b3eb93c
Revert submodule changes to match main
tushar-panto b1811e2
Reset submodule pointers to match main branch
tushar-panto 34b387f
Merge branch 'main' into fix-for-issue-12552
calixtus 756efcf
Merge branch 'main' into fix-for-issue-12552
tushar-2320 f6b4131
refactor:removed unecessary debugging statements and whitespace strip…
tushar-panto 85dce83
refactor:used List.of instead of Array.asList
tushar-panto 76eae89
Merge branch 'main' into fix-for-issue-12552
tushar-2320 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
import com.airhacks.afterburner.injection.Injector; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter; | ||
|
||
public class ClipboardContentGenerator { | ||
|
||
|
@@ -45,6 +46,7 @@ public ClipboardContent generate(List<BibEntry> selectedEntries, CitationStyleOu | |
return switch (outputFormat) { | ||
case HTML -> processHtml(citations); | ||
case TEXT -> processText(citations); | ||
case MARKDOWN -> processMarkdown(citations); | ||
}; | ||
} else { | ||
// if it is not a citation style take care of the preview | ||
|
@@ -120,6 +122,32 @@ static ClipboardContent processHtml(List<String> citations) { | |
return content; | ||
} | ||
|
||
/** | ||
* Insert each citation into HTML. | ||
* convert HTML to markdown using flexmark. | ||
*/ | ||
@VisibleForTesting | ||
static ClipboardContent processMarkdown(List<String> citations) { | ||
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. The method uses string concatenation for multiline HTML template instead of Java text blocks ("""). This makes the code less readable and maintainable. |
||
String result = "<!DOCTYPE html>" + OS.NEWLINE + | ||
"<html>" + OS.NEWLINE + | ||
" <head>" + OS.NEWLINE + | ||
" <meta charset=\"utf-8\">" + OS.NEWLINE + | ||
" </head>" + OS.NEWLINE + | ||
" <body>" + OS.NEWLINE + OS.NEWLINE; | ||
|
||
result += String.join(CitationStyleOutputFormat.HTML.getLineSeparator(), citations); | ||
result += OS.NEWLINE + | ||
" </body>" + OS.NEWLINE + | ||
"</html>" + OS.NEWLINE; | ||
|
||
FlexmarkHtmlConverter converter = FlexmarkHtmlConverter.builder().build(); | ||
String markdown = converter.convert(result); | ||
|
||
ClipboardContent content = new ClipboardContent(); | ||
content.putString(markdown); | ||
return content; | ||
} | ||
|
||
private List<String> generateTextBasedPreviewLayoutCitations(List<BibEntry> selectedEntries, BibDatabaseContext bibDatabaseContext) throws IOException { | ||
TextBasedPreviewLayout customPreviewLayout = previewPreferences.getCustomPreviewLayout(); | ||
Reader customLayoutReader = Reader.of(customPreviewLayout.getText().replace("__NEWLINE__", "\n")); | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 comment is trivial and simply restates what the code does without providing additional information about the reasoning or important details about the implementation.