From fb433bfaefe34970c7937877bbcb4916af0dc1d7 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 15 Jul 2021 17:24:05 -0500 Subject: [PATCH] Merging fixes in image 0.8.690 to integrate into new versions. --- repository/TiddlyWiki/Tiddler.class.st | 38 +++++++++++++++++---- repository/TiddlyWiki/WikiText.class.st | 45 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 repository/TiddlyWiki/WikiText.class.st diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 3a23635..d7b419b 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -11,13 +11,13 @@ Class { 'title', 'text', 'modified', - 'mofier', 'created', 'creator', 'tags', 'type', 'list', - 'caption' + 'caption', + 'modifier' ], #category : #'TiddlyWiki-Model' } @@ -32,6 +32,11 @@ Tiddler >> asDictionary [ yourself. ] +{ #category : #converting } +Tiddler >> asJson [ + ^ STONJSON 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 [ @@ -114,15 +133,22 @@ Tiddler >> modified: anObject [ ] { #category : #accessing } -Tiddler >> mofier [ +Tiddler >> modifier [ - ^ mofier + ^ modifier ] { #category : #accessing } -Tiddler >> mofier: anObject [ +Tiddler >> modifier: anObject [ - mofier := anObject + modifier := anObject +] + +{ #category : #accessing } +Tiddler >> printOn: aStream [ + super printOn: aStream. + aStream + nextPutAll: '( ', self title, ' )' ] { #category : #accessing } diff --git a/repository/TiddlyWiki/WikiText.class.st b/repository/TiddlyWiki/WikiText.class.st new file mode 100644 index 0000000..455d8d8 --- /dev/null +++ b/repository/TiddlyWiki/WikiText.class.st @@ -0,0 +1,45 @@ +Class { + #name : #WikiText, + #superclass : #Object, + #instVars : [ + 'content' + ], + #category : #'TiddlyWiki-Model' +} + +{ #category : #accessing } +WikiText >> content [ + ^ content +] + +{ #category : #accessing } +WikiText >> content: aString [ + content := aString +] + +{ #category : #conversions } +WikiText >> converMarkdownBold [ + self content: (self content copyReplaceAll: '**' with: ''''''). +] + +{ #category : #conversions } +WikiText >> convertMarkdownBold [ + self content: (self content copyReplaceAll: '**' with: ''''''). + ^ self. +] + +{ #category : #conversions } +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 ]. + 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 +]