Improving youtube link parser and adding yaml metadata parser and example class.

This commit is contained in:
ruidajo 2023-03-20 16:37:29 -05:00
parent ad8e0f445f
commit 2cb905e58f
2 changed files with 33 additions and 3 deletions

View File

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

View File

@ -0,0 +1,19 @@
Class {
#name : #HedgeDocGrammarExamples,
#superclass : #Object,
#category : #MiniDocs
}
{ #category : #accessing }
HedgeDocGrammarExamples >> hedgeDocParseYoutubeEmbeddedLinkExample [
<gtExample>
| 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
]