Skip to content

Commit d8bb65e

Browse files
authored
Merge pull request #10 from GoodNotes/extract_hyperlink
Detect the text unit where the hyperlink is set
2 parents c70a0fb + 7dde03a commit d8bb65e

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

corpus/hyperlink.txt

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ Adios}
2424
(staticNumberLiteral)
2525
(staticNumberLiteral)))
2626
(parTbl)
27+
(hyperlink)
2728
(textUnit
2829
(fontIndex)
2930
(fontSize)
3031
(colorFontIndex)
3132
(textUnitContent))
33+
(endHyperlink)
3234
(textUnit
3335
(fontIndex)
3436
(fontSize)
@@ -72,11 +74,13 @@ Text with hpyerlink - https://www.google.com/
7274
(textUnitContent))
7375
(textUnit
7476
(textUnitContent))
77+
(hyperlink)
7578
(textUnit
7679
(fontIndex)
7780
(fontSize)
7881
(colorFontIndex)
79-
(textUnitContent)))
82+
(textUnitContent))
83+
(endHyperlink))
8084

8185

8286
=============================
@@ -115,8 +119,10 @@ Text with hpyerlink - No extra style
115119
(textUnitContent))
116120
(textUnit
117121
(textUnitContent))
122+
(hyperlink)
118123
(textUnit
119-
(textUnitContent)))
124+
(textUnitContent))
125+
(endHyperlink))
120126

121127

122128
=============================
@@ -155,9 +161,11 @@ test.\
155161
(fontSize)
156162
(colorFontIndex)
157163
(textUnitContent))
164+
(hyperlink)
158165
(textUnit
159166
(fontSize)
160167
(textUnitContent))
168+
(endHyperlink)
161169
(textUnit
162170
(textUnitContent))
163171
(textUnit
@@ -201,7 +209,58 @@ Text with hpyerlink - No extra style and HTTP://GOGOLE.COM
201209
(textUnitContent))
202210
(textUnit
203211
(textUnitContent))
212+
(hyperlink)
204213
(textUnit
205214
(textUnitContent))
215+
(endHyperlink)
206216
(textUnit
207-
(textUnitContent)))
217+
(textUnitContent)))
218+
219+
220+
=============================
221+
Text with hpyerlink composed by 2 text units
222+
=============================
223+
{\rtf1\ansi\ansicpg1252\cocoartf2639
224+
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
225+
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
226+
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0;}
227+
\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
228+
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
229+
230+
\f0\fs24 \cf2 This is a {\field{\*\fldinst{HYPERLINK "http://www.google.com"}}{\fldrslt strange
231+
\f1\b\fs36 hyperlink}}}
232+
----------------------------
233+
(document
234+
(fonttbl
235+
(fontinfo
236+
(fontFamily)
237+
(charset)
238+
(fontname))
239+
(fontinfo
240+
(fontFamily)
241+
(charset)
242+
(fontname)))
243+
(colortbl
244+
(colorvalue
245+
(staticNumberLiteral)
246+
(staticNumberLiteral)
247+
(staticNumberLiteral))
248+
(colorvalue
249+
(staticNumberLiteral)
250+
(staticNumberLiteral)
251+
(staticNumberLiteral)))
252+
(parTbl)
253+
(textUnit
254+
(fontIndex)
255+
(fontSize)
256+
(colorFontIndex)
257+
(textUnitContent))
258+
(hyperlink)
259+
(textUnit
260+
(textUnitContent))
261+
(textUnit
262+
(fontIndex)
263+
(boldEnabled)
264+
(fontSize)
265+
(textUnitContent))
266+
(endHyperlink))

grammar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,12 @@ module.exports = grammar({
295295

296296
_fieldinst: ($) => seq("{\\*", "\\fldinst", $._hyperlinkUnit, "}"),
297297

298-
_fieldslt: ($) => seq("{\\fldrslt", " ", $.textUnit, "}"),
298+
_fieldslt: ($) =>
299+
seq("{\\fldrslt", " ", repeat1($.textUnit), $.endHyperlink),
299300

300-
_hyperlinkUnit: ($) => seq('{HYPERLINK "', $._static_URL_literal, '"}'),
301+
endHyperlink: () => "}",
302+
303+
_hyperlinkUnit: ($) => seq('{HYPERLINK "', $.hyperlink, '"}'),
301304

302305
_textUnitParameters: ($) =>
303306
seq(repeat1(seq(repeat1($._textUnit_config), " "))),
@@ -311,6 +314,8 @@ module.exports = grammar({
311314
_textUnitInformation: ($) =>
312315
seq($._textUnitVisibleInformation, optional("\n")),
313316

317+
hyperlink: ($) => $._static_URL_literal,
318+
314319
textUnit: ($) =>
315320
seq(optional($._textUnitParameters), $._textUnitInformation),
316321

0 commit comments

Comments
 (0)