Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(natives/rpc): Keep code fencing in doc summary #2570

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ext/natives/codegen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ function trim(s)
return s:gsub("^%s*(.-)%s*$", "%1")
end

function parseDocString(native)
function parseDocString(native, keepCodeFencing)
local docString = native.doc

if not docString then
Expand All @@ -515,7 +515,9 @@ function parseDocString(native)
summary = ''
end

summary = trim(summary:gsub('^```(.+)```$', '%1'))
if not keepCodeFencing then
summary = trim(summary:gsub('^```(.+)```$', '%1'))
end

local paramsData = {}
local hasParams = false
Expand Down
27 changes: 13 additions & 14 deletions ext/natives/codegen_out_markdown.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@

local json = require('dkjson')


local function printFunctionName(native)
return native.name:lower():gsub('0x', 'n_0x'):gsub('_(%a)', string.upper):gsub('(%a)(.+)', function(a, b)
return a:upper() .. b
end)
return native.name:lower():gsub('0x', 'n_0x'):gsub('_(%a)', string.upper):gsub('(%a)(.+)', function(a, b)
return a:upper() .. b
end)
end

local function printCName(native)
return native.name:gsub('0x', '_0x')
end

local function printCType(t, v)
local s = t.name:gsub('Ptr', '*')
local s = t.name:gsub('Ptr', '*')

if v and v.pointer then
s = s .. '*'
end
if v and v.pointer then
s = s .. '*'
end

return s
return s
end

local keywords = {
Expand Down Expand Up @@ -194,7 +193,7 @@ local function printNative(native)

str = str .. ');\n```\n\n'

local d = parseDocString(native)
local d = parseDocString(native, true)

if d and d.summary then
d.summary = d.summary:gsub('&gt;', '>'):gsub('&lt;', '<'):gsub('&amp;', '&')
Expand All @@ -213,7 +212,7 @@ local function printNative(native)
firstIndent = line:match("^%s+")
end

line = line:gsub(firstIndent or '', '')--:gsub('^-+', '')
line = line:gsub(firstIndent or '', '') --:gsub('^-+', '')
str = str .. line .. " \n"
end

Expand All @@ -231,10 +230,10 @@ local function printNative(native)

if d and d.hasParams then
for _, v in ipairs(d.params) do
args[v[1]] = v[2]
args[v[1]] = v[2]
end
end

if #native.arguments > 0 then
str = str .. '## Parameters\n'

Expand Down Expand Up @@ -263,4 +262,4 @@ for _, v in pairs(_natives) do
if matchApiSet(v) then
printNative(v)
end
end
end
Loading