Skip to content

Commit 9676fa5

Browse files
committed
get rid of the label highlight, and emit special wbr and span indent markers to perform signature linebreaking. also make linebreaking only apply to the multiline css style, and apply that style if the signature is more than 80 characters long
1 parent 5b5873e commit 9676fa5

19 files changed

+222
-159
lines changed

Assets/css/Main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/css/Main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Context.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension MarkdownBytecode
5656
case type
5757
case `typealias`
5858
/// New in 8.0.
59-
case label
59+
case indent
6060

6161
// Section elements.
6262
case parameters = 0xC0

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Marker.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
extension MarkdownBytecode
22
{
3+
/// Markers inhabit the unassigned codepoints of the UTF-8 encoding.
4+
///
5+
/// https://en.wikipedia.org/wiki/UTF-8
36
@frozen public
47
enum Marker:UInt8, Equatable, Hashable, Sendable
58
{

Sources/MarkdownPluginSwift/Signature.Abridged (ext).swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,44 @@ extension Signature.Abridged
2323
@usableFromInline internal
2424
init(utf8:[UInt8], actor:Bool = false)
2525
{
26-
let regions:SignatureSyntax = utf8.withUnsafeBufferPointer(SignatureSyntax.init)
26+
let signature:SignatureSyntax = utf8.withUnsafeBufferPointer(SignatureSyntax.init)
2727
let bytecode:MarkdownBytecode = .init
2828
{
29-
for token:SignatureSyntax.Token? in regions.tokens
29+
for span:SignatureSyntax.Span in signature.elements
3030
{
31-
guard let token:SignatureSyntax.Token
32-
else
31+
switch span
3332
{
33+
case .wbr(indent: false):
3434
$0[.wbr]
35-
continue
36-
}
3735

38-
let text:String = .init(decoding: utf8[token.range], as: Unicode.UTF8.self)
36+
case .wbr(indent: true):
37+
$0[.indent]
3938

40-
if actor,
41-
case (.keyword, "class") = (token.color, text)
42-
{
43-
$0 += "actor"
44-
continue
45-
}
39+
case .text(let range, nil, _):
40+
$0 += utf8[range]
4641

47-
switch (token.color, text)
48-
{
49-
case (.identifier, _),
50-
(.keyword, "init"),
51-
(.keyword, "deinit"),
52-
(.keyword, "subscript"):
53-
$0[.identifier] = text
42+
case .text(let range, let color?, let depth):
43+
let text:String = .init(decoding: utf8[range], as: Unicode.UTF8.self)
44+
switch (color, text, depth)
45+
{
46+
case (.keyword, "subscript", .toplevel?),
47+
(.keyword, "deinit", .toplevel?),
48+
(.keyword, "init", .toplevel?),
49+
(.identifier, _, _):
50+
$0[.identifier] = text
51+
52+
case (.keyword, "class", .toplevel?):
53+
guard actor
54+
else
55+
{
56+
fallthrough
57+
}
5458

55-
case (.label, _):
56-
$0[.label] = text
59+
$0 += "actor"
5760

58-
case _:
59-
$0 += text
61+
case (_, _, _):
62+
$0 += text
63+
}
6064
}
6165
}
6266
}

Sources/MarkdownPluginSwift/Signature.Expanded (ext).swift

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,60 +46,67 @@ extension Signature.Expanded
4646
@inlinable internal
4747
init(utf8:[UInt8], keywords:inout InterestingKeywords, symbols:inout [Int: Scalar])
4848
{
49-
let regions:SignatureSyntax = utf8.withUnsafeBufferPointer(SignatureSyntax.init)
49+
let signature:SignatureSyntax = utf8.withUnsafeBufferPointer(SignatureSyntax.init)
5050
var references:[Scalar: Int] = [:]
5151
var referents:[Scalar] = []
5252

5353
let bytecode:MarkdownBytecode = .init
5454
{
55-
for token:SignatureSyntax.Token? in regions.tokens
55+
for span:SignatureSyntax.Span in signature.elements
5656
{
57-
guard let token:SignatureSyntax.Token
58-
else
57+
switch span
5958
{
59+
case .wbr(indent: false):
6060
$0[.wbr]
61-
continue
62-
}
6361

64-
let text:String = .init(decoding: utf8[token.range], as: Unicode.UTF8.self)
62+
case .wbr(indent: true):
63+
$0[.indent]
6564

66-
guard let color:MarkdownBytecode.Context = token.color
67-
else
68-
{
69-
$0 += text
70-
continue
71-
}
65+
case .text(let range, nil, _):
66+
$0 += utf8[range]
7267

73-
if case .keyword = color
74-
{
75-
switch text
68+
case .text(let range, let color?, .toplevel?):
69+
if case .keyword = color
7670
{
77-
case "actor": keywords.actor = true
78-
case "class": keywords.class = true
79-
default: break
71+
// The `actor` and `async` keywords are contextual; there is no
72+
// other way to detect them besides inspecting token text!
73+
switch String.init(decoding: utf8[range], as: Unicode.UTF8.self)
74+
{
75+
case "actor": keywords.actor = true
76+
case "class": keywords.class = true
77+
default: break
78+
}
8079
}
81-
}
8280

83-
$0[color]
84-
{
85-
if let referent:Scalar = symbols.removeValue(forKey: token.start)
81+
fallthrough
82+
83+
case .text(let range, let color?, _):
84+
85+
$0[color]
8686
{
87-
$0[.href] =
87+
if let referent:Scalar = symbols.removeValue(forKey: range.lowerBound)
8888
{
89-
if let reference:Int = $0
90-
{
91-
return reference
92-
}
93-
else
89+
$0[.href] =
9490
{
95-
let next:Int = referents.endIndex
96-
referents.append(referent)
97-
$0 = next
98-
return next
99-
}
100-
} (&references[referent])
91+
if let reference:Int = $0
92+
{
93+
return reference
94+
}
95+
else
96+
{
97+
let next:Int = referents.endIndex
98+
referents.append(referent)
99+
$0 = next
100+
return next
101+
}
102+
} (&references[referent])
103+
}
101104
}
102-
} = text
105+
content:
106+
{
107+
$0 += utf8[range]
108+
}
109+
}
103110
}
104111
}
105112

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extension SignatureSyntax.Span
2+
{
3+
@frozen @usableFromInline internal
4+
enum Depth
5+
{
6+
case toplevel
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import MarkdownABI
2+
3+
extension SignatureSyntax
4+
{
5+
@frozen @usableFromInline internal
6+
enum Span
7+
{
8+
case text(Range<Int>, MarkdownBytecode.Context? = nil, Depth? = nil)
9+
case wbr(indent:Bool)
10+
}
11+
}

Sources/MarkdownPluginSwift/SignatureSyntax.Token.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)