Skip to content

Commit

Permalink
Merge pull request #3499 from Hannah-Sten/3472-bib-webreferences
Browse files Browse the repository at this point in the history
Fix #3472 by finishing implementation of urls in bib as verbatim
  • Loading branch information
PHPirates authored Mar 30, 2024
2 parents ff086f2 + 9700306 commit 08bf0da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/nl/hannahsten/texifyidea/grammar/BibtexLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ QUOTES="\""

WHITE_SPACE=[ \t\n\x0B\f\r]+
TYPE_TOKEN=@[a-zA-Z_]+
// BibTeX itself doesn't support % as a comment character (using it it the start of a line in an entry is illegal), but
// biber explicitly supports it as a comment, so we do as well.
COMMENT_TOKEN=%[^\r\n]*
// Characters disallowed by bibtex or biber (non-ascii or not depends on LaTeX compiler)
IDENTIFIER=[^,{}\(\)\"#%'=~\\ \n]+
Expand Down
24 changes: 23 additions & 1 deletion src/nl/hannahsten/texifyidea/util/Bibtex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ fun BibtexContent.evaluate(): String {
for (string in childrenOfType(BibtexString::class)) {
val braced = string.bracedString
val quoted = string.quotedString
val bracedVerbatim = string.bracedVerbatim
val quotedVerbatim = string.quotedVerbatim
val defined = string.definedString

if (braced != null) {
Expand All @@ -89,6 +91,12 @@ fun BibtexContent.evaluate(): String {
else if (defined != null) {
result += defined.evaluate()
}
else if (bracedVerbatim != null) {
result += bracedVerbatim.evaluate()
}
else if (quotedVerbatim != null) {
result += quotedVerbatim.evaluate()
}
}

if (result.isEmpty()) {
Expand Down Expand Up @@ -163,4 +171,18 @@ fun BibtexBracedString.evaluate(): String {
fun BibtexQuotedString.evaluate(): String {
val text = text
return text.substring(1 until text.length - 1)
}
}

/**
* Returns the contents of the quoted verbatim string.
*
* E.g. `"Test Hello"` becomes `Test Hello`.
*/
fun BibtexQuotedVerbatim.evaluate(): String = text.substring(1 until text.length - 1)

/**
* Returns the contents of the braced verbatim string.
*
* E.g. `{Test Hello}` becomes `Test Hello`.
*/
fun BibtexBracedVerbatim.evaluate(): String = text.substring(1 until text.length - 1)
8 changes: 1 addition & 7 deletions src/nl/hannahsten/texifyidea/util/parser/BibtexPsiUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ fun BibtexEntry.getTagContent(tagName: String?): String {

entryContent.tagList.forEach {
if (tagName.equals(it.key.text, ignoreCase = true)) {
val text = it.content?.evaluate() ?: return ""

// Deal with braced strings.
return if (text.first() == '{' && text.last() == '}') {
text.substring(1, text.length - 1)
}
else text
return it.content?.evaluate() ?: ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BibtexEntryImplUtilTest : BasePlatformTestCase() {
journal = {GitHub},
year = {2020},
url = {$url},
biburl = {$url}
biburl = "$url"
}"""

private val entryElement by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BibtexIdCompletionTest : BasePlatformTestCase() {
val entry1 = result.first { l -> l!!.lookupString == "Evans2015" }!!
assertTrue(entry1.allLookupStrings.contains("Evans, Isaac"))
assertTrue(entry1.allLookupStrings.contains("Evans2015"))
assertTrue(entry1.allLookupStrings.contains("Missing the Point(er): On the Effectiveness of Code Pointer Integrity"))
assertTrue(entry1.allLookupStrings.contains("{Missing the Point(er): On the Effectiveness of Code Pointer Integrity}"))
}

@Test
Expand Down

0 comments on commit 08bf0da

Please sign in to comment.