Improving youtube link parser and adding yaml metadata parser and example class.
This commit is contained in:
parent
ad8e0f445f
commit
2cb905e58f
@ -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
|
||||
]
|
||||
|
19
src/MiniDocs/HedgeDocGrammarExamples.class.st
Normal file
19
src/MiniDocs/HedgeDocGrammarExamples.class.st
Normal 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
|
||||
]
|
Loading…
Reference in New Issue
Block a user