-
Notifications
You must be signed in to change notification settings - Fork 28
Js Port #83
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
Leon0402
wants to merge
27
commits into
asciidoctor-contrib:main
Choose a base branch
from
Leon0402:feature/jsPort
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.
Open
Js Port #83
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8b172ec
Basic js setup
Leon0402 16e971c
Import asciidoctor only for ruby
Leon0402 0a34799
Add mocks for missing methods
Leon0402 f304423
WIP
Leon0402 8a32a2e
First working version
Leon0402 50318b4
Use entry output option
Leon0402 e07b20a
Remove unneeded files
Leon0402 739381b
Extract information from bitex format instead
Leon0402 b792377
Add style and locale option
Leon0402 720063a
Replace another mutable string
Leon0402 81e07c7
Support csl styles
Leon0402 87e794e
Add language support
Leon0402 6e99f2a
Fix numbering for numerical entries
Leon0402 227a0fd
Remove double import
Leon0402 b0d0e7b
Add error handling for unknown references
Leon0402 cba9e46
Fix typo in error message
Leon0402 06128bc
Use opal ref d136ea8
Leon0402 1ac728f
Merge branch 'feature/jsPort' of github.com:Leon0402/asciidoctor-bibt…
Leon0402 9d23ffe
Use one block for opal platform
Leon0402 83f42bb
Update package.json description
Leon0402 b201866
Update dev dependency in package.json
Leon0402 0f47302
Merge branch 'feature/jsPort' of github.com:Leon0402/asciidoctor-bibt…
Leon0402 b8ed5ea
Use File.file instead of native js code
Leon0402 b1ea41d
Build hash once
Leon0402 6f6422b
Resolve path to absolute
Leon0402 0564033
Resolve issue regarding gitignore
Leon0402 6b8c909
Use id as label
Leon0402 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ | |
/samples/*/*.html | ||
/samples/*/*.pdf | ||
pkg | ||
.bundle | ||
node_modules | ||
dist | ||
sample | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "vendor/locales"] | ||
path = vendor/locales | ||
url = https://github.com/citation-style-language/locales.git | ||
branch = master | ||
Leon0402 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[submodule "vendor/styles"] | ||
path = vendor/styles | ||
url = https://github.com/citation-style-language/styles.git | ||
branch = master |
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module AsciidoctorBibtex | ||
`const {Cite, plugins} = require('@citation-js/core')` | ||
`require('@citation-js/plugin-bibtex')` | ||
|
||
module BibTeX | ||
def self.open(path, options = {}) | ||
file = File.read(path, encoding: 'utf-8') | ||
return Bibliography.new(`new Cite(#{file})`) | ||
end | ||
|
||
class Bibliography | ||
def initialize(js_bibliography) | ||
@js_bibliography = js_bibliography | ||
end | ||
|
||
def to_citeproc(options = {}) | ||
return @js_bibliography | ||
Leon0402 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def [](key) | ||
js_entry = %x{#{@js_bibliography}.format('bibtex', { format: 'object'}).find(cite => cite.label === #{key})} | ||
if `js_entry === undefined` | ||
return nil | ||
end | ||
return Entry.new(js_entry) | ||
end | ||
end | ||
|
||
class Entry | ||
attr_reader :author, :editor, :year | ||
|
||
def initialize(js_entry) | ||
@author = `js_entry.properties.author` | ||
@editor = `js_entry.properties.editor` | ||
@year = `js_entry.properties.year` | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module AsciidoctorBibtex | ||
`const {Cite, plugins} = require('@citation-js/core')` | ||
`require('@citation-js/plugin-csl')` | ||
`const Fs = require('fs')` | ||
Leon0402 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`const { styles } = require('csl-js')` | ||
|
||
module CiteProc | ||
class Processor | ||
attr_reader :style, :format, :locale | ||
|
||
def initialize(options) | ||
@style = options[:style] | ||
@format = options[:format] | ||
@locale = options[:locale] | ||
|
||
styleFilePath = "../vendor/styles/#{@style}.csl" | ||
raise "nibtex-style '#{@style}' does not exist" unless `Fs.existsSync(#{styleFilePath})` | ||
Leon0402 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
localeFilePath = "../vendor/locales/locales-#{@locale}.xml" | ||
raise "bibtex-locale '#{@locale}' does not exist" unless `Fs.existsSync(#{localeFilePath})` | ||
|
||
styleFile = File.read(styleFilePath, encoding: 'utf-8') | ||
localeFile = File.read(localeFilePath, encoding: 'utf-8') | ||
%x{ | ||
let csl_config = plugins.config.get('@csl') | ||
csl_config.templates.add(#{style}, #{styleFile}) | ||
csl_config.locales.add(#{locale}, #{localeFile}) | ||
|
||
// This is used for style_utils.rb as the lib itself doesn't expose infos about the csl styles | ||
styles.set(#{style}, #{styleFile}) | ||
} | ||
end | ||
|
||
def import(js_bibliography) | ||
@js_bibliography = js_bibliography | ||
end | ||
|
||
def render(mode, cite_data) | ||
case mode | ||
when :bibliography | ||
return %x{#{@js_bibliography}.format('bibliography', { | ||
entry: #{cite_data[:id]}, | ||
template: #{@style}, | ||
lang: #{@locale} | ||
})}, "" | ||
when :citation | ||
return %x{#{@js_bibliography}.format('citation', { | ||
entry: #{cite_data[:id]}, | ||
template: #{@style}, | ||
lang: #{@locale} | ||
})} | ||
else | ||
raise ArgumentError, "cannot render unknown mode: #{mode.inspect}" | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module AsciidoctorBibtex | ||
`const { styles } = require('csl-js')` | ||
module StyleUtils | ||
def self.is_numeric?(style) | ||
return `styles.get(#{style}).info.category['citation-format'] === 'numeric'` | ||
end | ||
end | ||
end |
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.
Uh oh!
There was an error while loading. Please reload this page.