Merge 68dff9bd8c
This commit is contained in:
commit
59f4822e25
@ -129,3 +129,22 @@ HedgeDoc >> url: anObject [
|
||||
HedgeDoc >> visit [
|
||||
WebBrowser openOn: self server, '/', self pad.
|
||||
]
|
||||
|
||||
{ #category : #transformation }
|
||||
HedgeDoc >> youtubeEmbeddedLinksToMarkdeepFormat [
|
||||
"I replace the youtube embedded links from hedgedoc format to markdeep format."
|
||||
| linkDataCollection |
|
||||
linkDataCollection := (HedgeDocGrammar new youtubeEmbeddedLink parse: self contents)
|
||||
collect: [ :each | | parsedLink |
|
||||
parsedLink := OrderedCollection new.
|
||||
parsedLink
|
||||
add: ('' join:( each collect: [ :s | s value]));
|
||||
add: '![](https://youtu.be/',
|
||||
each second value trimmed , ')';
|
||||
add: (each first start to: each third stop);
|
||||
yourself ].
|
||||
linkDataCollection do: [ :each |
|
||||
self contents: (self contents
|
||||
copyReplaceAll: each first with: each second) ].
|
||||
^ self
|
||||
]
|
||||
|
36
src/MiniDocs/HedgeDocExamples.class.st
Normal file
36
src/MiniDocs/HedgeDocExamples.class.st
Normal file
@ -0,0 +1,36 @@
|
||||
Class {
|
||||
#name : #HedgeDocExamples,
|
||||
#superclass : #Object,
|
||||
#category : #'MiniDocs-Examples'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocExamples >> hedgeDocReplaceYoutubeEmbeddedLinkExample [
|
||||
<gtExample>
|
||||
| aSampleString hedgedocDoc parsedCollection hedgedocDocLinksReplaced |
|
||||
aSampleString := '---
|
||||
breaks: false
|
||||
|
||||
---
|
||||
|
||||
# Titulo
|
||||
|
||||
Un texto de ejemplo
|
||||
|
||||
# Enlaces youtube
|
||||
|
||||
{%youtube 1aw3XmTqFXA %}
|
||||
|
||||
otro video
|
||||
|
||||
{%youtube U7mpXaLN9Nc %}'.
|
||||
hedgedocDoc := HedgeDoc new
|
||||
contents: aSampleString.
|
||||
hedgedocDocLinksReplaced := HedgeDoc new contents: aSampleString; youtubeEmbeddedLinksToMarkdeepFormat.
|
||||
self assert: (hedgedocDoc contents
|
||||
includesSubstring: '{%youtube 1aw3XmTqFXA %}' ).
|
||||
self assert: (hedgedocDocLinksReplaced contents
|
||||
includesSubstring: '![](https://youtu.be/1aw3XmTqFXA)' ).
|
||||
^ { 'Original' -> hedgedocDoc .
|
||||
'Replaced' -> hedgedocDocLinksReplaced } asDictionary
|
||||
]
|
@ -9,11 +9,34 @@ Class {
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocGrammar >> start [
|
||||
^ #any asPParser starLazy
|
||||
| any |
|
||||
any := #any asPParser.
|
||||
^ (self yamlMetadata / any starLazy), youtubeEmbeddedLink
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocGrammar >> yamlMetadata [
|
||||
"I parse the header of the hedgedoc document for YAML metadata."
|
||||
^ '---' asPParser token, #any asPParser starLazy token, '---' asPParser token
|
||||
]
|
||||
|
||||
{ #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 := self youtubeEmbeddedLinkOpen,
|
||||
#any asPParser starLazy token,
|
||||
self youtubeEmbeddedLinkClose.
|
||||
linkSea := link islandInSea star.
|
||||
^ linkSea
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocGrammar >> youtubeEmbeddedLinkClose [
|
||||
^ '%}' asPParser token
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocGrammar >> youtubeEmbeddedLinkOpen [
|
||||
^ '{%youtube' asPParser token
|
||||
]
|
||||
|
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-Examples'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
HedgeDocGrammarExamples >> hedgeDocParseYoutubeEmbeddedLinkExample [
|
||||
<gtExample>
|
||||
| aSampleString parsedStringTokens parsedCollection |
|
||||
aSampleString := '{%youtube 1aw3XmTqFXA %}'.
|
||||
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: '%}'.
|
||||
^ parsedStringTokens
|
||||
]
|
Loading…
Reference in New Issue
Block a user