-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Markdown: allow to end URL with balanced parenthesis #18321
Conversation
@@ -1246,15 +1246,44 @@ proc isUrl(p: RstParser, i: int): bool = | |||
p.tok[i+3].kind == tkWord and | |||
p.tok[i].symbol in ["http", "https", "ftp", "telnet", "file"] | |||
|
|||
proc checkParen(token: Token, parensStack: var seq[char]): bool {.inline.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completely optional: can you split this into a more general reusable proc and then call it, and then in future work we can move this reusable proc to strbasics or strutils? (similar to https://dlang.org/library/std/algorithm/searching/balanced_parens.html, and same functionality as what you have)
proc balancedParens(a: openArray[char], parensStack: var seq[char]): bool =
# xxx in future work, move to stdlib
proc checkParen(token: Token, parensStack: var seq[char]): bool {.inline.} =
call balancedParens somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of balancedParens
is very different: it check whether parens are balanced or not.
checkParen
does not always forbid unbalanced parens: e.g. ([)
and (])
are legal, and checkParen
will return 3 values False,False,True
in both cases for 3 tokens.
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
lib/packages/docutils/rst.nim
Outdated
if c in {'(', '[', '{'}: # push | ||
parensStack.add c | ||
elif c in {')', ']', '}'}: # try pop | ||
if parensStack.len > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointless if
statement, if the collection is empty the loop will iterate 0 times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks.
* Markdown: allow to end URL with balanced parenthesis * Update lib/packages/docutils/rst.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * apply suggestion * remove unnecessary if Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Mostly fixes bug 24 from #17340 (except escaping).
cc @timotheecour