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 +]