Skip to content

(Swift) class func foo() not highlighted properly #4121

Closed
@fel1x-developer

Description

@fel1x-developer

Describe the issue

In Swift

class func foo()

works like

static func foo()

But highlight.js interpret func as the class name in this case. Both class and func should be interpreted as keywords.

For example,

class func foo() async throws -> [Bar]

becomes

<span class="hljs-keyword">class</span>
<span class="hljs-title class_">func</span>
 foo() 
<span class="hljs-keyword">async</span>
<span class="hljs-keyword">throws</span>
 -&gt; [
<span class="hljs-type">Bar</span>

Whereas,

static func foo() async throws -> [Bar]

becomes

<span class="hljs-keyword">static</span>
<span class="hljs-keyword">func</span>
<span class="hljs-title function_">foo</span>
() 
<span class="hljs-keyword">async</span>
<span class="hljs-keyword">throws</span>
 -&gt; [
<span class="hljs-type">Bar</span>

Which language seems to have the issue?

Swift, manually selected and tested on highlight.js demo page

Are you using highlight or highlightAuto?

I believe when the language is set to Swift on the demo page it uses highlight.

Sample Code to Reproduce

class func foo() async throws -> [Bar]

Expected behavior

<span class="hljs-keyword">class</span>
<span class="hljs-keyword">func</span>
<span class="hljs-title function_">foo</span>
() 
<span class="hljs-keyword">async</span>
<span class="hljs-keyword">throws</span>
 -&gt; [
<span class="hljs-type">Bar</span>

Additional context

swift-docc-render uses a customized function to resolve this issue. See here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions