Skip to content

Commit bfce54f

Browse files
committed
add fallback rendering for block directives
1 parent be5a30f commit bfce54f

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

Sources/MarkdownAST/BlockElements/MarkdownBlock.Directive.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import MarkdownABI
2+
13
extension MarkdownBlock
24
{
35
public final
@@ -17,5 +19,29 @@ extension MarkdownBlock
1719
self.arguments = arguments
1820
super.init(elements)
1921
}
22+
23+
/// Emits a fallback description of the directive.
24+
@inlinable public override
25+
func emit(into binary:inout MarkdownBinaryEncoder)
26+
{
27+
binary[.pre]
28+
{
29+
$0[.code] = "<\(self.name)>"
30+
31+
if !self.arguments.isEmpty
32+
{
33+
$0[.dl]
34+
{
35+
for (name, value):(String, String) in self.arguments
36+
{
37+
$0[.dt] = name
38+
$0[.dd] = value
39+
}
40+
}
41+
}
42+
43+
super.emit(into: &$0)
44+
}
45+
}
2046
}
2147
}

Sources/MarkdownParsing/Parser/SwiftFlavoredMarkdownParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ extension SwiftFlavoredMarkdownParser
5353
{
5454
private
5555
func block(
56-
from markup:/* borrowing */ any _BlockMarkup,
56+
from markup:borrowing any _BlockMarkup,
5757
in source:borrowing MarkdownSource) -> MarkdownBlock?
5858
{
59-
switch /* copy */ markup
59+
switch copy markup
6060
{
6161
case let block as _BlockQuote:
6262
return MarkdownBlock.Quote.init(block.blockChildren.compactMap

Sources/MarkdownSemantics/MarkdownInterpreter.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ extension MarkdownInterpreter
238238
case "Metadata":
239239
metadata.update(with: block.elements)
240240

241+
case "Snippet":
242+
// Don’t know how to handle these yet, so we just render them
243+
// as code blocks.
244+
self.append(block)
245+
241246
case _:
242247
// Don’t know how to handle these yet, so we just render them
243248
// as code blocks.

Sources/SymbolGraphLinker/StaticLinker.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ extension StaticLinker
246246
}
247247
}
248248

249+
extension StaticLinker
250+
{
251+
// struct Snippet
252+
// {
253+
254+
// }
255+
}
249256
extension StaticLinker
250257
{
251258
public mutating

0 commit comments

Comments
 (0)