pillar-markup / Microdown

Microdown is a cleaned and simpler markdown but with more powerful features such as extensions.
Other
40 stars 31 forks source link

Introduce support for MicRawParagraph #863

Closed Ducasse closed 1 month ago

Ducasse commented 3 months ago

<a>

jlkjlklkj
</a>

so we should match

<label>

jlkjlklkj
</label>
Ducasse commented 3 months ago

We do not need to have regexp for each HTML element. We can do

initialize

    super initialize.
    dispatchTable := Dictionary new.
    dispatchTable at: AnchorMarkup put: MicAnchorBlock.
    dispatchTable at: HeaderMarkup put: MicHeaderBlock.
    dispatchTable at: CodeblockMarkup put: MicAbstractCodeBlock.
    dispatchTable at: AnnotatedParagraphMarkup put: MicAnnotatedParagraph.
    dispatchTable at: CommentedLineMarkup put: MicCommentBlock.
    dispatchTable at: HorizontalLineMarkup put: MicHorizontalLineBlock.
    dispatchTable at: MathOpeningBlockMarkup put: MicMathBlock.
    dispatchTable at: EnvironmentOpeningBlockMarkup put: MicEnvironmentBlock.
    dispatchTable at: MetaDataOpeningBlockMarkup put: MicMetaDataBlock.
    dispatchTable at: UnorderedListPlusMarkup put: MicUnorderedListBlock.
    dispatchTable at: UnorderedListMarkup put: MicUnorderedListBlock.
    dispatchTable at: UnorderedListStarMarkup put: MicUnorderedListBlock.
    dispatchTable at: PreformattedMarkup put: MicBlockQuoteBlock.
    dispatchTable at: TableCellMarkup put: MicTableBlock.

         "we should pass via the shared poll"

        dispatchTable at: 'abb' put: MicRawParagraphBlock.
        dispatchTable at: 'add' put: MicRawParagraphBlock.

Then

blockStarterClassFrom: line
    "return the class of a block which can start with line, or nil if none"

    line ifEmpty: [ ^ nil ].
    (self matchOrdered: line)
        ifTrue: [ ^ self orderedListBlockClass ]
        ifFalse: [
            "the max significant length of a markup is 3"
            (3 to: 1 by: -1) do: [:i | | prefix |
                prefix := (line truncateTo: i).

"we could remove the first trailing '<' if there is one, we should pay attention 
that <! is in the shared pool so we should probably modify the shared pool to have ! as a opener"

                "If we have a inline starter, it takes precedence"
                (Delimiters includes: prefix) 
                    ifTrue: [ ^ self delimiterBlockClassFor: prefix ].
                dispatchTable
                    at: prefix
                    ifPresent: [ :blockClass | ^ blockClass ] ] ].

    ^ self nonMatchedBlockClassFor: line
Ducasse commented 3 months ago

We should pay attention to idetnfiy when to close the block. This is typically inside the canConsumeLine: method which should return false when facing

The startAndStop does it like that

canConsumeLine: line
    "As soon as a line closes a code block, it does not accept anymore any line.
    Indeed imagine 

    <
    a line 
    >
    The first line was accepted by its parent (a root block and the code block got created.
    then a line was accepted...
    then the closing line was reached and the code block got closed.)   
    "

    isClosed
        ifTrue: [ ^ false ].
    isClosed := self doesLineStartWithStopMarkup: line.
    ^ true
doesLineStartWithStopMarkup: line

    "return if the line starts with a stop markup"
    ^ line beginsWith: self lineStopMarkup
Ducasse commented 1 month ago

Done