Skip to content

Commit

Permalink
Merge pull request pillar-markup#700 from jecisc/fix-link-parsing
Browse files Browse the repository at this point in the history
Fix parsing of links
  • Loading branch information
jecisc authored Mar 26, 2024
2 parents 5f5143d + 6f786c7 commit 5fed492
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ MicLaTeXWriter >> visitItalic: anItalic [
MicLaTeXWriter >> visitLink: aLink [

| reference |
self halt.
reference := aLink fileStringWithoutHostFile.

canvas command
Expand Down
12 changes: 4 additions & 8 deletions src/Microdown-Tests/MicLinkBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,22 @@ MicLinkBlockTest >> testPrintOn [

{ #category : 'tests' }
MicLinkBlockTest >> testTwoUrls [

| lk |
self skip.
lk := (MicInlineParser new parse: '[https://advanced-design-mooc.pharo.org](https://advanced-design-mooc.pharo.org)') first.

self assert: lk bodyString equals: 'https://advanced-design-mooc.pharo.org'.
self assert: lk url equals: 'https://advanced-design-mooc.pharo.org'


]

{ #category : 'tests' }
MicLinkBlockTest >> testTwoUrlsWithMicrodownParser [

| lk |
self skip.
lk := (parser parse: '[https://advanced-design-mooc.pharo.org](https://advanced-design-mooc.pharo.org)') children first children first.

self assert: lk bodyString equals: 'https://advanced-design-mooc.pharo.org'.
self assert: lk url equals: 'https://advanced-design-mooc.pharo.org'


]

{ #category : 'tests' }
Expand Down
4 changes: 3 additions & 1 deletion src/Microdown/MicInlineHttpDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ MicInlineHttpDelimiter >> markup [

{ #category : 'accessing' }
MicInlineHttpDelimiter >> markupAsRegex [
^ 'http(s)?\://[\S]+'
"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 $]. "

^ 'http(s)?\://[^]\s]+'
]
15 changes: 6 additions & 9 deletions src/Microdown/MicInlineParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,15 @@ MicInlineParser >> parseEvaluatedBlock: blockType token: token stream: tokenStre
{ #category : 'private parsing' }
MicInlineParser >> parseNameUrlBlock: blockType from: aTokenStream token: token [

| skipRes children urlToken|
skipRes := (self skipToUrlStartInStream: aTokenStream).
skipRes ifNil: [ ^ self createTextBlock: token string].
| skipRes children urlToken |
skipRes := self skipToUrlStartInStream: aTokenStream.
skipRes ifNil: [ ^ self createTextBlock: token string ].
children := self parseChildrenIn: skipRes second.
urlToken := aTokenStream next.
^ blockType new
children: children;
url: urlToken undelimitedSubstring;
closeMe.



children: children;
url: urlToken undelimitedSubstring;
closeMe
]

{ #category : 'private parsing' }
Expand Down

0 comments on commit 5fed492

Please sign in to comment.