From 2cb905e58fd8e0ecb662a162bc6ce76b5c2ba819 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Mon, 20 Mar 2023 16:37:29 -0500 Subject: [PATCH 1/3] Improving youtube link parser and adding yaml metadata parser and example class. --- src/MiniDocs/HedgeDocGrammar.class.st | 17 ++++++++++++++--- src/MiniDocs/HedgeDocGrammarExamples.class.st | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/MiniDocs/HedgeDocGrammarExamples.class.st diff --git a/src/MiniDocs/HedgeDocGrammar.class.st b/src/MiniDocs/HedgeDocGrammar.class.st index 764b410..1880660 100644 --- a/src/MiniDocs/HedgeDocGrammar.class.st +++ b/src/MiniDocs/HedgeDocGrammar.class.st @@ -9,11 +9,22 @@ Class { { #category : #accessing } HedgeDocGrammar >> start [ - ^ #any asPParser starLazy + | any | + any := #any asPParser. + ^ (self yamlMetadata / any starLazy), self youtubeEmbeddedLink +] + +{ #category : #accessing } +HedgeDocGrammar >> yamlMetadata [ + "I parse the header of the hedgedoc document for YAML metadata." + ^ '---' asPParser token trim, #any asPParser starLazy token, '---' asPParser token trim ] { #category : #accessing } HedgeDocGrammar >> youtubeEmbeddedLink [ - "I parse a youtube embedded link in a hedgedoc document." - ^ '{%youtube' asPParser token trim, #any asPParser starLazy token, '%}' asPParser token trim + "I parse the youtube embedded links in a hedgedoc document." + | link linkSea | + link := '{%youtube' asPParser token trim, #any asPParser starLazy token, '%}' asPParser token trim. + linkSea := link sea ==> #second. + ^ linkSea star ] diff --git a/src/MiniDocs/HedgeDocGrammarExamples.class.st b/src/MiniDocs/HedgeDocGrammarExamples.class.st new file mode 100644 index 0000000..ce6c2f7 --- /dev/null +++ b/src/MiniDocs/HedgeDocGrammarExamples.class.st @@ -0,0 +1,19 @@ +Class { + #name : #HedgeDocGrammarExamples, + #superclass : #Object, + #category : #MiniDocs +} + +{ #category : #accessing } +HedgeDocGrammarExamples >> hedgeDocParseYoutubeEmbeddedLinkExample [ + + | aSampleString parsedString parsedCollection | + aSampleString := '{%youtube 1aw3XmTqFXA %}'. + parsedString := HedgeDocGrammar new youtubeEmbeddedLink parse: aSampleString. + parsedCollection := parsedString first. + self assert: parsedCollection size equals: 3. + self assert: parsedCollection first value equals: '{%youtube'. + self assert: parsedCollection second class equals: PP2Token. + self assert: parsedCollection third value equals: '%}'. + ^ parsedString +] From 71d1cbd9a64ab3d9c7b8ab1dbb7ff76547eb2987 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Tue, 21 Mar 2023 16:13:26 -0500 Subject: [PATCH 2/3] Modifyng hedgedoc youtube embedded link parser. --- src/MiniDocs/HedgeDocGrammar.class.st | 22 ++++++++++++++----- src/MiniDocs/HedgeDocGrammarExamples.class.st | 10 ++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/MiniDocs/HedgeDocGrammar.class.st b/src/MiniDocs/HedgeDocGrammar.class.st index 1880660..658f2c5 100644 --- a/src/MiniDocs/HedgeDocGrammar.class.st +++ b/src/MiniDocs/HedgeDocGrammar.class.st @@ -11,20 +11,32 @@ Class { HedgeDocGrammar >> start [ | any | any := #any asPParser. - ^ (self yamlMetadata / any starLazy), self youtubeEmbeddedLink + ^ (self yamlMetadata / any starLazy), youtubeEmbeddedLink ] { #category : #accessing } HedgeDocGrammar >> yamlMetadata [ "I parse the header of the hedgedoc document for YAML metadata." - ^ '---' asPParser token trim, #any asPParser starLazy token, '---' asPParser token trim + ^ '---' asPParser token, #any asPParser starLazy token, '---' asPParser token ] { #category : #accessing } HedgeDocGrammar >> youtubeEmbeddedLink [ "I parse the youtube embedded links in a hedgedoc document." | link linkSea | - link := '{%youtube' asPParser token trim, #any asPParser starLazy token, '%}' asPParser token trim. - linkSea := link sea ==> #second. - ^ linkSea star + link := self youtubeEmbeddedLinkOpen, + #any asPParser starLazy token trim, + self youtubeEmbeddedLinkClose. + linkSea := link islandInSea star. + ^ linkSea +] + +{ #category : #accessing } +HedgeDocGrammar >> youtubeEmbeddedLinkClose [ + ^ '%}' asPParser token +] + +{ #category : #accessing } +HedgeDocGrammar >> youtubeEmbeddedLinkOpen [ + ^ '{%youtube' asPParser token ] diff --git a/src/MiniDocs/HedgeDocGrammarExamples.class.st b/src/MiniDocs/HedgeDocGrammarExamples.class.st index ce6c2f7..c491e34 100644 --- a/src/MiniDocs/HedgeDocGrammarExamples.class.st +++ b/src/MiniDocs/HedgeDocGrammarExamples.class.st @@ -1,19 +1,19 @@ Class { #name : #HedgeDocGrammarExamples, #superclass : #Object, - #category : #MiniDocs + #category : #'MiniDocs-Examples' } { #category : #accessing } HedgeDocGrammarExamples >> hedgeDocParseYoutubeEmbeddedLinkExample [ - | aSampleString parsedString parsedCollection | + | aSampleString parsedStringTokens parsedCollection | aSampleString := '{%youtube 1aw3XmTqFXA %}'. - parsedString := HedgeDocGrammar new youtubeEmbeddedLink parse: aSampleString. - parsedCollection := parsedString first. + parsedStringTokens := HedgeDocGrammar new youtubeEmbeddedLink parse: aSampleString. + parsedCollection := parsedStringTokens first. self assert: parsedCollection size equals: 3. self assert: parsedCollection first value equals: '{%youtube'. self assert: parsedCollection second class equals: PP2Token. self assert: parsedCollection third value equals: '%}'. - ^ parsedString + ^ parsedStringTokens ] From 68dff9bd8c5851d8764f41a1e068e5c9aa3b5bc6 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Wed, 22 Mar 2023 10:54:16 -0500 Subject: [PATCH 3/3] Creating a HedgeDoc method to replace youtube embedded links to markdeep format and example. --- src/MiniDocs/HedgeDoc.class.st | 19 ++++++++++++++ src/MiniDocs/HedgeDocExamples.class.st | 36 ++++++++++++++++++++++++++ src/MiniDocs/HedgeDocGrammar.class.st | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/MiniDocs/HedgeDocExamples.class.st diff --git a/src/MiniDocs/HedgeDoc.class.st b/src/MiniDocs/HedgeDoc.class.st index 971180a..68df84e 100644 --- a/src/MiniDocs/HedgeDoc.class.st +++ b/src/MiniDocs/HedgeDoc.class.st @@ -129,3 +129,22 @@ HedgeDoc >> url: anObject [ HedgeDoc >> visit [ WebBrowser openOn: self server, '/', self pad. ] + +{ #category : #transformation } +HedgeDoc >> youtubeEmbeddedLinksToMarkdeepFormat [ + "I replace the youtube embedded links from hedgedoc format to markdeep format." + | linkDataCollection | + linkDataCollection := (HedgeDocGrammar new youtubeEmbeddedLink parse: self contents) + collect: [ :each | | parsedLink | + parsedLink := OrderedCollection new. + parsedLink + add: ('' join:( each collect: [ :s | s value])); + add: '![](https://youtu.be/', + each second value trimmed , ')'; + add: (each first start to: each third stop); + yourself ]. + linkDataCollection do: [ :each | + self contents: (self contents + copyReplaceAll: each first with: each second) ]. + ^ self +] diff --git a/src/MiniDocs/HedgeDocExamples.class.st b/src/MiniDocs/HedgeDocExamples.class.st new file mode 100644 index 0000000..9cbb293 --- /dev/null +++ b/src/MiniDocs/HedgeDocExamples.class.st @@ -0,0 +1,36 @@ +Class { + #name : #HedgeDocExamples, + #superclass : #Object, + #category : #'MiniDocs-Examples' +} + +{ #category : #accessing } +HedgeDocExamples >> hedgeDocReplaceYoutubeEmbeddedLinkExample [ + + | aSampleString hedgedocDoc parsedCollection hedgedocDocLinksReplaced | + aSampleString := '--- +breaks: false + +--- + +# Titulo + +Un texto de ejemplo + +# Enlaces youtube + +{%youtube 1aw3XmTqFXA %} + +otro video + +{%youtube U7mpXaLN9Nc %}'. + hedgedocDoc := HedgeDoc new + contents: aSampleString. + hedgedocDocLinksReplaced := HedgeDoc new contents: aSampleString; youtubeEmbeddedLinksToMarkdeepFormat. + self assert: (hedgedocDoc contents + includesSubstring: '{%youtube 1aw3XmTqFXA %}' ). + self assert: (hedgedocDocLinksReplaced contents + includesSubstring: '![](https://youtu.be/1aw3XmTqFXA)' ). + ^ { 'Original' -> hedgedocDoc . + 'Replaced' -> hedgedocDocLinksReplaced } asDictionary +] diff --git a/src/MiniDocs/HedgeDocGrammar.class.st b/src/MiniDocs/HedgeDocGrammar.class.st index 658f2c5..f94395a 100644 --- a/src/MiniDocs/HedgeDocGrammar.class.st +++ b/src/MiniDocs/HedgeDocGrammar.class.st @@ -25,7 +25,7 @@ HedgeDocGrammar >> youtubeEmbeddedLink [ "I parse the youtube embedded links in a hedgedoc document." | link linkSea | link := self youtubeEmbeddedLinkOpen, - #any asPParser starLazy token trim, + #any asPParser starLazy token, self youtubeEmbeddedLinkClose. linkSea := link islandInSea star. ^ linkSea