superscript.rb 377 Bytes
Newer Older
Thomas Wood's avatar
Thomas Wood committed
1
2
3
4
module Jekyll
  class Scholar
    class Superscript < BibTeX::Filter
      def apply(value)
Thomas Wood's avatar
Thomas Wood committed
5
6
7
8
        # Use of \g<1> pattern back-reference to allow for capturing nested {} groups.
        # The first (outermost) capture of $1 is used.
        value.to_s.gsub(/\\textsuperscript(\{(?:[^{}]|\g<1>)*\})/) {
          "<sup>#{$1[1..-2]}</sup>"
Thomas Wood's avatar
Thomas Wood committed
9
10
11
12
13
        }
      end
    end
  end
end