Commit 12760b08 by Thomas Wood

Fix superscript filter matching.

{} could be matched arbitrarily inside of a {} pattern, in addition to the expected behaviour of nested pairs. (oops) Closes #143
parent 218cede4
......@@ -279,3 +279,79 @@ Feature: BibTeX
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "<sup>ü ü ž</sup>" in "_site/scholar.html"
@tags @superscript
Scenario: LaTeX Superscript as HTML with embedded LaTeX chars left untouched
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
And I have the following BibTeX filters:
| superscript |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@misc{pickaxe,
title = {\textsuperscript{\"u \"{u} \v{z}}}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "<sup>\\"u \\"\{u\} \\v\{z\}</sup>" in "_site/scholar.html"
@tags @superscript
Scenario: LaTeX Superscript with subsequent groups as HTML
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
And I have the following BibTeX filters:
| superscript |
| latex |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@misc{pickaxe,
title = {This is \textsuperscript{superscript text} this should not be superscript {even} {with {additional} groups}.}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "This is <sup>superscript text</sup> this should not be superscript even with additional groups." in "_site/scholar.html"
@tags @superscript
Scenario: LaTeX Superscript with subsequent groups untouched in HTML
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
And I have the following BibTeX filters:
| superscript |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@misc{pickaxe,
title = {This is \textsuperscript{superscript text} this should not be superscript {even} {with {additional} groups}.}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "This is <sup>superscript text</sup> this should not be superscript \{even\} \{with \{additional\} groups\}." in "_site/scholar.html"
......@@ -2,9 +2,10 @@ module Jekyll
class Scholar
class Superscript < BibTeX::Filter
def apply(value)
# Use of \g<1> pattern back-reference to allow for capturing nested {} groups
value.to_s.gsub(/\\textsuperscript(\{((?:.|\g<1>)*)\})/) {
"<sup>#{$2}</sup>"
# 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>"
}
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment