From 2cb905e58fd8e0ecb662a162bc6ce76b5c2ba819 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Mon, 20 Mar 2023 16:37:29 -0500 Subject: [PATCH] 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 +]