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

Allow BibTeX::Filter access more metadata #129

Open
xu-cheng opened this issue Apr 23, 2018 · 2 comments
Open

Allow BibTeX::Filter access more metadata #129

xu-cheng opened this issue Apr 23, 2018 · 2 comments

Comments

@xu-cheng
Copy link

xu-cheng commented Apr 23, 2018

This is a feature request. Would it make sense to allow BibTeX::Filter know more metadata in addition to the value?

For example, instead of making filter interface as:

class Filter
  def apply(value)
  end
end

Allow the interface access more meta data:

class Filter
  def apply(value, info)
  end
end

The info would be a Hash storing variaous meta data, such as:

{
  :entry => # the entry of the whole bibtex record
  :field => # the field of the current value, such as :first_name, :last_name, :title, etc.
  :index => # the index of the value if there are multiple same field, e.g. the index of the author.
  :annotation => # support bibtex annotation
}

The reason of using Hash is that it allows us to extend the feature in the future if necessary.

This will allow the filter to access more information regarding the current value. And it will enable us to support many features. For example:

  1. Allow us to highlight authors using bibtex annotation (Unable to parse bibtex if + is in the key #128)
class HighlightAuthor < BibTeX::Filter
  def apply(value, info)
    if info[:field] == :author && info[:annotation] == "highlight"
      "<b>#{value}</b>"
    else
      value
    end
  end
end
  1. Append conference abbreviation in the booktitle.
class ConfAbbr < BibTeX::Filter
  def apply(value, info)
      if info[:field] == :booktitle
        "#{value} (<b>#{info[:entry].series}</b>)"
      else
        value
      end
  end
end
@inukshuk
Copy link
Owner

I'm happy to merge a PR for this.

That said, the intention of the filters is was mostly to clean or convert values directly after parsing; your examples seem to be for rendering, formatting entries, but why use filters for that, why not just write a normal method that does it?

@xu-cheng
Copy link
Author

I'm happy to merge a PR for this.

Great. I will look into it. And try to come up with a PR.

but why use filters for that, why not just write a normal method that does it?

Since my use case is jekyll-schloar, I am not sure there are other ways instead of using BibTeX::Filter.

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

No branches or pull requests

2 participants