Improving Markdown support.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-07-16 21:47:46 -05:00
parent 28e21b5e79
commit d2fb9e00da
3 changed files with 48 additions and 2 deletions

View File

@ -16,7 +16,7 @@ BaselineOfMiniDocs >> baseline: spec [
"Packages"
spec
package: 'Markdeep'
package: 'MiniDocs'
with: [ spec requires: #('Mustache') ]
].
spec

View File

@ -36,11 +36,42 @@ LePage >> asMarkdeepFile [
^ self asMarkdeep exportAsFileOn: folder / self markdeepFileName
]
{ #category : #'*MiniDocs' }
LePage >> asMarkdown [
| bodyStream markdown |
bodyStream := '' writeStream.
bodyStream
nextPutAll: '---';
nextPutAll: String lf.
self metadata keysAndValuesDo: [ :k :v |
bodyStream
nextPutAll: k , ': ' , v;
nextPutAll: String lf ].
bodyStream nextPutAll: '---' , String lf , String lf.
self preorderTraversal
do: [ :snippet | bodyStream nextPutAll: snippet asMarkdown ].
markdown := Markdown new contents: bodyStream contents.
^ markdown
]
{ #category : #'*MiniDocs' }
LePage >> asMarkdownFile [
| folder |
folder := self options at: 'storage' ifAbsent: [ FileLocator temp ].
^ MarkupFile exportAsFileOn: folder / self markdownFileName containing: self asMarkdown contents
]
{ #category : #'*MiniDocs' }
LePage >> markdeepFileName [
^ self markdownFileName , '.html'
]
{ #category : #'*MiniDocs' }
LePage >> markdownFileName [
| sanitized |
sanitized := self title asDashedLowercase copyWithoutAll: #($/).
^ sanitized, '--',(self uidString copyFrom: 1 to: 5), '.md.html'.
^ sanitized, '--',(self uidString copyFrom: 1 to: 5), '.md'.
]
{ #category : #'*MiniDocs' }

View File

@ -124,6 +124,14 @@ Markdown >> fromFile: aFileReference [
self file: aFileReference
]
{ #category : #accessing }
Markdown >> gtTextFor: aView [
<gtView>
^ aView textEditor
title: 'Text';
text: [ self contents ]
]
{ #category : #utilities }
Markdown >> lines [
^ self contents lines.
@ -139,6 +147,13 @@ Markdown >> metadata [
^ rawMeta
]
{ #category : #accessing }
Markdown >> printOn: aStream [
super printOn: aStream.
aStream
nextPutAll: '( ', (self metadata at: 'title'), ' )'
]
{ #category : #utilities }
Markdown >> startsWithYAMLMetadataDelimiter [
^ self lines first beginsWith: self class yamlMetadataDelimiter