Skip to content

Allow BibTeX::Filter access more metadata  #129

@xu-cheng

Description

@xu-cheng

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions