Skip to content

Commit 6f786c7

Browse files
committed
Fix parsing of links
Update the link regex to not conflict with the syntax of MicLinkBlock `[]()`. Fixes pillar-markup#699
1 parent 5f5143d commit 6f786c7

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ MicLaTeXWriter >> visitItalic: anItalic [
231231
MicLaTeXWriter >> visitLink: aLink [
232232

233233
| reference |
234-
self halt.
235234
reference := aLink fileStringWithoutHostFile.
236235

237236
canvas command

src/Microdown-Tests/MicLinkBlockTest.class.st

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,22 @@ MicLinkBlockTest >> testPrintOn [
155155

156156
{ #category : 'tests' }
157157
MicLinkBlockTest >> testTwoUrls [
158+
158159
| lk |
159-
self skip.
160160
lk := (MicInlineParser new parse: '[https://advanced-design-mooc.pharo.org](https://advanced-design-mooc.pharo.org)') first.
161-
161+
162162
self assert: lk bodyString equals: 'https://advanced-design-mooc.pharo.org'.
163163
self assert: lk url equals: 'https://advanced-design-mooc.pharo.org'
164-
165-
166164
]
167165

168166
{ #category : 'tests' }
169167
MicLinkBlockTest >> testTwoUrlsWithMicrodownParser [
168+
170169
| lk |
171-
self skip.
172170
lk := (parser parse: '[https://advanced-design-mooc.pharo.org](https://advanced-design-mooc.pharo.org)') children first children first.
173-
171+
174172
self assert: lk bodyString equals: 'https://advanced-design-mooc.pharo.org'.
175173
self assert: lk url equals: 'https://advanced-design-mooc.pharo.org'
176-
177-
178174
]
179175

180176
{ #category : 'tests' }

src/Microdown/MicInlineHttpDelimiter.class.st

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ MicInlineHttpDelimiter >> markup [
4444

4545
{ #category : 'accessing' }
4646
MicInlineHttpDelimiter >> markupAsRegex [
47-
^ 'http(s)?\://[\S]+'
47+
"We end the link if we find a character that is a whitespace OR a $]. $] should be valid in links but it causes conflicts with the closing bracket of the body of link syntax with the way microdown is coded. Thus, this is a hack to limit the impact of this conflict. We prefer to be able to parse things such as: `[http://mylink.fr](http://mylink.fr)` than matching links containing a $]. "
48+
49+
^ 'http(s)?\://[^]\s]+'
4850
]

src/Microdown/MicInlineParser.class.st

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,15 @@ MicInlineParser >> parseEvaluatedBlock: blockType token: token stream: tokenStre
9898
{ #category : 'private parsing' }
9999
MicInlineParser >> parseNameUrlBlock: blockType from: aTokenStream token: token [
100100

101-
| skipRes children urlToken|
102-
skipRes := (self skipToUrlStartInStream: aTokenStream).
103-
skipRes ifNil: [ ^ self createTextBlock: token string].
101+
| skipRes children urlToken |
102+
skipRes := self skipToUrlStartInStream: aTokenStream.
103+
skipRes ifNil: [ ^ self createTextBlock: token string ].
104104
children := self parseChildrenIn: skipRes second.
105105
urlToken := aTokenStream next.
106106
^ blockType new
107-
children: children;
108-
url: urlToken undelimitedSubstring;
109-
closeMe.
110-
111-
112-
107+
children: children;
108+
url: urlToken undelimitedSubstring;
109+
closeMe
113110
]
114111

115112
{ #category : 'private parsing' }

0 commit comments

Comments
 (0)