1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-17 12:02:58 +08:00
Commit Graph

4 Commits

  • Add parenthesis handling to old link format
    Allow users to put both balanced round parentheses, as well as
    unbalanced escaped ones, in old style link text. The implementation
    is the same as for Markdown and new style links, except for swapping
    all instances of
    
        \[\]
    
    to
    
        \(\)
    
    for obvious reasons (different type of parenthesis requiring escaping).
    Tests also included.
  • Add bracket handling to Markdown link format
    Allow users to put both balanced brackets, as well as unbalanced
    escaped ones, in Markdown link text. The implementation is the exact
    same as in the case of new format links.
    
    For completion's sake, tests also included.
  • Add backslash escaping to new link format
    For users to be able to add square brackets inside of links using
    the new format, the regular expression used for parsing those links
    contained a balancing group, which can be used for matching pairs
    of tokens (in this case, opening and closing brackets, in that order).
    However, this means that users could not post links with unmatched
    brackets inside of them (ie. ones that contain single brackets, or
    a closing bracket and then an opening one). Allow for escaping opening
    and closing brackets using the backslash character.
    
    The change substitutes this old fragment of the regex in the display
    text group:
    
        [^\[\]]*        // any character other than closing/opening bracket
    
    for this one:
    
        (((?<=\\)[\[\]])|[^\[\]])*
    
    The second pattern in the alternative remains the same; the first one
    performs the escaping, as follows:
    
        (
            (?<=\\)     // positive lookbehind expression:
                        // this match will succeed, if the next expression
                        // is preceded by a single backslash
            [\[\]]      // either an opening or closing brace
        )
    
    Since the entire display group is matched, unfortunately the lookbehind
    expression does not actually strip the backslashes, so they are
    manually stripped in handleMatches.
    
    As demonstrated in the unit tests attached, this also allows balanced
    brackets to be mixed with escaped ones.