dart-lang / markdown

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

Make default syntaxes public #605

Open matthew-carroll opened 3 months ago

matthew-carroll commented 3 months ago

Is there a reason that the default inline syntaxes are private?

https://github.com/dart-lang/markdown/blob/782b1803a29aa964410d93b4437d5d1efa47f6b4/lib/src/inline_parser.dart#L26

Imagine that I want the defaults, but I want to add my own syntax either as top priority, or bottom priority. With public defaults, that's as easy as:

inlineSyntaxes: [
  myTopPrioritySyntax,
  ...defaultInlineSyntaxes,
  myBottomPrioritySyntax,
]

But if the defaults are private then the developer has to dig through the source code to fine them, and then has to copy them over. There will be cases where that's still necessary, because sometimes a new syntax needs to be placed at a specific location in the priority list, but the most common case probably doesn't require that level of intervention.

chenzhiguang commented 3 months ago

Because the order matters, for example, if you put SoftLineBreakSyntax() before LineBreakSyntax(), some syntax might not work as expected, or it might lower the performance if you move them around freely.

But perhaps that shouldn't be the reason for making it private

matthew-carroll commented 3 months ago

I understand order matters - that's why I describe three cases in my original post:

  1. Add a syntax as top priority
  2. Add a syntax as bottom priority
  3. Add a syntax somewhere in the middle

Situation 3 will always require copying the list. But situation 1 and 2 wouldn't, and I would guess those two are the average.