diff --git a/README.md b/README.md index 6da5c36..49b6c41 100644 --- a/README.md +++ b/README.md @@ -633,10 +633,6 @@ and writes the following XML to standard out (shortened): ``` -Look at the 'examples' directory for more elaborate examples of a BibTeX to -YAML and a BibTeX to HTML converter using **#to_citeproc** to format a -bibliography using [CSL](https://citationstyles.org/). - BibTeX-Ruby offers an API which lets you manipulate BibTeX objects (string replacement, name parsing etc.); however, sometimes you just want quick access to your bibliography's contents. In these cases the **to_hash** method is diff --git a/examples/bib2html.rb b/examples/bib2html.rb deleted file mode 100644 index 2cdc289..0000000 --- a/examples/bib2html.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require 'rubygems' -require 'bibtex' - -begin - require 'citeproc/ruby' - require 'csl/styles' -rescue LoadError - puts 'this example depends on the citeproc-ruby and csl-styles gems' - exit -end - -# Open a bibliography file -bib = BibTeX.open File.expand_path('markdown.bib', __dir__), - include: [:meta_content] - -# Replaces all strings in the Bibliography and then -# converts each BibTeX entries to a string using Chicago style -# (all other elements are mapped to simple strings) -bib.replace - -cp = CiteProc::Processor.new style: 'apa', - format: 'html', locale: 'en' - -cp.import bib.to_citeproc - -content = bib['@entry, @meta_content'].map do |e| - if e.entry? - cp.render :bibliography, id: e.key - else - e.to_s - end -end - -begin - require 'redcarpet' -rescue LoadError - puts 'this example depends on the redcarpet gem' - exit -end - -puts Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content.join) diff --git a/examples/bib2yaml.rb b/examples/bib2yaml.rb deleted file mode 100755 index 8c65449..0000000 --- a/examples/bib2yaml.rb +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require 'rubygems' -require 'bibtex' -require 'yaml' - -if ARGV.empty? - puts "Usage: #{$PROGRAM_NAME} []" -else - out = ARGV.length == 2 ? File.open(ARGV[1], 'w') : $stdout - out.puts BibTeX.open(ARGV[0]).to_yaml -end diff --git a/examples/markdown.bib b/examples/markdown.bib deleted file mode 100644 index a6cf539..0000000 --- a/examples/markdown.bib +++ /dev/null @@ -1,39 +0,0 @@ -Bibliography -============ - -Here is a little bibliography to illustrate how *BibTeX* and -*Markdown* can be seamlessly integrated. This is a _valid_ BibTeX -File; at the same time its comments are written using Markdown -markup. For example, this is a list: - -* More interestingly, though, we can also include -* any BibTeX object we want. - -It will not show up in the HTML, but here we define a string: - -@string{ thoreau = "Thoreau, Henry David" } -@string{ nyc = "New York" } - -Now we can add a few BibTeX entries and convert them to text -for inclusion. - -In the HTML version we will print the BibTeX entries in a simple -text format instead. - -@book{key, - author = thoreau, - title = {Walden; or Life in the Woods}, - publisher = "Dover", - address = nyc, - year = 1995 -} - -@book{poe, - author = {Poe, Edgar Allen}, - title = "Poetry, Tales, and Selected Essays", - address = nyc, - publisher = "Library of America", - year = 1996 -} - -Neat, huh? diff --git a/features/meta_content.feature b/features/meta_content.feature new file mode 100644 index 0000000..2868f8c --- /dev/null +++ b/features/meta_content.feature @@ -0,0 +1,30 @@ +Feature: Text between BibTeX objects + As a hacker who works with bibliographies + I want to keep the text between BibTeX objects + So that a bibliography can also be a document, like written in Markdown + + Scenario: A Markdown document with strings and entries + When I parse the following file keeping the text between objects: + """ + Bibliography + ============ + Here we define a string: + + @string{ thoreau = "Thoreau, Henry David" } + + And here we add a book: + + @book{walden, + author = thoreau, + title = {Walden; or Life in the Woods}, + year = 1995 + } + + Neat, huh? + """ + And I replace all strings in my bibliography + And I search for "@entry, @meta_content" + Then there should be exactly 4 matches + And my bibliography should contain these books: + | key | author | title | + | walden | Thoreau, Henry David | Walden; or Life in the Woods | diff --git a/features/step_definitions/bibtex_steps.rb b/features/step_definitions/bibtex_steps.rb index 4676357..d09cfb3 100644 --- a/features/step_definitions/bibtex_steps.rb +++ b/features/step_definitions/bibtex_steps.rb @@ -18,6 +18,10 @@ @bibliography = BibTeX.parse(string, options) end +When(/^I parse the following file keeping the text between objects:$/) do |string| + @bibliography = BibTeX.parse(string, include: [:meta_content]) +end + When(/^I search for "([^"]*)"$/) do |query| @result = @bibliography.query(query) end