Skip to content

Commit 48b8259

Browse files
committed
namespace even more markdown types to Markdown
1 parent 3171be5 commit 48b8259

36 files changed

+311
-277
lines changed

Sources/MarkdownRendering/HTML/HTML.AttributeEncoder (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import HTML
33
extension HTML.AttributeEncoder
44
{
55
@inlinable public
6-
var highlight:MarkdownSyntaxHighlight?
6+
var highlight:Markdown.SyntaxHighlight?
77
{
88
get
99
{

Sources/MarkdownRendering/HTML/HTML.ContentEncoder (ext).swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extension HTML.ContentEncoder
55
{
66
mutating
77
func emit(element:Markdown.Bytecode.Emission,
8-
with attributes:MarkdownElementContext.AttributeList)
8+
with attributes:Markdown.TreeContext.AttributeList)
99
{
1010
let html:HTML.VoidElement
1111

@@ -40,13 +40,13 @@ extension HTML.ContentEncoder
4040
{
4141
private mutating
4242
func open(_ element:HTML.ContainerElement,
43-
with attributes:MarkdownElementContext.AttributeList)
43+
with attributes:Markdown.TreeContext.AttributeList)
4444
{
4545
self.open(element) { attributes.encode(to: &$0) }
4646
}
4747
mutating
48-
func open(context:MarkdownElementContext,
49-
with attributes:MarkdownElementContext.AttributeList)
48+
func open(context:Markdown.TreeContext,
49+
with attributes:Markdown.TreeContext.AttributeList)
5050
{
5151
switch context
5252
{
@@ -84,7 +84,7 @@ extension HTML.ContentEncoder
8484
}
8585
}
8686
mutating
87-
func close(context:MarkdownElementContext)
87+
func close(context:Markdown.TreeContext)
8888
{
8989
switch context
9090
{

Sources/MarkdownRendering/HTML/HTML.OutputStreamableMarkdown.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ extension HTML.OutputStreamableMarkdown
6161
public
6262
func render(to html:inout HTML.ContentEncoder) throws
6363
{
64-
var attributes:MarkdownElementContext.AttributeContext = .init()
65-
var stack:[MarkdownElementContext] = []
64+
var attributes:Markdown.TreeContext.AttributeContext = .init()
65+
var stack:[Markdown.TreeContext] = []
6666

6767
defer
6868
{
69-
for context:MarkdownElementContext in stack.reversed()
69+
for context:Markdown.TreeContext in stack.reversed()
7070
{
7171
html.close(context: context)
7272
}
@@ -78,7 +78,7 @@ extension HTML.OutputStreamableMarkdown
7878
switch instruction
7979
{
8080
case .invalid:
81-
throw MarkdownRenderingError.invalidInstruction
81+
throw Markdown.RenderingError.invalidInstruction
8282

8383
case .attribute(let attribute, nil):
8484
attributes.flush(beginning: attribute)
@@ -106,7 +106,7 @@ extension HTML.OutputStreamableMarkdown
106106
case .push(let element):
107107
attributes.flush()
108108

109-
let context:MarkdownElementContext = .init(from: element,
109+
let context:Markdown.TreeContext = .init(from: element,
110110
attributes: &attributes.list)
111111

112112
html.emit(newlines: &newlines)
@@ -128,7 +128,7 @@ extension HTML.OutputStreamableMarkdown
128128
html.close(context: context)
129129

130130
case nil:
131-
throw MarkdownRenderingError.illegalInstruction
131+
throw Markdown.RenderingError.illegalInstruction
132132
}
133133

134134
case .utf8(let codeunit):
@@ -162,7 +162,7 @@ extension HTML.OutputStreamableMarkdown
162162
guard stack.isEmpty
163163
else
164164
{
165-
throw MarkdownRenderingError.interrupted
165+
throw Markdown.RenderingError.interrupted
166166
}
167167
}
168168
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
extension Markdown
2+
{
3+
/// Defines the CSS classes associated with each type of supported syntax highlight.
4+
///
5+
/// The two-letter codenames make the Sass sources slightly less readable, but they reduce the
6+
/// size of a typical rendered page by around 30 percent.
7+
@frozen public
8+
enum SyntaxHighlight:String, Equatable, Hashable, Sendable
9+
{
10+
case attribute = "xa"
11+
case binding = "xb"
12+
case comment = "xc"
13+
case directive = "xr"
14+
case doccomment = "xd"
15+
case identifier = "xv"
16+
case interpolation = "xj"
17+
case keyword = "xk"
18+
case label = "xl"
19+
case literalNumber = "xn"
20+
case literalString = "xs"
21+
case magic = "xm"
22+
case `operator` = "xo"
23+
case pseudo = "xp"
24+
case actor = "xy"
25+
case `class` = "xz"
26+
case type = "xt"
27+
case `typealias` = "xu"
28+
case indent = "xi"
29+
}
30+
}
31+
extension Markdown.SyntaxHighlight:CustomStringConvertible
32+
{
33+
@inlinable public
34+
var description:String { self.rawValue }
35+
}

Sources/MarkdownRendering/HTML/MarkdownElementContext.AttributeContext.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.AttributeContext.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MarkdownABI
22

3-
extension MarkdownElementContext
3+
extension Markdown.TreeContext
44
{
55
// TODO: investigate if it is worthwhile to track `href` and `id` as separate instance
66
// properties.
@@ -21,7 +21,7 @@ extension MarkdownElementContext
2121
}
2222
}
2323
}
24-
extension MarkdownElementContext.AttributeContext
24+
extension Markdown.TreeContext.AttributeContext
2525
{
2626
mutating
2727
func buffer(utf8 codeunit:UInt8) -> Void?
@@ -53,6 +53,6 @@ extension MarkdownElementContext.AttributeContext
5353
}
5454
}
5555
}
56-
extension MarkdownElementContext.AttributeContext:MarkdownAttributeContext
56+
extension Markdown.TreeContext.AttributeContext:MarkdownAttributeContext
5757
{
5858
}

Sources/MarkdownRendering/HTML/MarkdownElementContext.AttributeList.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.AttributeList.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import HTML
22
import MarkdownABI
33
import URI
44

5-
extension MarkdownElementContext
5+
extension Markdown.TreeContext
66
{
77
struct AttributeList
88
{
@@ -24,7 +24,7 @@ extension MarkdownElementContext
2424
}
2525
}
2626
}
27-
extension MarkdownElementContext.AttributeList
27+
extension Markdown.TreeContext.AttributeList
2828
{
2929
mutating
3030
func append(class enumerated:some RawRepresentable<String>)
@@ -70,7 +70,7 @@ extension MarkdownElementContext.AttributeList
7070
self.id = nil
7171
}
7272
}
73-
extension MarkdownElementContext.AttributeList
73+
extension Markdown.TreeContext.AttributeList
7474
{
7575
func encode(to attributes:inout HTML.AttributeEncoder)
7676
{

Sources/MarkdownRendering/HTML/MarkdownElementContext.Highlight.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.Highlight.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import HTML
22

3-
extension MarkdownElementContext
3+
extension Markdown.TreeContext
44
{
55
struct Highlight:Equatable, Hashable, Sendable
66
{
77
let container:HTML.ContainerElement
8-
let type:MarkdownSyntaxHighlight
8+
let type:Markdown.SyntaxHighlight
99

10-
init(container:HTML.ContainerElement, type:MarkdownSyntaxHighlight)
10+
init(container:HTML.ContainerElement, type:Markdown.SyntaxHighlight)
1111
{
1212
self.container = container
1313
self.type = type

Sources/MarkdownRendering/HTML/MarkdownElementContext.Section.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.Section.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import HTML
22

3-
extension MarkdownElementContext
3+
extension Markdown.TreeContext
44
{
55
/// A section context, which typically renders as an `section` HTML element.
66
/// The most famous section context is probably ``parameters``, but some
@@ -14,11 +14,11 @@ extension MarkdownElementContext
1414
case `throws`
1515
}
1616
}
17-
extension MarkdownElementContext.Section:Identifiable
17+
extension Markdown.TreeContext.Section:Identifiable
1818
{
1919
var id:String { "ss:\(self.rawValue)" }
2020
}
21-
extension MarkdownElementContext.Section:CustomStringConvertible
21+
extension Markdown.TreeContext.Section:CustomStringConvertible
2222
{
2323
var description:String
2424
{

Sources/MarkdownRendering/HTML/MarkdownElementContext.Signage.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.Signage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import HTML
22

3-
extension MarkdownElementContext
3+
extension Markdown.TreeContext
44
{
55
/// A signage context, which typically renders as an `aside` HTML element.
66
/// Most markdown “asides” are signage contexts, but we prefer the term
@@ -35,7 +35,7 @@ extension MarkdownElementContext
3535
case warning
3636
}
3737
}
38-
extension MarkdownElementContext.Signage:CustomStringConvertible
38+
extension Markdown.TreeContext.Signage:CustomStringConvertible
3939
{
4040
var description:String
4141
{

Sources/MarkdownRendering/HTML/MarkdownElementContext.swift renamed to Sources/MarkdownRendering/HTML/Markdown.TreeContext.swift

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import HTML
22
import MarkdownABI
33

4-
enum MarkdownElementContext
4+
extension Markdown
55
{
6-
/// An anchorable context, which generates an HTML container element
7-
/// with an `a` element inside of it that links to the outer container’s
8-
/// fragment `id`.
9-
case anchorable(HTML.ContainerElement)
10-
/// A normal HTML container element.
11-
case container(HTML.ContainerElement)
12-
/// A syntax highlight, which generates an `a` or `span` element,
13-
/// depending on its attribute context.
14-
case highlight(Highlight)
15-
/// A section context, which generates a `section` element, with
16-
/// a synthesized `h2` heading.
17-
case section(Section)
18-
/// A signage context, which generates an `aside` element, with
19-
/// a synthesized `h3` heading.
20-
case signage(Signage)
21-
/// A snippet context, which generates a `pre` element with a `code`
22-
/// element inside of it, and enables line numbers. The outer `pre`
23-
/// element has a single class named `snippet`.
24-
case snippet
25-
/// The transparent context, which ignores attributes, and renders
26-
/// all nested elements without any wrappers, and without escaping
27-
/// special characters.
28-
case transparent
6+
enum TreeContext
7+
{
8+
/// An anchorable context, which generates an HTML container element
9+
/// with an `a` element inside of it that links to the outer container’s
10+
/// fragment `id`.
11+
case anchorable(HTML.ContainerElement)
12+
/// A normal HTML container element.
13+
case container(HTML.ContainerElement)
14+
/// A syntax highlight, which generates an `a` or `span` element,
15+
/// depending on its attribute context.
16+
case highlight(Highlight)
17+
/// A section context, which generates a `section` element, with
18+
/// a synthesized `h2` heading.
19+
case section(Section)
20+
/// A signage context, which generates an `aside` element, with
21+
/// a synthesized `h3` heading.
22+
case signage(Signage)
23+
/// A snippet context, which generates a `pre` element with a `code`
24+
/// element inside of it, and enables line numbers. The outer `pre`
25+
/// element has a single class named `snippet`.
26+
case snippet
27+
/// The transparent context, which ignores attributes, and renders
28+
/// all nested elements without any wrappers, and without escaping
29+
/// special characters.
30+
case transparent
31+
}
2932
}
30-
extension MarkdownElementContext
33+
extension Markdown.TreeContext
3134
{
3235
private static
3336
func heading(_ type:HTML.ContainerElement, attributes:borrowing AttributeList) -> Self
@@ -36,7 +39,7 @@ extension MarkdownElementContext
3639
}
3740

3841
private static
39-
func highlight(_ type:MarkdownSyntaxHighlight, attributes:inout AttributeList) -> Self
42+
func highlight(_ type:Markdown.SyntaxHighlight, attributes:inout AttributeList) -> Self
4043
{
4144
let container:HTML.ContainerElement = attributes.href == nil ? .span : .a
4245
attributes.append(class: type)
@@ -56,7 +59,7 @@ extension MarkdownElementContext
5659
return .signage(type)
5760
}
5861
}
59-
extension MarkdownElementContext
62+
extension Markdown.TreeContext
6063
{
6164
init(from markdown:Markdown.Bytecode.Context, attributes:inout AttributeList)
6265
{

0 commit comments

Comments
 (0)