From 70a06b2c4d28e0ea572f21cabda8770c14cc388f Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 21 Oct 2022 18:47:37 -0500 Subject: [PATCH] Implementing PubPub initial minimal grammar for dealing with alternate link notation. --- src/MiniDocs/Markdeep.class.st | 10 ++++++- src/MiniDocs/MiniDocs.class.st | 5 ++-- src/MiniDocs/PubPubGrammar.class.st | 45 +++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/MiniDocs/PubPubGrammar.class.st diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index 64c7adc..c8540a7 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -24,6 +24,14 @@ Markdeep class >> fromMarkdownFile: aFileReference [ ^ self new fromMarkdownFile: aFileReference. ] +{ #category : #accessing } +Markdeep class >> fromPubPubTOC: orderedDictionary folder: folder index: ordinalPossitive [ + | contentSection testFile | + contentSection := orderedDictionary associations at: ordinalPossitive. + testFile := folder / (contentSection key,'--', contentSection value),'md'. + ^ self new fromMarkdownFile: testFile. +] + { #category : #'instance creation' } Markdeep >> authors [ self metadata at: 'authors' ifPresent: [:k | ^ '**', k, '**' ]. @@ -123,7 +131,7 @@ Markdeep >> contents [ Markdeep >> exportAsFile [ | newFile | self markdownFile ifNil: [ self inform: 'Define an input Markdown file or use #exportAsFileOn: instead.' ]. - newFile := (self markdownFile fullName, '.html') asFileReference. + newFile := (self markdownFile file fullName, '.html') asFileReference. self exportAsFileOn: newFile. ] diff --git a/src/MiniDocs/MiniDocs.class.st b/src/MiniDocs/MiniDocs.class.st index dd682db..a1fc372 100644 --- a/src/MiniDocs/MiniDocs.class.st +++ b/src/MiniDocs/MiniDocs.class.st @@ -14,7 +14,7 @@ MiniDocs class >> appFolder [ { #category : #accessing } MiniDocs class >> installYamlToJson [ - "For the moment, only Gnu/Linux and Mac are supported. + "For the moment, only Gnu/Linux and Mac are supported. IMPORTANT: Nimble, Nim's package manager should be installed, as this process doesn't verify its proper installation." self yamlToJsonBinary exists ifTrue: [ ^ MiniDocs appFolder ]. Nimble install: 'commandeer'. @@ -28,7 +28,8 @@ MiniDocs class >> installYamlToJson [ { #category : #accessing } MiniDocs class >> yamlToJson: yamlString [ - + "This method uses a external binary written in Nim, as the native Pharo parser for YAML, written in PetitParser, + was less robust and unable to parse correctly the same strings as the external one." self yamlToJsonBinary exists ifFalse: [ self installYamlToJson ]. OSSUnixSubprocess new diff --git a/src/MiniDocs/PubPubGrammar.class.st b/src/MiniDocs/PubPubGrammar.class.st new file mode 100644 index 0000000..cca6509 --- /dev/null +++ b/src/MiniDocs/PubPubGrammar.class.st @@ -0,0 +1,45 @@ +Class { + #name : #PubPubGrammar, + #superclass : #PP2CompositeNode, + #instVars : [ + 'document', + 'link', + 'linkLabel', + 'linkContent' + ], + #category : #'MiniDocs-Model' +} + +{ #category : #accessing } +PubPubGrammar >> document [ + ^ link islandInSea star +] + +{ #category : #links } +PubPubGrammar >> link [ + ^ linkLabel, linkContent ==> #second +] + +{ #category : #links } +PubPubGrammar >> linkContent [ + | content | + content := ($} asPParser not) star flatten. + ^ ${ asPParser, content, $} asPParser +] + +{ #category : #links } +PubPubGrammar >> linkLabel [ + | label | + label := ($] asPParser not) star flatten. + ^ $[ asPParser, label, $] asPParser +] + +{ #category : #accessing } +PubPubGrammar >> linkSea [ + ^ link sea ==> #second +] + +{ #category : #accessing } +PubPubGrammar >> start [ + ^ document +]