diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 3a23635..73c3efc 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -32,6 +32,11 @@ Tiddler >> asDictionary [ yourself. ] +{ #category : #converting } +Tiddler >> asJson [ + ^ STON toStringPretty: self asDictionary +] + { #category : #accessing } Tiddler >> caption [ @@ -101,6 +106,20 @@ Tiddler >> list: anObject [ list := anObject ] +{ #category : #utilities } +Tiddler >> markdownLinksAsWikiText [ + "I'm useful to convert _internal_ links between formats, as is a common pattern + found when migrating content from Markdown to TiddlyWiki's WikiText. + I DON'T work on external links. A better regex could be used for that. + See: + - https://davidwells.io/snippets/regex-match-markdown-links + - http://blog.michaelperrin.fr/2019/02/04/advanced-regular-expressions/" + | markdownLinks | + markdownLinks := (self text splitOn: Character space) select: [:each | each matchesRegex: '\[(.+)\)']. + markdownLinks ifEmpty: [^ self]. + ^ markdownLinks +] + { #category : #accessing } Tiddler >> modified [ @@ -125,6 +144,13 @@ Tiddler >> mofier: anObject [ mofier := anObject ] +{ #category : #accessing } +Tiddler >> printOn: aStream [ + super printOn: aStream. + aStream + nextPutAll: '( ', self title, ' )' +] + { #category : #accessing } Tiddler >> tags [ diff --git a/repository/TiddlyWiki/WikiText.class.st b/repository/TiddlyWiki/WikiText.class.st new file mode 100644 index 0000000..c877918 --- /dev/null +++ b/repository/TiddlyWiki/WikiText.class.st @@ -0,0 +1,34 @@ +Class { + #name : #WikiText, + #superclass : #Object, + #instVars : [ + 'content' + ], + #category : #'TiddlyWiki-Model' +} + +{ #category : #accessing } +WikiText >> content [ + ^ content +] + +{ #category : #accessing } +WikiText >> content: aString [ + content := aString +] + +{ #category : #accessing } +WikiText >> convertMarkdownLinks [ + | markdownLinks markdownLinksRegex | + markdownLinksRegex := '\[([\w|\s]+)\]\((\S+)\)'. + "For the explanation of the Regex details see: http://scottradcliff.com/how-to-parse-urls-in-markdown.html" + markdownLinks := self content regex: markdownLinksRegex matchesCollect: [:link | link ]. + markdownLinks ifEmpty: [^ self content ]. + markdownLinks do: [:markdownLink | | linkText closingLinkIndex newContent | + closingLinkIndex := markdownLink indexOf: $]. + linkText := markdownLink copyFrom: 2 to: closingLinkIndex. + newContent := self content copyReplaceAll: markdownLink with: '[[', linkText, ']'. + self content: newContent. + ]. + ^ self content +]