1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2025-02-26 14:11:59 +01:00

Replaced regex with backrefs package in search plugin (#8034)

Use Re in all places in the search plugin except where Unicode
properties are desired (checking for Chinese chars). Use Backrefs'
`bre` to check for Unicode properties. To minimize any differences,
explicitly use `script` as Backrefs uses `script_extensions` (or `scx`)
by default with `Is*` properties.
This commit is contained in:
Isaac Muse 2025-02-25 20:57:51 -07:00 committed by GitHub
parent 37162a57cd
commit ab1511074c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 5 deletions

View File

@ -21,7 +21,8 @@
import json
import logging
import os
import regex as re
import re
from backrefs import bre
from html import escape
from html.parser import HTMLParser
@ -285,7 +286,7 @@ class SearchIndex:
# Find and segment Chinese characters in string
def _segment_chinese(self, data):
expr = re.compile(r"(\p{IsHan}+)", re.UNICODE)
expr = bre.compile(r"(\p{script: Han}+)", bre.UNICODE)
# Replace callback
def replace(match):

View File

@ -30,5 +30,5 @@ pymdown-extensions~=10.2
babel~=2.10
colorama~=0.4
paginate~=0.5
regex>=2022.4
backrefs~=5.8
requests~=2.26

View File

@ -21,7 +21,8 @@
import json
import logging
import os
import regex as re
import re
import backrefs as bre
from html import escape
from html.parser import HTMLParser
@ -285,7 +286,7 @@ class SearchIndex:
# Find and segment Chinese characters in string
def _segment_chinese(self, data):
expr = re.compile(r"(\p{IsHan}+)", re.UNICODE)
expr = bre.compile(r"(\p{script: Han}+)", bre.UNICODE)
# Replace callback
def replace(match):