Skip to content

Commit da075c2

Browse files
committed
fix delimiter problems; probably also closes #25
1 parent c723b22 commit da075c2

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: lingglosses
22
Type: Package
33
Title: Interlinear Glossed Linguistic Examples and Abbreviation Lists Generation
44
Version: 0.0.9
5-
Depends: R (>= 3.5.0)
5+
Depends: R (>= 4.1.0)
66
Authors@R: person("George", "Moroz",
77
role = c("aut", "cre"),
88
email = "[email protected]",
@@ -19,6 +19,6 @@ LazyData: true
1919
URL: https://CRAN.R-project.org/package=phonfieldwork, https://agricolamz.github.io/lingglosses/
2020
BugReports: https://github.com/agricolamz/lingglosses/issues
2121
Imports: kableExtra, knitr, gt, rmarkdown, utils, htmltools, methods
22-
RoxygenNote: 7.3.2.9000
22+
RoxygenNote: 7.3.3
2323
Suggests: testthat (>= 3.0.0)
2424
Config/testthat/edition: 3

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# lingglosses 0.0.10
2+
3+
- fix delimeter problems; probably also closes #25
4+
15
# lingglosses 0.0.9
26

37
- add `docx` compatibility

R/add_gloss.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ add_gloss <- function(glosses){
2323
# remove formatting --------------------------------------------------------
2424
glosses2add <- gsub("[_\\*]", "", glosses[glosses == toupper(glosses)])
2525
without_escape <- which(!(grepl("^\\{", glosses2add) &
26-
grepl("\\}$", glosses2add)))
26+
grepl("\\}$", glosses2add)|
27+
grepl("[-\\.=:\\)\\(!\\?<>\\~\\+\uFF3D\uFF3B]", glosses2add)))
2728
glosses2add <- glosses2add[without_escape]
2829

2930
# add glosses to the list --------------------------------------------------
@@ -35,7 +36,9 @@ add_gloss <- function(glosses){
3536
}
3637
# add small caps -----------------------------------------------------------
3738
glosses <- ifelse(glosses == toupper(glosses) &
38-
!(grepl("^\\{", glosses) & grepl("\\}$", glosses)),
39+
!(grepl("^\\{", glosses) &
40+
grepl("\\}$", glosses) |
41+
grepl("[-\\.=:\\)\\(!\\?<>\\~\\+\uFF3D\uFF3B]", glosses)),
3942
small_caps(glosses),
4043
glosses)
4144
glosses <- gsub("[\\}\\{]", "", glosses)

R/gloss_example.R

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,26 @@ gloss_example <- function(transliteration,
158158
}
159159

160160
# add glosses to the document gloss list -----------------------------------
161-
single_gl <- unlist(strsplit(glosses_by_word, "[-\\.=:\\)\\(!\\?<>\\~\\+\uFF3D\uFF3B]"))
162-
starts_with_punctuation <- single_gl[1] == ""
163-
single_gl <- gsub(pattern = "<", replacement = "&lt;", single_gl)
164-
single_gl <- gsub(pattern = ">", replacement = "&gt;", single_gl)
165-
single_gl <- lingglosses::add_gloss(single_gl)
166-
if(starts_with_punctuation){single_gl <- c("", single_gl)}
161+
glosses_by_word |>
162+
strsplit("(?=[-\\.=:\\)\\(!\\?<>\\~\\+\uFF3D\uFF3B])", perl = TRUE) |>
163+
lapply(FUN = function(i){
164+
gsub(pattern = "<", replacement = "&lt;", x = i) |>
165+
gsub(pattern = ">", replacement = "&gt;", x = _)
166+
}) ->
167+
single_gl
168+
169+
single_gl |>
170+
lapply(function(i){
171+
lingglosses::add_gloss(i)
172+
})
167173

168174
# get delimiters back ------------------------------------------------------
169-
delimiters <- unlist(strsplit(glosses,
170-
"[^-:\\.= \\)\\(!\\?\u201E\u201C\u2019\u201D\u00BB\u00AB\u201F<>\\~\\+\uFF3B\uFF3D]"))
171-
delimiters <- c(delimiters[delimiters != ""], "")
172-
if(!starts_with_punctuation){single_gl <- c(single_gl, rep("", sum(delimiters == ">")))}
173-
glosses <- paste0(single_gl, delimiters, collapse = "")
174-
glosses <- gsub("<span style=", "<span_style=", glosses)
175-
glosses <- unlist(strsplit(glosses, " "))
176-
glosses <- gsub("<span_style=", "<span style=", glosses)
175+
176+
single_gl |>
177+
lapply(function(i){
178+
paste0(i, collapse = "")
179+
}) ->
180+
glosses
177181

178182
# italic of the language line ----------------------------------------------
179183
if(isTRUE(italic_transliteration) & !drop_transliteration){

docs/index.html

Lines changed: 17 additions & 3 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)