Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qiweiii committed Sep 17, 2024
1 parent 7459841 commit ebf485a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 24 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@

## dev
## Dev

```bash
pnpm dev
```

## publish
## Publish

```bash
pnpm build
pnpm zip
```

## Limitations

- Limited by mark.js library
- Search by whole word does not mark first word of a block sometimes
- Search with regular expressions is not working
- Cannot mark text in inputs
- Cannot mark text in PDFs
4 changes: 2 additions & 2 deletions entrypoints/content/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const Search: React.FC<SearchProps> = ({
{/*
MARK:- Regex
*/}
<div className="tooltip-container">
{/* <div className="tooltip-container">
<button
className={`iconButton ${config.isRegex ? "active" : ""}`}
onClick={() => {
Expand All @@ -260,7 +260,7 @@ const Search: React.FC<SearchProps> = ({
<RegexIcon size={17} style={{ marginTop: "-1px" }} />
</button>
<div className="tooltip">Match Regex</div>
</div>
</div> */}

<div className="border"></div>

Expand Down
25 changes: 14 additions & 11 deletions lib/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore
import Mark from "qw-mark.js";
import Mark from "mark.js";
import { SearchConfig } from "./type";

// https://markjs.io/
Expand Down Expand Up @@ -52,7 +51,10 @@ const isValidTag = (
let parent: HTMLElement | null | undefined = node.parentElement;
for (let i = 0; i < levels; i++) {
if (
["SCRIPT", "NOSCRIPT", "STYLE", "META"].includes(parent?.tagName || "")
// TODO: inputs and textareas should be searchable
["SCRIPT", "NOSCRIPT", "STYLE", "META", "INPUT", "TEXTAREA"].includes(
parent?.tagName || ""
)
) {
return false;
}
Expand All @@ -67,7 +69,7 @@ const isValidTag = (
* Note that this throws on input errors
*/
export const search = (
input: string | RegExp,
input: string,
mode: SearchConfig,
done: (numOfMatches: number) => void,
onNoMatch?: (notFoundTerm: string) => void
Expand Down Expand Up @@ -122,13 +124,14 @@ export const search = (
markInstance.unmark({
done: function () {
if (mode.isRegex) {
try {
// TODO: this cause extension and page to freeze...
const regex = new RegExp("bls");
markInstance.markRegExp(regex, options);
} catch (error) {
throw new Error("Invalid regular expression: " + error);
}
// TODO: mark.js regex search is not working
// try {
// const regex = new RegExp(input);
// markInstance.markRegExp(regex, options);
// } catch (error) {
// console.error("Invalid regular expression: " + error);
// throw new Error("Invalid regular expression: " + error);
// }
} else {
if (typeof input !== "string") {
throw new Error("Input must be a string");
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"framer-motion": "^11.3.27",
"lodash": "^4.17.21",
"lucide-react": "^0.427.0",
"qw-mark.js": "^9.0.2",
"mark.js": "^8.11.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/lodash": "^4.17.7",
"@types/mark.js": "^8.11.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@wxt-dev/module-react": "^1.1.0",
Expand Down
38 changes: 30 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ebf485a

Please sign in to comment.