Modifyng hedgedoc youtube embedded link parser.

This commit is contained in:
ruidajo 2023-03-21 16:13:26 -05:00
parent 2cb905e58f
commit 71d1cbd9a6
2 changed files with 22 additions and 10 deletions

View File

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

View File

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