mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add function to get highlight start location
This commit is contained in:
parent
b8dbcdb2bd
commit
73bf695cf3
4 changed files with 35 additions and 1 deletions
|
|
@ -46,6 +46,7 @@
|
|||
"cookie-parser": "^1.4.5",
|
||||
"cors": "^2.8.5",
|
||||
"dataloader": "^2.0.0",
|
||||
"diff-match-patch": "^1.0.5",
|
||||
"dompurify": "^2.0.17",
|
||||
"dot-case": "^3.0.4",
|
||||
"dotenv": "^8.2.0",
|
||||
|
|
@ -96,6 +97,7 @@
|
|||
"@types/chai-string": "^1.4.2",
|
||||
"@types/cookie": "^0.4.0",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/diff-match-patch": "^1.0.32",
|
||||
"@types/dompurify": "^2.0.4",
|
||||
"@types/express": "^4.17.7",
|
||||
"@types/graphql-fields": "^1.3.4",
|
||||
|
|
|
|||
7
packages/api/src/services/highlights.ts
Normal file
7
packages/api/src/services/highlights.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { diff_match_patch } from 'diff-match-patch'
|
||||
|
||||
export const getHighlightLocation = (patch: string): number | undefined => {
|
||||
const dmp = new diff_match_patch()
|
||||
const patches = dmp.patch_fromText(patch)
|
||||
return patches[0].start1 || undefined
|
||||
}
|
||||
25
packages/api/test/services/highlights.test.ts
Normal file
25
packages/api/test/services/highlights.test.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
import { getHighlightLocation } from '../../src/services/highlights'
|
||||
|
||||
describe('getHighlightLocation', () => {
|
||||
let patch: string
|
||||
let location: number
|
||||
|
||||
before(async () => {
|
||||
location = 109
|
||||
patch = `@@ -${location + 1},16 +${location + 1},36 @@
|
||||
. We're
|
||||
+%3Comnivore_highlight%3E
|
||||
humbled
|
||||
@@ -254,16 +254,37 @@
|
||||
h in the
|
||||
+%3C/omnivore_highlight%3E
|
||||
coming`
|
||||
})
|
||||
|
||||
it('returns highlight location from patch', async () => {
|
||||
const result = getHighlightLocation(patch)
|
||||
expect(result).to.eql(location)
|
||||
})
|
||||
})
|
||||
|
|
@ -9,7 +9,7 @@ CREATE TYPE omnivore.integration_type AS ENUM ('READWISE');
|
|||
CREATE TABLE omnivore.integrations (
|
||||
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
|
||||
user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE,
|
||||
"type" integration_type NOT NULL,
|
||||
"type" omnivore.integration_type NOT NULL,
|
||||
token varchar(255) NOT NULL,
|
||||
"enabled" boolean NOT NULL DEFAULT true,
|
||||
created_at timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
|
|
|
|||
Loading…
Reference in a new issue