dart-lang / markdown

A Dart markdown library
https://pub.dev/packages/markdown
BSD 3-Clause "New" or "Revised" License
441 stars 201 forks source link

Make a custom Syntax #525

Open logneh4 opened 1 year ago

logneh4 commented 1 year ago

I'm trying to make a custom custom syntax and transform: --!text *strong* text!-- text and elements between --! and !--. I've tried using the DelimiterSyntax class to achieve this, but I'm having trouble getting it to work as expected. Its work only when start and end is the same.

chenzhiguang commented 1 year ago

You are re right. The DelimiterSyntax only works when the start and end delimiters are the same. For this syntax, you need to create a syntax that extends from InlineSyntax.

logneh4 commented 1 year ago

You are re right. The DelimiterSyntax only works when the start and end delimiters are the same. For this syntax, you need to create a syntax that extends from InlineSyntax.

I found the start and end positions of my custom syntax in the onMatch method, and I'm creating an Element and adding a Text element inside it with the content between the start and end positions. However, this approach doesn't parse and format other Markdown elements (such as test for emphasis) inside the custom syntax.