|
| 1 | +package dotty.tools.scaladoc |
| 2 | +package tasty.comments.markdown |
| 3 | + |
| 4 | +import dotty.tools.scaladoc.snippets._ |
| 5 | + |
| 6 | +import com.vladsch.flexmark.formatter._ |
| 7 | +import com.vladsch.flexmark.parser._ |
| 8 | +import com.vladsch.flexmark.ext.wikilink._ |
| 9 | +import com.vladsch.flexmark.ext.wikilink.internal.WikiLinkLinkRefProcessor |
| 10 | +import com.vladsch.flexmark.util.ast._ |
| 11 | +import com.vladsch.flexmark.util.options._ |
| 12 | +import com.vladsch.flexmark.util.sequence.BasedSequence |
| 13 | +import com.vladsch.flexmark._ |
| 14 | + |
| 15 | +object SnippetFormattingExtension extends Formatter.FormatterExtension: |
| 16 | + |
| 17 | + def rendererOptions(opt: MutableDataHolder): Unit = () |
| 18 | + |
| 19 | + object ExtendedFencedCodeBlockHandler extends CustomNodeFormatter[ExtendedFencedCodeBlock]: |
| 20 | + override def render(node: ExtendedFencedCodeBlock, c: NodeFormatterContext, markdown: MarkdownWriter): Unit = |
| 21 | + markdown.append( |
| 22 | + SnippetRenderer.renderSnippetWithMessages( |
| 23 | + node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq, |
| 24 | + node.compilationResult.toSeq.flatMap(_.messages) |
| 25 | + ) |
| 26 | + ) |
| 27 | + |
| 28 | + object Format extends NodeFormatter: |
| 29 | + override def getNodeFormattingHandlers: JSet[NodeFormattingHandler[?]] = |
| 30 | + JSet( |
| 31 | + new NodeFormattingHandler(classOf[ExtendedFencedCodeBlock], ExtendedFencedCodeBlockHandler), |
| 32 | + ) |
| 33 | + |
| 34 | + def getNodeClasses: JSet[Class[?]] = null |
| 35 | + |
| 36 | + object Factory extends NodeFormatterFactory: |
| 37 | + override def create(options: DataHolder): NodeFormatter = Format |
| 38 | + |
| 39 | + def extend(formatterBuilder: Formatter.Builder) = |
| 40 | + formatterBuilder.nodeFormatterFactory(Factory) |
0 commit comments