Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect ditto marks better in curly quotes #590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/guiguts/misc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,11 +1745,18 @@ def convert_to_curly_quotes() -> None:
continue

# Apart from special cases, alternate open/close double quotes through each paragraph
# Ditto marks first (surrounded by double-space)
# Ditto marks first - surrounded by double-space. Also permit 0/1 space
# before ditto if at start of line, or 0/1 space after ditto if at end of line.
line, count = re.subn('(?<= )"(?= )', DQUOTES[1], line)
if count:
edited = True
# Start of line must be open quotes
line, count = re.subn('(?<=^ ?)"(?= )', DQUOTES[1], line)
if count:
edited = True
line, count = re.subn('(?<= )"(?= ?$)', DQUOTES[1], line)
if count:
edited = True
# Start of line, must be open quotes
line, count = re.subn('^"', DQUOTES[0], line)
if count:
edited = True
Expand Down Expand Up @@ -1900,22 +1907,25 @@ def add_quote_entry(prefix: str) -> None:
)
if dqtype == 1:
add_quote_entry("DOUBLE OPEN QUOTE UNEXPECTED: ")
elif context[2] == "\n":
elif len(context) > 2 and context[2] == "\n":
add_quote_entry("DOUBLE OPEN QUOTE AT END OF LINE: ")
elif context[2] == " ":
elif len(context) > 2 and context[2] == " ":
add_quote_entry("DOUBLE OPEN QUOTE FOLLOWED BY SPACE: ")
elif context[0].isalnum():
add_quote_entry("DOUBLE OPEN QUOTE PRECEDED BY WORD CHARACTER: ")
dqtype = 1
last_open_double_idx = match.rowcol.index()
elif match_text == DQUOTES[1]: # Close double
# If surrounded by double-spaces or end of line, it's ditto mark, so OK
# If surrounded by double-spaces or beg/end of line (with optional single space), it's ditto mark, so OK
context = maintext().get(
f"{match.rowcol.index()}-2c", f"{match.rowcol.index()}+3c"
)
if (
context == f" {DQUOTES[1]} "
or context == f" {DQUOTES[1]} \n"
len(context) < 5
or re.fullmatch(
rf"([\n ] {DQUOTES[1]} | {DQUOTES[1]} \n)", context
)
or context[1:] == f"\n{DQUOTES[1]} "
or context[:4] == f" {DQUOTES[1]}\n"
):
continue
Expand All @@ -1932,9 +1942,9 @@ def add_quote_entry(prefix: str) -> None:
context = maintext().get(
f"{match.rowcol.index()}-1c", f"{match.rowcol.index()}+2c"
)
if context[2] == "\n":
if len(context) > 2 and context[2] == "\n":
add_quote_entry("SINGLE OPEN QUOTE AT END OF LINE: ")
elif context[2] == " ":
elif len(context) > 2 and context[2] == " ":
add_quote_entry("SINGLE OPEN QUOTE FOLLOWED BY SPACE: ")
elif context[0].isalnum():
add_quote_entry("SINGLE OPEN QUOTE PRECEDED BY WORD CHARACTER: ")
Expand Down
Loading