-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from all commits
b9ab287
9de6531
ad09503
84a1dd1
8bed13b
fae3c18
49b035b
8654adc
d582566
9c32813
508b93d
d131b92
0553179
529c9f0
e805e7e
7b3fbf7
b3eb93c
b1811e2
34b387f
756efcf
f6b4131
85dce83
76eae89
9071097
179fc7c
3bb6178
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 |
|---|---|---|
|
|
@@ -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.
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. You followed @Siedlerchr's recommendation and did not follow mine to use citeproc-java conversion. (michel-kraemer/citeproc-java@66cad6b) There needs to be AT LEAST a comment, why citeproc-java could not be used.
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. I was unaware of this, good point
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. Maybe my comment here #13387 (comment) is of help? Just to try out how to route things to that plugin?
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. Because it works for all previews! Not just csl. I see no advantage in using citeproc here.
Contributor
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. My only point is that find citeproc more configurable than flexmark.
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. I would do case handling If CSL use citeproc (specialized!, e.g. DOI linked) If no CSL, use flexmark |
||
| 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")); | ||
|
|
||
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.