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