Skip to content

Commit

Permalink
Merge 7ed271e
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin.moutte.etu committed May 24, 2024
2 parents 7a648ca + 7ed271e commit 36043f6
Show file tree
Hide file tree
Showing 21 changed files with 773 additions and 125 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Microdown Parser and Elements

<a href="https://www.pharo.org">
<img alt="Pharo" src="https://img.shields.io/static/v1?style=for-the-badge&message=Pharo&color=3297d4&logo=Harbor&logoColor=FFFFFF&label=" />
</a>

I'm a parser and object model for Microdown originally implemented by S. Ducasse, L. Dargaud and G. Polito.
The implementation is based on the work on markdown of K. Osterbye.
Further developments by S. Ducasse and K. Osterbye.
Expand Down
7 changes: 5 additions & 2 deletions src/BaselineOfMicrodown/BaselineOfMicrodown.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ BaselineOfMicrodown >> baseline: spec [
package: #'Microdown-ReferenceChecker' with: [
spec requires: #( #'Microdown' ) ];

package: #'Microdown-ParentChildrenChecker' with: [
spec requires: #( #'Microdown' ) ];

package: #'Microdown-Blog' with: [
spec requires: #( #'Microdown' ) ];
package: #'Microdown-Blog-Tests' with: [
Expand All @@ -80,13 +83,13 @@ BaselineOfMicrodown >> baseline: spec [
group: 'Tests' with: #( 'Core' 'Microdown-Tests' );
group: 'RichText' with: #( 'Core' 'Microdown-RichTextComposer' );
group: 'Extensions'
with: #( #'Microdown-Evaluator' #'Microdown-Evaluator-Tests' #'Microdown-ReferenceChecker'
with: #( #'Microdown-Evaluator' #'Microdown-Evaluator-Tests' #'Microdown-ReferenceChecker'
#'Microdown-PrettyPrinter' #'Microdown-PrettyPrinter-Tests'
#'Microdown-HTMLExporter' #'Microdown-HTMLExporter-Tests'
#'Microdown-LaTeXExporter' #'Microdown-LaTeXExporter-Tests'
#'Microdown-Transformer' #'Microdown-Transformer-Tests' );
group: 'All'
with: #( 'Core' 'Tests' 'Extensions' 'Microdown-Pharo-Tools'
with: #( 'Core' 'Tests' 'Extensions' 'Microdown-Pharo-Tools'
'RichText' )
"
#'Microdown-RichTextPresenter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ MicMicrodownToSlideTest >> testSlideGotCorrectParent [
self assert: doc children size equals: 2

]

{ #category : 'tests' }
MicMicrodownToSlideTest >> testSlideMetaData [

| doc |
doc := MicrodownParser new parse: '
{
"title":"Essence of Dispatch",
"subtitle":"Taking Pharo Booleans as example",
"slidesid" : "M1S1"
}
# Slide title
- item 1
- item 2
'.
self assert: doc children size equals: 3.
MicMicrodownToSlideVisitor new visit: doc.
self assert: doc children first class equals: MicMetaDataBlock.
self assert: doc children second class equals: MicSlideBlock

]
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,62 @@ Class {
#package : 'Microdown-ParentChildrenChecker'
}

{ #category : 'visiting main API' }
MicParentChildrenChecker >> check: anElement [
"Check if the parent of the element correctly includes this element as a child"

anElement parent
ifNil: [
anElement class = MicRootBlock
ifFalse: [ orphanList add: anElement ]
ifTrue: [ anElement children do: [ :each | self check: each ] ] ]
ifNotNil: [ :p | "We cannot identify bad parent that are refered by child not in the children
list, because by construction the algo only considers the children of an element).
(p children includes: anElement) ifFalse: [ self addParent: p ]."
p children do: [ :child |
child parent = p ifFalse: [ confusedKids add: child ] ].

anElement children do: [ :each | self check: each ] ]
{ #category : 'accessing' }
MicParentChildrenChecker >> check: anElement [
"Check if the parent of the element correctly includes this element as a child and if the element's parent pointer is correct."

anElement parent
ifNil: [
"Check if the root element is indeed supposed to have no parent"
(anElement class = MicRootBlock)
ifFalse: [
"If it's not a root, it should have a parent"
orphanList add: anElement
].
"Recursively check all children of the current element"
anElement children do: [ :each | self check: each ]
]
ifNotNil: [ :p |
"Check if the parent’s list of children actually includes this element"
(p children includes: anElement)
ifFalse: [
confusedKids add: anElement
].

"Recursively check all children of the current element"
anElement children do: [ :child |
self check: child
]
].
]

{ #category : 'accessing' }
MicParentChildrenChecker >> confusedKids [
MicParentChildrenChecker >> confusedKids [

^ confusedKids


]

{ #category : 'visiting main API' }
MicParentChildrenChecker >> initialize [
{ #category : 'accessing' }
MicParentChildrenChecker >> initialize [

super initialize.
orphanList := OrderedCollection new.
confusedKids := OrderedCollection new


]

{ #category : 'testing' }
MicParentChildrenChecker >> isOk [
{ #category : 'accessing' }
MicParentChildrenChecker >> isOk [

^ (orphanList isEmpty and: [ confusedKids isEmpty ])

^ confusedKids isEmpty and:
(orphanList isEmpty and: [ confusedKids isEmpty ])
]

{ #category : 'accessing' }
MicParentChildrenChecker >> orphanList [
MicParentChildrenChecker >> orphanList [
^orphanList

]
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,203 @@ Class {
#package : 'Microdown-ParentChildrenChecker'
}

{ #category : 'tests' }
{ #category : 'accessing' }
MicParentChildrenCheckerTest >> document [
^ Microdown parse: '#Microdown is quite cool
Here is some code
```language=Pharo&caption=Beautiful&anchor=Fig1
1000 factorial / 999 factorial
```
Here is a figure and a link: [http://pharo.org](http://pharo.org).
![Pharologo](https://files.pharo.org/media/logo/logo.png size=80&anchor=figLogo.)
Here is a list:
- item 1
1. sub item 1
3. sub item 2
- item 2
**Bold**, _italic_, `monospace`
In Pharo, Microdown supports hyperlinks to:
- classes e.g., `Point`,
- methodes e.g., `Point class`, `Point>>#setX:setY:`, and
- packages e.g., `#''Microdown-Tests''` (for packages).
You can edit this file clicking on `ClySyntaxHelpMorph>>#rawMicrodownSyntax`.'.


]

{ #category : 'tests' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [
{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testComplexDocumentWithConfusedKidsAndOrphans [
| checker document child1 child2 wrongChild orphan |

checker := MicParentChildrenChecker new.

"Parse a complex Microdown document"
document := Microdown parse: '# Microdown Documentation Example

Welcome to the **Microdown Documentation**. This document serves as a tutorial and reference for creating rich markdown documents with various formatting options in Microdown.

## Introduction

Microdown allows you to write documentation directly in your Pharo environment, supporting standard markdown syntax and Pharo-specific enhancements.

### What is Markdown?

Markdown is a lightweight markup language with plain-text formatting syntax. It is designed so that it can be converted to HTML and many other formats.

## Text Formatting

Text in Microdown can be formatted in several ways:

- **Bold**: `**Bold text**` renders as **Bold text**
- _Italic_: `*Italic text*` renders as _Italic text_
- **_Combined Emphasis_**: `**_Bold and italic_**` renders as **_Bold and italic_**

## Lists

Microdown supports both ordered and unordered lists.

### Unordered List

- Item 1
- Item 2
- Subitem 2.1
- Subitem 2.2

### Ordered List

1. First item
2. Second item
1. Subitem 2.1
2. Subitem 2.2

## Links and Images

### Linking

This is how you create a [link](http://example.com).

### Images

Here''s how you embed an image:

![Alt text for the image](http://example.com/image.png)

## Code Blocks

You can add code blocks for code snippets, which are especially useful for programming documentation:

```smalltalk
Transcript show: ''Hello, world!'.

"Create confused kids: Misassign a sub-subheading to a different subheading"
child1 := document children second children second. "Assuming this is Sub-Subheading 1.1"
child2 := document children third. "Assuming this is Subheading 2"
wrongChild := child1 children first. "Content of Sub-Subheading 1.1"
wrongChild basicParent: child2. "Incorrectly setting it to Subheading 2"

"Create an orphan: Detach a sub-subheading without assigning a new parent"
orphan := document children third children last. "Assuming this is Sub-Subheading 2.2"
orphan basicParent: nil.

"Verify incorrect setups before checking"
self assert: (wrongChild parent = child2).
self assert: orphan parent isNil.

"Run the checker on the modified document"
checker check: document.

"Assert that the checker identifies the document as not OK"
self deny: checker isOk


]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testDocumentWithConfusedKids [
| checker document child1 child2 |
checker := MicParentChildrenChecker new.
document := Microdown parse: '# Microdown is quite cool
## Subheading 1
Microdown enables rich text formatting.
## Subheading 2
It’s also quite easy to use.'.

"Manually access children and reassign to create a 'confused kid'"
child1 := document children first.
child2 := document children second children first .
child2 basicParent: child1 .

checker check: document.

"Assert that the checker identifies the document as not OK due to confused relationships"
self deny: checker isOk


]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [

| checker |
checker := MicParentChildrenChecker new.
checker check: self document.
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedAnnotation [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '{!citation|name=Duca99a!}').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedFormat [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '**Bold**').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedInlineCode [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '`hello`').
self assert: checker isOk

]

{ #category : 'tests' }
MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [
{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedInput [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: '<!inputFile|path=Chapters/bloc/element.md!>').
self assert: checker isOk

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormedLink [

| checker |
checker := MicParentChildrenChecker new.
checker check: (Microdown parse: 'a link: [http://pharo.org](http://pharo.org)').
self assert: checker isOk.
self assert: checker orphanList isEmpty

]

{ #category : 'accessing' }
MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [

| brokenDocument visitor orphan |
visitor := MicParentChildrenChecker new.
Expand All @@ -61,4 +213,5 @@ MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [
visitor check: brokenDocument.

self deny: visitor isOk

]
Loading

0 comments on commit 36043f6

Please sign in to comment.