diff --git a/devtools/doc/rpc-gen/src/gen.rs b/devtools/doc/rpc-gen/src/gen.rs index 21262bec98..2f1921945d 100644 --- a/devtools/doc/rpc-gen/src/gen.rs +++ b/devtools/doc/rpc-gen/src/gen.rs @@ -26,10 +26,17 @@ fn resolve_type_name(name: &str) -> String { .unwrap_or_else(|| name.to_string()) } -/// Convert a generic type name to an anchor-safe string -/// e.g. "ResponseFormat" -> "responseformat_for_blockview" +/// Convert a type name to the slug GitHub uses for markdown heading anchors. +/// e.g. "ResponseFormat" -> "responseformatblockview" fn type_name_to_anchor(name: &str) -> String { - name.to_lowercase().replace('<', "_for_").replace('>', "") + name.chars() + .filter_map(|c| match c { + 'A'..='Z' => Some(c.to_ascii_lowercase()), + 'a'..='z' | '0'..='9' | '_' | '-' => Some(c), + ' ' => Some('-'), + _ => None, + }) + .collect() } /// Build a mapping from numbered type names (e.g. "ResponseFormat2") to their @@ -751,3 +758,26 @@ This is a 64-bit unsigned integer type encoded as the 0x-prefixed hex string in ("RationalU256", "The ratio which numerator and denominator are both 256-bit unsigned integers.") ].iter().map(|&(x, y)| (x.to_string(), y.to_string())) } + +#[cfg(test)] +mod tests { + use super::type_name_to_anchor; + + #[test] + fn type_name_anchor_matches_github_for_generic_types() { + assert_eq!( + type_name_to_anchor("ResponseFormat"), + "responseformatheaderview" + ); + assert_eq!( + type_name_to_anchor("IndexerPagination"), + "indexerpaginationindexercell" + ); + } + + #[test] + fn type_name_anchor_preserves_simple_names() { + assert_eq!(type_name_to_anchor("Uint32"), "uint32"); + assert_eq!(type_name_to_anchor("ScriptHashType"), "scripthashtype"); + } +} diff --git a/rpc/README.md b/rpc/README.md index 469041d5ea..9c3debc991 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -191,8 +191,8 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Type `IndexerCellType`](#type-indexercelltype) * [Type `IndexerCellsCapacity`](#type-indexercellscapacity) * [Type `IndexerOrder`](#type-indexerorder) - * [Type `IndexerPagination`](#type-indexerpagination_for_indexercell) - * [Type `IndexerPagination`](#type-indexerpagination_for_indexertx) + * [Type `IndexerPagination`](#type-indexerpaginationindexercell) + * [Type `IndexerPagination`](#type-indexerpaginationindexertx) * [Type `IndexerRange`](#type-indexerrange) * [Type `IndexerScriptType`](#type-indexerscripttype) * [Type `IndexerSearchKey`](#type-indexersearchkey) @@ -226,9 +226,9 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Type `RawTxPool`](#type-rawtxpool) * [Type `RemoteNode`](#type-remotenode) * [Type `RemoteNodeProtocol`](#type-remotenodeprotocol) - * [Type `ResponseFormat`](#type-responseformat_for_blockview) - * [Type `ResponseFormat`](#type-responseformat_for_headerview) - * [Type `ResponseFormat`](#type-responseformat_for_transactionview) + * [Type `ResponseFormat`](#type-responseformatblockview) + * [Type `ResponseFormat`](#type-responseformatheaderview) + * [Type `ResponseFormat`](#type-responseformattransactionview) * [Type `Rfc0043`](#type-rfc0043) * [Type `Script`](#type-script) * [Type `ScriptHashType`](#type-scripthashtype) @@ -630,7 +630,7 @@ When specifying with_cycles, the response object will be different like below: * `get_header(block_hash, verbosity)` * `block_hash`: [`H256`](#type-h256) * `verbosity`: [`Uint32`](#type-uint32) `|` `null` -* result: [`ResponseFormat`](#type-responseformat_for_headerview) `|` `null` +* result: [`ResponseFormat`](#type-responseformatheaderview) `|` `null` Returns the information about a block header by hash. @@ -709,7 +709,7 @@ The response looks like below when `verbosity` is 0. * `get_header_by_number(block_number, verbosity)` * `block_number`: [`Uint64`](#type-uint64) * `verbosity`: [`Uint32`](#type-uint32) `|` `null` -* result: [`ResponseFormat`](#type-responseformat_for_headerview) `|` `null` +* result: [`ResponseFormat`](#type-responseformatheaderview) `|` `null` Returns the block header in the [canonical chain](#canonical-chain) with the specific block number. @@ -1022,7 +1022,7 @@ Response #### Method `get_tip_header` * `get_tip_header(verbosity)` * `verbosity`: [`Uint32`](#type-uint32) `|` `null` -* result: [`ResponseFormat`](#type-responseformat_for_headerview) +* result: [`ResponseFormat`](#type-responseformatheaderview) Returns the header with the highest block number in the [canonical chain](#canonical-chain). @@ -1552,7 +1552,7 @@ Response * `get_fork_block(block_hash, verbosity)` * `block_hash`: [`H256`](#type-h256) * `verbosity`: [`Uint32`](#type-uint32) `|` `null` -* result: [`ResponseFormat`](#type-responseformat_for_blockview) `|` `null` +* result: [`ResponseFormat`](#type-responseformatblockview) `|` `null` Returns the information about a fork block by hash. @@ -2290,7 +2290,7 @@ Response * `order`: [`IndexerOrder`](#type-indexerorder) * `limit`: [`Uint32`](#type-uint32) * `after`: [`JsonBytes`](#type-jsonbytes) `|` `null` -* result: [`IndexerPagination`](#type-indexerpagination_for_indexercell) +* result: [`IndexerPagination`](#type-indexerpaginationindexercell) Returns the live cells collection by the lock or type script. @@ -2648,7 +2648,7 @@ Response * `order`: [`IndexerOrder`](#type-indexerorder) * `limit`: [`Uint32`](#type-uint32) * `after`: [`JsonBytes`](#type-jsonbytes) `|` `null` -* result: [`IndexerPagination`](#type-indexerpagination_for_indexertx) +* result: [`IndexerPagination`](#type-indexerpaginationindexertx) Returns the transactions collection by the lock or type script. @@ -5011,7 +5011,7 @@ Same as CKB Indexer. * `order`: [`IndexerOrder`](#type-indexerorder) * `limit`: [`Uint32`](#type-uint32) * `after`: [`JsonBytes`](#type-jsonbytes) `|` `null` -* result: [`IndexerPagination`](#type-indexerpagination_for_indexercell) +* result: [`IndexerPagination`](#type-indexerpaginationindexercell) Returns the live cells collection by the lock or type script. @@ -5059,7 +5059,7 @@ Same as CKB Indexer. * `order`: [`IndexerOrder`](#type-indexerorder) * `limit`: [`Uint32`](#type-uint32) * `after`: [`JsonBytes`](#type-jsonbytes) `|` `null` -* result: [`IndexerPagination`](#type-indexerpagination_for_indexertx) +* result: [`IndexerPagination`](#type-indexerpaginationindexertx) Returns the transactions collection by the lock or type script. @@ -5867,7 +5867,7 @@ BlockResponse with cycles format wrapper `BlockWithCyclesResponse` is a JSON object with the following fields. -* `block`: [`ResponseFormat`](#type-responseformat_for_blockview) - The block structure +* `block`: [`ResponseFormat`](#type-responseformatblockview) - The block structure ### Type `Buried` Represent soft fork deployments where the activation epoch is