Skip to content

Commit

Permalink
Autofix: Add \p. Fixes Bridgeconn#270
Browse files Browse the repository at this point in the history
  • Loading branch information
kavitharaju committed Nov 25, 2024
1 parent fd59749 commit f8a3f22
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions node-usfm-parser/src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ class Validator {
modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`);
changed = true;
}
else if (error.isError && !errorText.startsWith("\\") && error.previousSibling.type === "chapter" &&
!error.children.some(ch => ch.type === "paragraph")) {
// console.log("Match 7.1");
const start = error.previousSibling.startIndex;
const end = error.startIndex;
const toReplace = modifiedUSFM.slice(start, end);
modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`);
changed = true;
}
// Stray slash not with a valid marker
else if (errorText.startsWith("\\") && !validMarkersPattern.test(errorText)) {
// console.log("Match 8");
Expand Down
12 changes: 12 additions & 0 deletions py-usfm-parser/src/usfm_grammar/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ def auto_fix_usfm(self, usfm, fixed=False): #pylint: disable=R0912,R0915
# self.modified_usfm = re.sub(to_replace, repalcement, self.modified_usfm)
self.modified_usfm = self.modified_usfm.replace(to_replace, repalcement)
changed = True
elif error.is_error and \
(not error_text.startswith("\\")) and \
error.prev_sibling.type == "chapter" and \
"paragraph" not in [ch.type for ch in error.children]:
# print("match 7.1")
start = error.prev_sibling.start_byte
end = error.start_byte
to_replace = self.usfm_bytes[start:end].decode('utf-8')
repalcement = to_replace+"\\p\n"
# self.modified_usfm = re.sub(to_replace, repalcement, self.modified_usfm)
self.modified_usfm = self.modified_usfm.replace(to_replace, repalcement)
changed = True
# Stray slash not with a valid marker
elif error_text.startswith("\\") and \
(not re.match(valid_markers_pattern, error_text)):
Expand Down
24 changes: 24 additions & 0 deletions tests/autofix/b_without_p.usfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
\id GEN genesis Some desc
\c 1
\p
\v 1 test verse
\s some poem
\q1
first line
\b
\q1
\v 2 more lines
\b
remaining verses
\v 3 text follows
\c 2
\p
\v 1 test verse
\s some poem
\q1
first line
\b
\q1
\v 2 more lines
\b
\v 3 verse follows
9 changes: 9 additions & 0 deletions web-usfm-parser/src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ class Validator {
modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`);
changed = true;
}
else if (error.isError && !errorText.startsWith("\\") && error.previousSibling.type === "chapter" &&
!error.children.some(ch => ch.type === "paragraph")) {
// console.log("Match 7.1");
const start = error.previousSibling.startIndex;
const end = error.startIndex;
const toReplace = modifiedUSFM.slice(start, end);
modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`);
changed = true;
}
// Stray slash not with a valid marker
else if (errorText.startsWith("\\") && !validMarkersPattern.test(errorText)) {
// console.log("Match 8");
Expand Down

0 comments on commit f8a3f22

Please sign in to comment.