Skip to content
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
50 changes: 50 additions & 0 deletions tools/pony-doc/link_format.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
trait val LinkFormat
"""
Format-specific behavior for cross-reference links and type parameter
brackets in type rendering.

TypeRenderer delegates link generation and bracket escaping to
implementations of this trait. Pass `None` instead of a `LinkFormat`
for plain-text output (no links, plain brackets).

Implementations must ensure that `link()` returns a string appropriate
for the output format. The returned string is embedded directly into the
rendered output — it must not contain characters that are syntactically
significant in the target format unless properly escaped.

`open_bracket()` and `close_bracket()` must return a visually paired
bracket pair suitable for delimiting type argument and type parameter
lists in linked contexts.
"""
fun link(name: String, tqfn: String): String
"""
Produce a cross-reference string linking `name` to the entity
identified by `tqfn`.
"""

fun open_bracket(): String
"""
Opening bracket for type argument and type parameter lists in linked
contexts.
"""

fun close_bracket(): String
"""
Closing bracket for type argument and type parameter lists in linked
contexts.
"""

primitive MkDocsLinkFormat is LinkFormat
"""
Markdown link format for MkDocs documentation output.

Produces `[Name](tqfn.md)` cross-references and escaped brackets
`\[`/`\]` to avoid conflicts with markdown link syntax.
"""

fun link(name: String, tqfn: String): String =>
"[" + name + "](" + tqfn + ".md)"

fun open_bracket(): String => "\\["

fun close_bracket(): String => "\\]"
24 changes: 12 additions & 12 deletions tools/pony-doc/mk_docs_backend.pony
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ primitive MkDocsBackend is Backend
content.append(
TypeRenderer.render_type_params(
entity.type_params,
true,
MkDocsLinkFormat,
false,
include_private))
content.append(_source_link(entity.source, sanitized_pkg))
Expand All @@ -294,7 +294,7 @@ primitive MkDocsBackend is Backend
content.append(
TypeRenderer.render_type_params(
entity.type_params,
false,
None,
true,
include_private))
content.append(
Expand All @@ -303,7 +303,7 @@ primitive MkDocsBackend is Backend
" is\n ",
",\n ",
"",
false,
None,
include_private))
content.append("\n```\n\n")

Expand All @@ -316,7 +316,7 @@ primitive MkDocsBackend is Backend
"#### Type Alias For\n\n* ",
"\n* ",
"\n\n---\n\n",
true,
MkDocsLinkFormat,
include_private))
else
content.append(
Expand All @@ -325,7 +325,7 @@ primitive MkDocsBackend is Backend
"#### Implements\n\n* ",
"\n* ",
"\n\n---\n\n",
true,
MkDocsLinkFormat,
include_private))
end

Expand Down Expand Up @@ -411,7 +411,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render_type_params(
method.type_params,
true,
MkDocsLinkFormat,
false,
include_private))
result.append(_source_link(method.source, sanitized_pkg))
Expand Down Expand Up @@ -443,7 +443,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render_type_params(
method.type_params,
false,
None,
true,
include_private))

Expand All @@ -461,7 +461,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render(
param.param_type,
false,
None,
true,
include_private))
match param.default_value
Expand All @@ -481,7 +481,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render(
rt,
false,
None,
true,
include_private))
end
Expand All @@ -502,7 +502,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render(
param.param_type,
true,
MkDocsLinkFormat,
true,
include_private))
match param.default_value
Expand All @@ -525,7 +525,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render(
rt,
true,
MkDocsLinkFormat,
true,
include_private))
end
Expand Down Expand Up @@ -567,7 +567,7 @@ primitive MkDocsBackend is Backend
result.append(
TypeRenderer.render(
field.field_type,
true,
MkDocsLinkFormat,
false,
include_private))
result.append(_source_link(field.source, sanitized_pkg))
Expand Down
Loading
Loading