Skip to content
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

Js Port #83

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Js Port #83

wants to merge 27 commits into from

Conversation

Leon0402
Copy link

Fixes #48

This is my initial try to port asciidoctor-bibtex to javascript. I tested it with one of the more complex examples with different styles and it seems to work fine.

Gemfile Outdated Show resolved Hide resolved
Co-authored-by: Guillaume Grossetie <[email protected]>
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
"ProgramFan (https://github.com/ProgramFan)",
"Leon De Andrade (https://github.com/Leon0402)"
],
"license": "Open Works",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this licence.
@mojavelinux do we have guidelines in the Asciidoctor org?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I'm wondering if we should replace this license to align with other projects in the Asciidoctor organization.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mojavelinux Any news here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Asciidoctor project doesn't use the Open Works license. It should either be MIT or Apache. I prefer MIT. Open Works is compatible with MIT as far as I can tell (since it is derived from it and extended to non-software) so I don't think there is any issue with updating it.

package.json Outdated Show resolved Hide resolved
Co-authored-by: Guillaume Grossetie <[email protected]>
result << "[[#{key}]]" if @links
if StyleUtils.is_numeric? @style
result << "#{@bibtex_ob}#{index}#{@bibtex_cb} "
if RUBY_ENGINE == 'opal' and not cptext.nil?
# Numbering is added by asciidoctor-bibtex and therefore should be stripped here
cptext = cptext.first.gsub(/^[\[\d\.\]]*/, ""), ""
Copy link
Member

@ggrossetie ggrossetie Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You meant by Citation.js? Otherwise, I don't get why we do it only when RUBY_ENGINE == 'opal'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant asciidoctor-bibtex already adds numbering in the bibliography. But so does citation.js. So both add numbers.

Actually the numbers from citation.js depend on the style. For instance for vancouver it is "1. MyBibEntry" whereas for ieee it is "[1] MyBibEntry". For asciidoctor-bibtex it is alwas [1].

To be consistent with asciidoctor-bibtex I strip the numbering from citation.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.
I would say that "Strip Citation.js numbering, will be added by asciidoctor-bibtex"?

I think it's easier to understand if we explain what we are doing and then why. When I first read the sentence, I thought the goal was to remove the numbering added by asciidoctor-bibtex (and use Citation.js numbering but apparently that's the other way around).

.gitignore Outdated Show resolved Hide resolved
@ggrossetie
Copy link
Member

I think it would be great to add a smoke test to make sure that the generation is working as expected. Something like: https://github.com/asciidoctor/asciidoctor-reveal.js/blob/acb2247380fe70e51dadcbb71568e2902d8865ce/test/smoke.js#L1-L22

@locale = options[:locale]

styleFilePath = "../vendor/styles/#{@style}.csl"
styleFilePath = `path.resolve(__dirname, #{styleFilePath})`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mogztter I needed to add this, so it works regardless of the structure. I'm sure this can be written in ruby, but I'm not quite sure how. I tried a few things like styleFilePath == File.expand_path(styleFilePath, __FILE__).

Copy link
Member

@ggrossetie ggrossetie May 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What File.expand_path(styleFilePath, __FILE__) gives you? Maybe __FILE__ is not correctly implemented in Opal... 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be a bug in opal. I tried following code snippet:

puts __FILE__
puts File.expand_path('../vendor/styles',  __FILE__)

With ruby __FILE__ just gives the file name and expand_path the full absolute path.

Wit opal (our version & newest) you get the same behaviour for __FILE__, but expand_path just gives ./vendor/styles.

So it seems expand_path or __FILE__ is not correctly implemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use File.absolute_path. File.expand_path has some magic behavior that isn't needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JavaScript compatibility
3 participants