Skip to content

Fix 11102 by allowing users to add local bst files to preview layout list#11234

Merged
Siedlerchr merged 31 commits into
JabRef:mainfrom
sahilsekr42:fix-11102
May 20, 2024
Merged

Fix 11102 by allowing users to add local bst files to preview layout list#11234
Siedlerchr merged 31 commits into
JabRef:mainfrom
sahilsekr42:fix-11102

Conversation

@sahilsekr42

@sahilsekr42 sahilsekr42 commented Apr 21, 2024

Copy link
Copy Markdown
Contributor

I've tried to fix #11102 by adding a button which may be used to add the selected bst files to the available styles and tested it to work although I think for preview to function well bstvm should be used not sure how. Would like some guidance . After it works as expected may be documentation can be modified.

Mandatory checks

grafik
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@Siedlerchr

Copy link
Copy Markdown
Member

No need to close the PR and reopen. Just continue committing and pushing. The PR will be updated automatically

@Siedlerchr

Copy link
Copy Markdown
Member

think for preview to function well bstvm should be used not sure how

I am not quite sure I understand you correctly, but the BstPreviewLayout itself already handles the bstVm:, so it should work out of the box

@Override
public String generatePreview(BibEntry originalEntry, BibDatabaseContext databaseContext) {
if (error != null) {
return error;
}
// ensure that the entry is of BibTeX format (and do not modify the original entry)
BibEntry entry = (BibEntry) originalEntry.clone();
new ConvertToBibtexCleanup().cleanup(entry);
String result = bstVM.render(List.of(entry));
// Remove all comments
result = result.replaceAll("%.*", "");

@sahilsekr42

Copy link
Copy Markdown
Contributor Author

@Siedlerchr thanks I didn't really understand the mechanism of updating pull request (i.e. just committing to my branch automatically updates the pr and runs tests again.

Comment thread src/main/java/org/jabref/gui/preferences/preview/PreviewTabViewModel.java Outdated
@Siedlerchr

Copy link
Copy Markdown
Member

Thanks for the PR! We refactored the code a bit and found an issue with the BST rendering itself, (not your fault, but we would like to continue here, so please leave the PR open).

Comment thread src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java Outdated
@koppor

koppor commented Apr 25, 2024

Copy link
Copy Markdown
Member

Intermediate result:

Comment thread src/test/java/org/jabref/logic/bst/BstVMTest.java
@koppor

koppor commented Apr 25, 2024

Copy link
Copy Markdown
Member

Current state:

The t is a function which is "not found", but t seems to be string or a variable.

Maybe, the whole new interpretation mixes up parsing of the .bst file and the real execution.

Other than that, I find following code strange - this seems to mix parsing and execution

    @Override
    public Integer visitBstFunction(BstParser.BstFunctionContext ctx) {
        String name = ctx.getChild(0).getText();
        if (bstVMContext.functions().containsKey(name)) {
            LOGGER.trace("Function '{}' found", name);
            bstVMContext.functions().get(name).execute(this, ctx, selectedBstEntry);
        } else {
            LOGGER.trace("Function '{}' not found", name);
            visit(ctx.getChild(0));
        }

        return BstVM.TRUE;
    }

@koppor

koppor commented May 19, 2024

Copy link
Copy Markdown
Member

Strange git error:

error: Authentication error: Authentication required: You must have push access to verify locks
error: failed to push some refs to 'https://github.com/sahilsekr42/jabref.git'

Pushed to koppor.

@Siedlerchr

Copy link
Copy Markdown
Member

something with git lfs stuff

@koppor

koppor commented May 19, 2024

Copy link
Copy Markdown
Member

We identified that there is an endless loop happening in following bst function

% Converts all single dashes "-" to double dashes "--".
FUNCTION {n.dashify}
{ large.number.separate
  't :=
  ""
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
            { "--" *
              t #2 global.max$ substring$ 't :=
            }
            {   { t #1 #1 substring$ "-" = }
                { "-" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
            }
          if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}

(And we fixed the lookup)

@koppor koppor mentioned this pull request May 19, 2024
6 tasks
* upstream/main:
  Fix BSTVM (JabRef#11304)

# Conflicts:
#	src/main/java/org/jabref/logic/bst/BstVM.java
#	src/main/java/org/jabref/logic/bst/BstVMVisitor.java
#	src/test/java/org/jabref/logic/bst/BstVMTest.java
@Siedlerchr Siedlerchr marked this pull request as draft May 20, 2024 09:45
Fix NPE
add preview to chosen
@Siedlerchr

Siedlerchr commented May 20, 2024

Copy link
Copy Markdown
Member

Storing in the prefs now works as well

add to layout cycle

Apply some intellij logger suggestions
@Siedlerchr Siedlerchr marked this pull request as ready for review May 20, 2024 10:55
@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 20, 2024
@Siedlerchr Siedlerchr requested review from calixtus and koppor May 20, 2024 11:35
Comment thread src/main/java/org/jabref/preferences/JabRefPreferences.java Outdated
Comment thread src/main/java/org/jabref/preferences/JabRefPreferences.java Outdated
Comment thread src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java
@Siedlerchr Siedlerchr enabled auto-merge May 20, 2024 11:44
@Siedlerchr Siedlerchr added this pull request to the merge queue May 20, 2024
Merged via the queue into JabRef:main with commit 16f0e54 May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the option to select a BST style for Preview

4 participants